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; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 45 | using helpers::InputOperandAt; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 46 | using helpers::InputRegister; |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 47 | using helpers::InputRegisterAt; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 48 | using helpers::InputSRegisterAt; |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 49 | using helpers::InputVRegister; |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 50 | using helpers::InputVRegisterAt; |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 51 | using helpers::Int32ConstantFrom; |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 52 | using helpers::Int64ConstantFrom; |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 53 | using helpers::LocationFrom; |
| 54 | using helpers::LowRegisterFrom; |
| 55 | using helpers::LowSRegisterFrom; |
| 56 | using helpers::OutputRegister; |
| 57 | using helpers::OutputSRegister; |
| 58 | using helpers::OutputVRegister; |
| 59 | using helpers::RegisterFrom; |
| 60 | using helpers::SRegisterFrom; |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 61 | using helpers::Uint64ConstantFrom; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 62 | |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 63 | using vixl::ExactAssemblyScope; |
| 64 | using vixl::CodeBufferCheckScope; |
| 65 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 66 | using RegisterList = vixl32::RegisterList; |
| 67 | |
| 68 | static bool ExpectedPairLayout(Location location) { |
| 69 | // We expected this for both core and fpu register pairs. |
| 70 | return ((location.low() & 1) == 0) && (location.low() + 1 == location.high()); |
| 71 | } |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 72 | // Use a local definition to prevent copying mistakes. |
| 73 | static constexpr size_t kArmWordSize = static_cast<size_t>(kArmPointerSize); |
| 74 | static constexpr size_t kArmBitsPerWord = kArmWordSize * kBitsPerByte; |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 75 | static constexpr int kCurrentMethodStackOffset = 0; |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 76 | static constexpr uint32_t kPackedSwitchCompareJumpThreshold = 7; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 77 | |
| 78 | #ifdef __ |
| 79 | #error "ARM Codegen VIXL macro-assembler macro already defined." |
| 80 | #endif |
| 81 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 82 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 83 | #define __ down_cast<CodeGeneratorARMVIXL*>(codegen)->GetVIXLAssembler()-> // NOLINT |
| 84 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kArmPointerSize, x).Int32Value() |
| 85 | |
| 86 | // Marker that code is yet to be, and must, be implemented. |
| 87 | #define TODO_VIXL32(level) LOG(level) << __PRETTY_FUNCTION__ << " unimplemented " |
| 88 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 89 | // SaveLiveRegisters and RestoreLiveRegisters from SlowPathCodeARM operate on sets of S registers, |
| 90 | // for each live D registers they treat two corresponding S registers as live ones. |
| 91 | // |
| 92 | // Two following functions (SaveContiguousSRegisterList, RestoreContiguousSRegisterList) build |
| 93 | // from a list of contiguous S registers a list of contiguous D registers (processing first/last |
| 94 | // S registers corner cases) and save/restore this new list treating them as D registers. |
| 95 | // - decreasing code size |
| 96 | // - avoiding hazards on Cortex-A57, when a pair of S registers for an actual live D register is |
| 97 | // restored and then used in regular non SlowPath code as D register. |
| 98 | // |
| 99 | // For the following example (v means the S register is live): |
| 100 | // D names: | D0 | D1 | D2 | D4 | ... |
| 101 | // S names: | S0 | S1 | S2 | S3 | S4 | S5 | S6 | S7 | ... |
| 102 | // Live? | | v | v | v | v | v | v | | ... |
| 103 | // |
| 104 | // S1 and S6 will be saved/restored independently; D registers list (D1, D2) will be processed |
| 105 | // as D registers. |
| 106 | // |
| 107 | // TODO(VIXL): All this code should be unnecessary once the VIXL AArch32 backend provides helpers |
| 108 | // for lists of floating-point registers. |
| 109 | static size_t SaveContiguousSRegisterList(size_t first, |
| 110 | size_t last, |
| 111 | CodeGenerator* codegen, |
| 112 | size_t stack_offset) { |
| 113 | static_assert(kSRegSizeInBytes == kArmWordSize, "Broken assumption on reg/word sizes."); |
| 114 | static_assert(kDRegSizeInBytes == 2 * kArmWordSize, "Broken assumption on reg/word sizes."); |
| 115 | DCHECK_LE(first, last); |
| 116 | if ((first == last) && (first == 0)) { |
| 117 | __ Vstr(vixl32::SRegister(first), MemOperand(sp, stack_offset)); |
| 118 | return stack_offset + kSRegSizeInBytes; |
| 119 | } |
| 120 | if (first % 2 == 1) { |
| 121 | __ Vstr(vixl32::SRegister(first++), MemOperand(sp, stack_offset)); |
| 122 | stack_offset += kSRegSizeInBytes; |
| 123 | } |
| 124 | |
| 125 | bool save_last = false; |
| 126 | if (last % 2 == 0) { |
| 127 | save_last = true; |
| 128 | --last; |
| 129 | } |
| 130 | |
| 131 | if (first < last) { |
| 132 | vixl32::DRegister d_reg = vixl32::DRegister(first / 2); |
| 133 | DCHECK_EQ((last - first + 1) % 2, 0u); |
| 134 | size_t number_of_d_regs = (last - first + 1) / 2; |
| 135 | |
| 136 | if (number_of_d_regs == 1) { |
| 137 | __ Vstr(d_reg, MemOperand(sp, stack_offset)); |
| 138 | } else if (number_of_d_regs > 1) { |
| 139 | UseScratchRegisterScope temps(down_cast<CodeGeneratorARMVIXL*>(codegen)->GetVIXLAssembler()); |
| 140 | vixl32::Register base = sp; |
| 141 | if (stack_offset != 0) { |
| 142 | base = temps.Acquire(); |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 143 | __ Add(base, sp, Operand::From(stack_offset)); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 144 | } |
| 145 | __ Vstm(F64, base, NO_WRITE_BACK, DRegisterList(d_reg, number_of_d_regs)); |
| 146 | } |
| 147 | stack_offset += number_of_d_regs * kDRegSizeInBytes; |
| 148 | } |
| 149 | |
| 150 | if (save_last) { |
| 151 | __ Vstr(vixl32::SRegister(last + 1), MemOperand(sp, stack_offset)); |
| 152 | stack_offset += kSRegSizeInBytes; |
| 153 | } |
| 154 | |
| 155 | return stack_offset; |
| 156 | } |
| 157 | |
| 158 | static size_t RestoreContiguousSRegisterList(size_t first, |
| 159 | size_t last, |
| 160 | CodeGenerator* codegen, |
| 161 | size_t stack_offset) { |
| 162 | static_assert(kSRegSizeInBytes == kArmWordSize, "Broken assumption on reg/word sizes."); |
| 163 | static_assert(kDRegSizeInBytes == 2 * kArmWordSize, "Broken assumption on reg/word sizes."); |
| 164 | DCHECK_LE(first, last); |
| 165 | if ((first == last) && (first == 0)) { |
| 166 | __ Vldr(vixl32::SRegister(first), MemOperand(sp, stack_offset)); |
| 167 | return stack_offset + kSRegSizeInBytes; |
| 168 | } |
| 169 | if (first % 2 == 1) { |
| 170 | __ Vldr(vixl32::SRegister(first++), MemOperand(sp, stack_offset)); |
| 171 | stack_offset += kSRegSizeInBytes; |
| 172 | } |
| 173 | |
| 174 | bool restore_last = false; |
| 175 | if (last % 2 == 0) { |
| 176 | restore_last = true; |
| 177 | --last; |
| 178 | } |
| 179 | |
| 180 | if (first < last) { |
| 181 | vixl32::DRegister d_reg = vixl32::DRegister(first / 2); |
| 182 | DCHECK_EQ((last - first + 1) % 2, 0u); |
| 183 | size_t number_of_d_regs = (last - first + 1) / 2; |
| 184 | if (number_of_d_regs == 1) { |
| 185 | __ Vldr(d_reg, MemOperand(sp, stack_offset)); |
| 186 | } else if (number_of_d_regs > 1) { |
| 187 | UseScratchRegisterScope temps(down_cast<CodeGeneratorARMVIXL*>(codegen)->GetVIXLAssembler()); |
| 188 | vixl32::Register base = sp; |
| 189 | if (stack_offset != 0) { |
| 190 | base = temps.Acquire(); |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 191 | __ Add(base, sp, Operand::From(stack_offset)); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 192 | } |
| 193 | __ Vldm(F64, base, NO_WRITE_BACK, DRegisterList(d_reg, number_of_d_regs)); |
| 194 | } |
| 195 | stack_offset += number_of_d_regs * kDRegSizeInBytes; |
| 196 | } |
| 197 | |
| 198 | if (restore_last) { |
| 199 | __ Vldr(vixl32::SRegister(last + 1), MemOperand(sp, stack_offset)); |
| 200 | stack_offset += kSRegSizeInBytes; |
| 201 | } |
| 202 | |
| 203 | return stack_offset; |
| 204 | } |
| 205 | |
| 206 | void SlowPathCodeARMVIXL::SaveLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) { |
| 207 | size_t stack_offset = codegen->GetFirstRegisterSlotInSlowPath(); |
| 208 | size_t orig_offset = stack_offset; |
| 209 | |
| 210 | const uint32_t core_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ true); |
| 211 | for (uint32_t i : LowToHighBits(core_spills)) { |
| 212 | // If the register holds an object, update the stack mask. |
| 213 | if (locations->RegisterContainsObject(i)) { |
| 214 | locations->SetStackBit(stack_offset / kVRegSize); |
| 215 | } |
| 216 | DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 217 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 218 | saved_core_stack_offsets_[i] = stack_offset; |
| 219 | stack_offset += kArmWordSize; |
| 220 | } |
| 221 | |
| 222 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 223 | arm_codegen->GetAssembler()->StoreRegisterList(core_spills, orig_offset); |
| 224 | |
| 225 | uint32_t fp_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ false); |
| 226 | orig_offset = stack_offset; |
| 227 | for (uint32_t i : LowToHighBits(fp_spills)) { |
| 228 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 229 | saved_fpu_stack_offsets_[i] = stack_offset; |
| 230 | stack_offset += kArmWordSize; |
| 231 | } |
| 232 | |
| 233 | stack_offset = orig_offset; |
| 234 | while (fp_spills != 0u) { |
| 235 | uint32_t begin = CTZ(fp_spills); |
| 236 | uint32_t tmp = fp_spills + (1u << begin); |
| 237 | fp_spills &= tmp; // Clear the contiguous range of 1s. |
| 238 | uint32_t end = (tmp == 0u) ? 32u : CTZ(tmp); // CTZ(0) is undefined. |
| 239 | stack_offset = SaveContiguousSRegisterList(begin, end - 1, codegen, stack_offset); |
| 240 | } |
| 241 | DCHECK_LE(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 242 | } |
| 243 | |
| 244 | void SlowPathCodeARMVIXL::RestoreLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) { |
| 245 | size_t stack_offset = codegen->GetFirstRegisterSlotInSlowPath(); |
| 246 | size_t orig_offset = stack_offset; |
| 247 | |
| 248 | const uint32_t core_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ true); |
| 249 | for (uint32_t i : LowToHighBits(core_spills)) { |
| 250 | DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 251 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 252 | stack_offset += kArmWordSize; |
| 253 | } |
| 254 | |
| 255 | // TODO(VIXL): Check the coherency of stack_offset after this with a test. |
| 256 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 257 | arm_codegen->GetAssembler()->LoadRegisterList(core_spills, orig_offset); |
| 258 | |
| 259 | uint32_t fp_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ false); |
| 260 | while (fp_spills != 0u) { |
| 261 | uint32_t begin = CTZ(fp_spills); |
| 262 | uint32_t tmp = fp_spills + (1u << begin); |
| 263 | fp_spills &= tmp; // Clear the contiguous range of 1s. |
| 264 | uint32_t end = (tmp == 0u) ? 32u : CTZ(tmp); // CTZ(0) is undefined. |
| 265 | stack_offset = RestoreContiguousSRegisterList(begin, end - 1, codegen, stack_offset); |
| 266 | } |
| 267 | DCHECK_LE(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 268 | } |
| 269 | |
| 270 | class NullCheckSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 271 | public: |
| 272 | explicit NullCheckSlowPathARMVIXL(HNullCheck* instruction) : SlowPathCodeARMVIXL(instruction) {} |
| 273 | |
| 274 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 275 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 276 | __ Bind(GetEntryLabel()); |
| 277 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 278 | // Live registers will be restored in the catch block if caught. |
| 279 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 280 | } |
| 281 | arm_codegen->InvokeRuntime(kQuickThrowNullPointer, |
| 282 | instruction_, |
| 283 | instruction_->GetDexPc(), |
| 284 | this); |
| 285 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); |
| 286 | } |
| 287 | |
| 288 | bool IsFatal() const OVERRIDE { return true; } |
| 289 | |
| 290 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathARMVIXL"; } |
| 291 | |
| 292 | private: |
| 293 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathARMVIXL); |
| 294 | }; |
| 295 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 296 | class DivZeroCheckSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 297 | public: |
| 298 | explicit DivZeroCheckSlowPathARMVIXL(HDivZeroCheck* instruction) |
| 299 | : SlowPathCodeARMVIXL(instruction) {} |
| 300 | |
| 301 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 302 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 303 | __ Bind(GetEntryLabel()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 304 | arm_codegen->InvokeRuntime(kQuickThrowDivZero, instruction_, instruction_->GetDexPc(), this); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 305 | CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); |
| 306 | } |
| 307 | |
| 308 | bool IsFatal() const OVERRIDE { return true; } |
| 309 | |
| 310 | const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathARMVIXL"; } |
| 311 | |
| 312 | private: |
| 313 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathARMVIXL); |
| 314 | }; |
| 315 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 316 | class SuspendCheckSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 317 | public: |
| 318 | SuspendCheckSlowPathARMVIXL(HSuspendCheck* instruction, HBasicBlock* successor) |
| 319 | : SlowPathCodeARMVIXL(instruction), successor_(successor) {} |
| 320 | |
| 321 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 322 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 323 | __ Bind(GetEntryLabel()); |
| 324 | arm_codegen->InvokeRuntime(kQuickTestSuspend, instruction_, instruction_->GetDexPc(), this); |
| 325 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
| 326 | if (successor_ == nullptr) { |
| 327 | __ B(GetReturnLabel()); |
| 328 | } else { |
| 329 | __ B(arm_codegen->GetLabelOf(successor_)); |
| 330 | } |
| 331 | } |
| 332 | |
| 333 | vixl32::Label* GetReturnLabel() { |
| 334 | DCHECK(successor_ == nullptr); |
| 335 | return &return_label_; |
| 336 | } |
| 337 | |
| 338 | HBasicBlock* GetSuccessor() const { |
| 339 | return successor_; |
| 340 | } |
| 341 | |
| 342 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathARMVIXL"; } |
| 343 | |
| 344 | private: |
| 345 | // If not null, the block to branch to after the suspend check. |
| 346 | HBasicBlock* const successor_; |
| 347 | |
| 348 | // If `successor_` is null, the label to branch to after the suspend check. |
| 349 | vixl32::Label return_label_; |
| 350 | |
| 351 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathARMVIXL); |
| 352 | }; |
| 353 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 354 | class BoundsCheckSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 355 | public: |
| 356 | explicit BoundsCheckSlowPathARMVIXL(HBoundsCheck* instruction) |
| 357 | : SlowPathCodeARMVIXL(instruction) {} |
| 358 | |
| 359 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 360 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 361 | LocationSummary* locations = instruction_->GetLocations(); |
| 362 | |
| 363 | __ Bind(GetEntryLabel()); |
| 364 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 365 | // Live registers will be restored in the catch block if caught. |
| 366 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 367 | } |
| 368 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 369 | // move resolver. |
| 370 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 371 | codegen->EmitParallelMoves( |
| 372 | locations->InAt(0), |
| 373 | LocationFrom(calling_convention.GetRegisterAt(0)), |
| 374 | Primitive::kPrimInt, |
| 375 | locations->InAt(1), |
| 376 | LocationFrom(calling_convention.GetRegisterAt(1)), |
| 377 | Primitive::kPrimInt); |
| 378 | QuickEntrypointEnum entrypoint = instruction_->AsBoundsCheck()->IsStringCharAt() |
| 379 | ? kQuickThrowStringBounds |
| 380 | : kQuickThrowArrayBounds; |
| 381 | arm_codegen->InvokeRuntime(entrypoint, instruction_, instruction_->GetDexPc(), this); |
| 382 | CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>(); |
| 383 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
| 384 | } |
| 385 | |
| 386 | bool IsFatal() const OVERRIDE { return true; } |
| 387 | |
| 388 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathARMVIXL"; } |
| 389 | |
| 390 | private: |
| 391 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathARMVIXL); |
| 392 | }; |
| 393 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 394 | class LoadClassSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 395 | public: |
| 396 | LoadClassSlowPathARMVIXL(HLoadClass* cls, HInstruction* at, uint32_t dex_pc, bool do_clinit) |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 397 | : SlowPathCodeARMVIXL(at), cls_(cls), dex_pc_(dex_pc), do_clinit_(do_clinit) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 398 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 399 | } |
| 400 | |
| 401 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 402 | LocationSummary* locations = instruction_->GetLocations(); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 403 | Location out = locations->Out(); |
| 404 | constexpr bool call_saves_everything_except_r0 = (!kUseReadBarrier || kUseBakerReadBarrier); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 405 | |
| 406 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 407 | __ Bind(GetEntryLabel()); |
| 408 | SaveLiveRegisters(codegen, locations); |
| 409 | |
| 410 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 411 | // For HLoadClass/kBssEntry/kSaveEverything, make sure we preserve the address of the entry. |
| 412 | DCHECK_EQ(instruction_->IsLoadClass(), cls_ == instruction_); |
| 413 | bool is_load_class_bss_entry = |
| 414 | (cls_ == instruction_) && (cls_->GetLoadKind() == HLoadClass::LoadKind::kBssEntry); |
| 415 | vixl32::Register entry_address; |
| 416 | if (is_load_class_bss_entry && call_saves_everything_except_r0) { |
| 417 | vixl32::Register temp = RegisterFrom(locations->GetTemp(0)); |
| 418 | // In the unlucky case that the `temp` is R0, we preserve the address in `out` across |
| 419 | // the kSaveEverything call. |
| 420 | bool temp_is_r0 = temp.Is(calling_convention.GetRegisterAt(0)); |
| 421 | entry_address = temp_is_r0 ? RegisterFrom(out) : temp; |
| 422 | DCHECK(!entry_address.Is(calling_convention.GetRegisterAt(0))); |
| 423 | if (temp_is_r0) { |
| 424 | __ Mov(entry_address, temp); |
| 425 | } |
| 426 | } |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 427 | dex::TypeIndex type_index = cls_->GetTypeIndex(); |
| 428 | __ Mov(calling_convention.GetRegisterAt(0), type_index.index_); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 429 | QuickEntrypointEnum entrypoint = do_clinit_ ? kQuickInitializeStaticStorage |
| 430 | : kQuickInitializeType; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 431 | arm_codegen->InvokeRuntime(entrypoint, instruction_, dex_pc_, this); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 432 | if (do_clinit_) { |
| 433 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>(); |
| 434 | } else { |
| 435 | CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>(); |
| 436 | } |
| 437 | |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 438 | // For HLoadClass/kBssEntry, store the resolved Class to the BSS entry. |
| 439 | if (is_load_class_bss_entry) { |
| 440 | if (call_saves_everything_except_r0) { |
| 441 | // The class entry address was preserved in `entry_address` thanks to kSaveEverything. |
| 442 | __ Str(r0, MemOperand(entry_address)); |
| 443 | } else { |
| 444 | // For non-Baker read barrier, we need to re-calculate the address of the string entry. |
| 445 | UseScratchRegisterScope temps( |
| 446 | down_cast<CodeGeneratorARMVIXL*>(codegen)->GetVIXLAssembler()); |
| 447 | vixl32::Register temp = temps.Acquire(); |
| 448 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels = |
| 449 | arm_codegen->NewTypeBssEntryPatch(cls_->GetDexFile(), type_index); |
| 450 | arm_codegen->EmitMovwMovtPlaceholder(labels, temp); |
| 451 | __ Str(r0, MemOperand(temp)); |
| 452 | } |
| 453 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 454 | // Move the class to the desired location. |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 455 | if (out.IsValid()) { |
| 456 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
| 457 | arm_codegen->Move32(locations->Out(), LocationFrom(r0)); |
| 458 | } |
| 459 | RestoreLiveRegisters(codegen, locations); |
| 460 | __ B(GetExitLabel()); |
| 461 | } |
| 462 | |
| 463 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathARMVIXL"; } |
| 464 | |
| 465 | private: |
| 466 | // The class this slow path will load. |
| 467 | HLoadClass* const cls_; |
| 468 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 469 | // The dex PC of `at_`. |
| 470 | const uint32_t dex_pc_; |
| 471 | |
| 472 | // Whether to initialize the class. |
| 473 | const bool do_clinit_; |
| 474 | |
| 475 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathARMVIXL); |
| 476 | }; |
| 477 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 478 | class LoadStringSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 479 | public: |
| 480 | explicit LoadStringSlowPathARMVIXL(HLoadString* instruction) |
| 481 | : SlowPathCodeARMVIXL(instruction) {} |
| 482 | |
| 483 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 484 | DCHECK(instruction_->IsLoadString()); |
| 485 | DCHECK_EQ(instruction_->AsLoadString()->GetLoadKind(), HLoadString::LoadKind::kBssEntry); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 486 | LocationSummary* locations = instruction_->GetLocations(); |
| 487 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 488 | HLoadString* load = instruction_->AsLoadString(); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 489 | const dex::StringIndex string_index = load->GetStringIndex(); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 490 | vixl32::Register out = OutputRegister(load); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 491 | constexpr bool call_saves_everything_except_r0 = (!kUseReadBarrier || kUseBakerReadBarrier); |
| 492 | |
| 493 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 494 | __ Bind(GetEntryLabel()); |
| 495 | SaveLiveRegisters(codegen, locations); |
| 496 | |
| 497 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 498 | // 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] | 499 | // the kSaveEverything call. |
| 500 | vixl32::Register entry_address; |
| 501 | if (call_saves_everything_except_r0) { |
| 502 | vixl32::Register temp = RegisterFrom(locations->GetTemp(0)); |
| 503 | bool temp_is_r0 = (temp.Is(calling_convention.GetRegisterAt(0))); |
| 504 | entry_address = temp_is_r0 ? out : temp; |
| 505 | DCHECK(!entry_address.Is(calling_convention.GetRegisterAt(0))); |
| 506 | if (temp_is_r0) { |
| 507 | __ Mov(entry_address, temp); |
| 508 | } |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 509 | } |
| 510 | |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 511 | __ Mov(calling_convention.GetRegisterAt(0), string_index.index_); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 512 | arm_codegen->InvokeRuntime(kQuickResolveString, instruction_, instruction_->GetDexPc(), this); |
| 513 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
| 514 | |
| 515 | // Store the resolved String to the .bss entry. |
| 516 | if (call_saves_everything_except_r0) { |
| 517 | // The string entry address was preserved in `entry_address` thanks to kSaveEverything. |
| 518 | __ Str(r0, MemOperand(entry_address)); |
| 519 | } else { |
| 520 | // 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] | 521 | UseScratchRegisterScope temps( |
| 522 | down_cast<CodeGeneratorARMVIXL*>(codegen)->GetVIXLAssembler()); |
| 523 | vixl32::Register temp = temps.Acquire(); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 524 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels = |
| 525 | arm_codegen->NewPcRelativeStringPatch(load->GetDexFile(), string_index); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 526 | arm_codegen->EmitMovwMovtPlaceholder(labels, temp); |
| 527 | __ Str(r0, MemOperand(temp)); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 528 | } |
| 529 | |
| 530 | arm_codegen->Move32(locations->Out(), LocationFrom(r0)); |
| 531 | RestoreLiveRegisters(codegen, locations); |
| 532 | |
| 533 | __ B(GetExitLabel()); |
| 534 | } |
| 535 | |
| 536 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathARMVIXL"; } |
| 537 | |
| 538 | private: |
| 539 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathARMVIXL); |
| 540 | }; |
| 541 | |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 542 | class TypeCheckSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 543 | public: |
| 544 | TypeCheckSlowPathARMVIXL(HInstruction* instruction, bool is_fatal) |
| 545 | : SlowPathCodeARMVIXL(instruction), is_fatal_(is_fatal) {} |
| 546 | |
| 547 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 548 | LocationSummary* locations = instruction_->GetLocations(); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 549 | DCHECK(instruction_->IsCheckCast() |
| 550 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 551 | |
| 552 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 553 | __ Bind(GetEntryLabel()); |
| 554 | |
| 555 | if (!is_fatal_) { |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 556 | SaveLiveRegisters(codegen, locations); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 557 | } |
| 558 | |
| 559 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 560 | // move resolver. |
| 561 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 562 | |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 563 | codegen->EmitParallelMoves(locations->InAt(0), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 564 | LocationFrom(calling_convention.GetRegisterAt(0)), |
| 565 | Primitive::kPrimNot, |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 566 | locations->InAt(1), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 567 | LocationFrom(calling_convention.GetRegisterAt(1)), |
| 568 | Primitive::kPrimNot); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 569 | if (instruction_->IsInstanceOf()) { |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 570 | arm_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, |
| 571 | instruction_, |
| 572 | instruction_->GetDexPc(), |
| 573 | this); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 574 | CheckEntrypointTypes<kQuickInstanceofNonTrivial, size_t, mirror::Object*, mirror::Class*>(); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 575 | arm_codegen->Move32(locations->Out(), LocationFrom(r0)); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 576 | } else { |
| 577 | DCHECK(instruction_->IsCheckCast()); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 578 | arm_codegen->InvokeRuntime(kQuickCheckInstanceOf, |
| 579 | instruction_, |
| 580 | instruction_->GetDexPc(), |
| 581 | this); |
| 582 | CheckEntrypointTypes<kQuickCheckInstanceOf, void, mirror::Object*, mirror::Class*>(); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 583 | } |
| 584 | |
| 585 | if (!is_fatal_) { |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 586 | RestoreLiveRegisters(codegen, locations); |
| 587 | __ B(GetExitLabel()); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 588 | } |
| 589 | } |
| 590 | |
| 591 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathARMVIXL"; } |
| 592 | |
| 593 | bool IsFatal() const OVERRIDE { return is_fatal_; } |
| 594 | |
| 595 | private: |
| 596 | const bool is_fatal_; |
| 597 | |
| 598 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathARMVIXL); |
| 599 | }; |
| 600 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 601 | class DeoptimizationSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 602 | public: |
| 603 | explicit DeoptimizationSlowPathARMVIXL(HDeoptimize* instruction) |
| 604 | : SlowPathCodeARMVIXL(instruction) {} |
| 605 | |
| 606 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 607 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 608 | __ Bind(GetEntryLabel()); |
| 609 | arm_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this); |
| 610 | CheckEntrypointTypes<kQuickDeoptimize, void, void>(); |
| 611 | } |
| 612 | |
| 613 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathARMVIXL"; } |
| 614 | |
| 615 | private: |
| 616 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathARMVIXL); |
| 617 | }; |
| 618 | |
| 619 | class ArraySetSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 620 | public: |
| 621 | explicit ArraySetSlowPathARMVIXL(HInstruction* instruction) : SlowPathCodeARMVIXL(instruction) {} |
| 622 | |
| 623 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 624 | LocationSummary* locations = instruction_->GetLocations(); |
| 625 | __ Bind(GetEntryLabel()); |
| 626 | SaveLiveRegisters(codegen, locations); |
| 627 | |
| 628 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 629 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 630 | parallel_move.AddMove( |
| 631 | locations->InAt(0), |
| 632 | LocationFrom(calling_convention.GetRegisterAt(0)), |
| 633 | Primitive::kPrimNot, |
| 634 | nullptr); |
| 635 | parallel_move.AddMove( |
| 636 | locations->InAt(1), |
| 637 | LocationFrom(calling_convention.GetRegisterAt(1)), |
| 638 | Primitive::kPrimInt, |
| 639 | nullptr); |
| 640 | parallel_move.AddMove( |
| 641 | locations->InAt(2), |
| 642 | LocationFrom(calling_convention.GetRegisterAt(2)), |
| 643 | Primitive::kPrimNot, |
| 644 | nullptr); |
| 645 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 646 | |
| 647 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 648 | arm_codegen->InvokeRuntime(kQuickAputObject, instruction_, instruction_->GetDexPc(), this); |
| 649 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
| 650 | RestoreLiveRegisters(codegen, locations); |
| 651 | __ B(GetExitLabel()); |
| 652 | } |
| 653 | |
| 654 | const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathARMVIXL"; } |
| 655 | |
| 656 | private: |
| 657 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathARMVIXL); |
| 658 | }; |
| 659 | |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 660 | // Slow path marking an object reference `ref` during a read |
| 661 | // barrier. The field `obj.field` in the object `obj` holding this |
| 662 | // reference does not get updated by this slow path after marking (see |
| 663 | // ReadBarrierMarkAndUpdateFieldSlowPathARM below for that). |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 664 | // |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 665 | // This means that after the execution of this slow path, `ref` will |
| 666 | // always be up-to-date, but `obj.field` may not; i.e., after the |
| 667 | // flip, `ref` will be a to-space reference, but `obj.field` will |
| 668 | // probably still be a from-space reference (unless it gets updated by |
| 669 | // another thread, or if another thread installed another object |
| 670 | // reference (different from `ref`) in `obj.field`). |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 671 | class ReadBarrierMarkSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 672 | public: |
| 673 | ReadBarrierMarkSlowPathARMVIXL(HInstruction* instruction, |
| 674 | Location ref, |
| 675 | Location entrypoint = Location::NoLocation()) |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 676 | : SlowPathCodeARMVIXL(instruction), ref_(ref), entrypoint_(entrypoint) { |
| 677 | DCHECK(kEmitCompilerReadBarrier); |
| 678 | } |
| 679 | |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 680 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathARMVIXL"; } |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 681 | |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 682 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 683 | LocationSummary* locations = instruction_->GetLocations(); |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 684 | vixl32::Register ref_reg = RegisterFrom(ref_); |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 685 | DCHECK(locations->CanCall()); |
| 686 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg.GetCode())) << ref_reg; |
| 687 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 688 | instruction_->IsStaticFieldGet() || |
| 689 | instruction_->IsArrayGet() || |
| 690 | instruction_->IsArraySet() || |
| 691 | instruction_->IsLoadClass() || |
| 692 | instruction_->IsLoadString() || |
| 693 | instruction_->IsInstanceOf() || |
| 694 | instruction_->IsCheckCast() || |
| 695 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()) || |
| 696 | (instruction_->IsInvokeStaticOrDirect() && instruction_->GetLocations()->Intrinsified())) |
| 697 | << "Unexpected instruction in read barrier marking slow path: " |
| 698 | << instruction_->DebugName(); |
| 699 | // The read barrier instrumentation of object ArrayGet |
| 700 | // instructions does not support the HIntermediateAddress |
| 701 | // instruction. |
| 702 | DCHECK(!(instruction_->IsArrayGet() && |
| 703 | instruction_->AsArrayGet()->GetArray()->IsIntermediateAddress())); |
| 704 | |
| 705 | __ Bind(GetEntryLabel()); |
| 706 | // No need to save live registers; it's taken care of by the |
| 707 | // entrypoint. Also, there is no need to update the stack mask, |
| 708 | // as this runtime call will not trigger a garbage collection. |
| 709 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 710 | DCHECK(!ref_reg.Is(sp)); |
| 711 | DCHECK(!ref_reg.Is(lr)); |
| 712 | DCHECK(!ref_reg.Is(pc)); |
| 713 | // IP is used internally by the ReadBarrierMarkRegX entry point |
| 714 | // as a temporary, it cannot be the entry point's input/output. |
| 715 | DCHECK(!ref_reg.Is(ip)); |
| 716 | DCHECK(ref_reg.IsRegister()) << ref_reg; |
| 717 | // "Compact" slow path, saving two moves. |
| 718 | // |
| 719 | // Instead of using the standard runtime calling convention (input |
| 720 | // and output in R0): |
| 721 | // |
| 722 | // R0 <- ref |
| 723 | // R0 <- ReadBarrierMark(R0) |
| 724 | // ref <- R0 |
| 725 | // |
| 726 | // we just use rX (the register containing `ref`) as input and output |
| 727 | // of a dedicated entrypoint: |
| 728 | // |
| 729 | // rX <- ReadBarrierMarkRegX(rX) |
| 730 | // |
| 731 | if (entrypoint_.IsValid()) { |
| 732 | arm_codegen->ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction_, this); |
| 733 | __ Blx(RegisterFrom(entrypoint_)); |
| 734 | } else { |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 735 | int32_t entry_point_offset = |
| 736 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArmPointerSize>(ref_reg.GetCode()); |
| 737 | // This runtime call does not require a stack map. |
| 738 | arm_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
| 739 | } |
| 740 | __ B(GetExitLabel()); |
| 741 | } |
| 742 | |
| 743 | private: |
| 744 | // The location (register) of the marked object reference. |
| 745 | const Location ref_; |
| 746 | |
| 747 | // The location of the entrypoint if already loaded. |
| 748 | const Location entrypoint_; |
| 749 | |
| 750 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathARMVIXL); |
| 751 | }; |
| 752 | |
| 753 | // Slow path marking an object reference `ref` during a read barrier, |
| 754 | // and if needed, atomically updating the field `obj.field` in the |
| 755 | // object `obj` holding this reference after marking (contrary to |
| 756 | // ReadBarrierMarkSlowPathARM above, which never tries to update |
| 757 | // `obj.field`). |
| 758 | // |
| 759 | // This means that after the execution of this slow path, both `ref` |
| 760 | // and `obj.field` will be up-to-date; i.e., after the flip, both will |
| 761 | // hold the same to-space reference (unless another thread installed |
| 762 | // another object reference (different from `ref`) in `obj.field`). |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 763 | class ReadBarrierMarkAndUpdateFieldSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 764 | public: |
| 765 | ReadBarrierMarkAndUpdateFieldSlowPathARMVIXL(HInstruction* instruction, |
| 766 | Location ref, |
| 767 | vixl32::Register obj, |
| 768 | Location field_offset, |
| 769 | vixl32::Register temp1, |
Roland Levillain | 35345a5 | 2017-02-27 14:32:08 +0000 | [diff] [blame] | 770 | vixl32::Register temp2) |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 771 | : SlowPathCodeARMVIXL(instruction), |
| 772 | ref_(ref), |
| 773 | obj_(obj), |
| 774 | field_offset_(field_offset), |
| 775 | temp1_(temp1), |
Roland Levillain | 35345a5 | 2017-02-27 14:32:08 +0000 | [diff] [blame] | 776 | temp2_(temp2) { |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 777 | DCHECK(kEmitCompilerReadBarrier); |
| 778 | } |
| 779 | |
| 780 | const char* GetDescription() const OVERRIDE { |
| 781 | return "ReadBarrierMarkAndUpdateFieldSlowPathARMVIXL"; |
| 782 | } |
| 783 | |
| 784 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 785 | LocationSummary* locations = instruction_->GetLocations(); |
| 786 | vixl32::Register ref_reg = RegisterFrom(ref_); |
| 787 | DCHECK(locations->CanCall()); |
| 788 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg.GetCode())) << ref_reg; |
| 789 | // This slow path is only used by the UnsafeCASObject intrinsic. |
| 790 | DCHECK((instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
| 791 | << "Unexpected instruction in read barrier marking and field updating slow path: " |
| 792 | << instruction_->DebugName(); |
| 793 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 794 | DCHECK_EQ(instruction_->AsInvoke()->GetIntrinsic(), Intrinsics::kUnsafeCASObject); |
| 795 | DCHECK(field_offset_.IsRegisterPair()) << field_offset_; |
| 796 | |
| 797 | __ Bind(GetEntryLabel()); |
| 798 | |
| 799 | // Save the old reference. |
| 800 | // Note that we cannot use IP to save the old reference, as IP is |
| 801 | // used internally by the ReadBarrierMarkRegX entry point, and we |
| 802 | // need the old reference after the call to that entry point. |
| 803 | DCHECK(!temp1_.Is(ip)); |
| 804 | __ Mov(temp1_, ref_reg); |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 805 | |
| 806 | // No need to save live registers; it's taken care of by the |
| 807 | // entrypoint. Also, there is no need to update the stack mask, |
| 808 | // as this runtime call will not trigger a garbage collection. |
| 809 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 810 | DCHECK(!ref_reg.Is(sp)); |
| 811 | DCHECK(!ref_reg.Is(lr)); |
| 812 | DCHECK(!ref_reg.Is(pc)); |
| 813 | // IP is used internally by the ReadBarrierMarkRegX entry point |
| 814 | // as a temporary, it cannot be the entry point's input/output. |
| 815 | DCHECK(!ref_reg.Is(ip)); |
| 816 | DCHECK(ref_reg.IsRegister()) << ref_reg; |
| 817 | // "Compact" slow path, saving two moves. |
| 818 | // |
| 819 | // Instead of using the standard runtime calling convention (input |
| 820 | // and output in R0): |
| 821 | // |
| 822 | // R0 <- ref |
| 823 | // R0 <- ReadBarrierMark(R0) |
| 824 | // ref <- R0 |
| 825 | // |
| 826 | // we just use rX (the register containing `ref`) as input and output |
| 827 | // of a dedicated entrypoint: |
| 828 | // |
| 829 | // rX <- ReadBarrierMarkRegX(rX) |
| 830 | // |
Roland Levillain | 35345a5 | 2017-02-27 14:32:08 +0000 | [diff] [blame] | 831 | int32_t entry_point_offset = |
| 832 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArmPointerSize>(ref_reg.GetCode()); |
| 833 | // This runtime call does not require a stack map. |
| 834 | arm_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 835 | |
| 836 | // If the new reference is different from the old reference, |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 837 | // update the field in the holder (`*(obj_ + field_offset_)`). |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 838 | // |
| 839 | // Note that this field could also hold a different object, if |
| 840 | // another thread had concurrently changed it. In that case, the |
| 841 | // LDREX/SUBS/ITNE sequence of instructions in the compare-and-set |
| 842 | // (CAS) operation below would abort the CAS, leaving the field |
| 843 | // as-is. |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 844 | vixl32::Label done; |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 845 | __ Cmp(temp1_, ref_reg); |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 846 | __ B(eq, &done, /* far_target */ false); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 847 | |
| 848 | // Update the the holder's field atomically. This may fail if |
| 849 | // mutator updates before us, but it's OK. This is achieved |
| 850 | // using a strong compare-and-set (CAS) operation with relaxed |
| 851 | // memory synchronization ordering, where the expected value is |
| 852 | // the old reference and the desired value is the new reference. |
| 853 | |
| 854 | UseScratchRegisterScope temps(arm_codegen->GetVIXLAssembler()); |
| 855 | // Convenience aliases. |
| 856 | vixl32::Register base = obj_; |
| 857 | // The UnsafeCASObject intrinsic uses a register pair as field |
| 858 | // offset ("long offset"), of which only the low part contains |
| 859 | // data. |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 860 | vixl32::Register offset = LowRegisterFrom(field_offset_); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 861 | vixl32::Register expected = temp1_; |
| 862 | vixl32::Register value = ref_reg; |
| 863 | vixl32::Register tmp_ptr = temps.Acquire(); // Pointer to actual memory. |
| 864 | vixl32::Register tmp = temp2_; // Value in memory. |
| 865 | |
| 866 | __ Add(tmp_ptr, base, offset); |
| 867 | |
| 868 | if (kPoisonHeapReferences) { |
| 869 | arm_codegen->GetAssembler()->PoisonHeapReference(expected); |
| 870 | if (value.Is(expected)) { |
| 871 | // Do not poison `value`, as it is the same register as |
| 872 | // `expected`, which has just been poisoned. |
| 873 | } else { |
| 874 | arm_codegen->GetAssembler()->PoisonHeapReference(value); |
| 875 | } |
| 876 | } |
| 877 | |
| 878 | // do { |
| 879 | // tmp = [r_ptr] - expected; |
| 880 | // } while (tmp == 0 && failure([r_ptr] <- r_new_value)); |
| 881 | |
| 882 | vixl32::Label loop_head, exit_loop; |
| 883 | __ Bind(&loop_head); |
| 884 | |
| 885 | __ Ldrex(tmp, MemOperand(tmp_ptr)); |
| 886 | |
| 887 | __ Subs(tmp, tmp, expected); |
| 888 | |
| 889 | { |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 890 | ExactAssemblyScope aas(arm_codegen->GetVIXLAssembler(), |
| 891 | 2 * kMaxInstructionSizeInBytes, |
| 892 | CodeBufferCheckScope::kMaximumSize); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 893 | |
| 894 | __ it(ne); |
| 895 | __ clrex(ne); |
| 896 | } |
| 897 | |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 898 | __ B(ne, &exit_loop, /* far_target */ false); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 899 | |
| 900 | __ Strex(tmp, value, MemOperand(tmp_ptr)); |
| 901 | __ Cmp(tmp, 1); |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 902 | __ B(eq, &loop_head, /* far_target */ false); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 903 | |
| 904 | __ Bind(&exit_loop); |
| 905 | |
| 906 | if (kPoisonHeapReferences) { |
| 907 | arm_codegen->GetAssembler()->UnpoisonHeapReference(expected); |
| 908 | if (value.Is(expected)) { |
| 909 | // Do not unpoison `value`, as it is the same register as |
| 910 | // `expected`, which has just been unpoisoned. |
| 911 | } else { |
| 912 | arm_codegen->GetAssembler()->UnpoisonHeapReference(value); |
| 913 | } |
| 914 | } |
| 915 | |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 916 | __ Bind(&done); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 917 | __ B(GetExitLabel()); |
| 918 | } |
| 919 | |
| 920 | private: |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 921 | // The location (register) of the marked object reference. |
| 922 | const Location ref_; |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 923 | // The register containing the object holding the marked object reference field. |
| 924 | const vixl32::Register obj_; |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 925 | // The location of the offset of the marked reference field within `obj_`. |
| 926 | Location field_offset_; |
| 927 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 928 | const vixl32::Register temp1_; |
| 929 | const vixl32::Register temp2_; |
| 930 | |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 931 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkAndUpdateFieldSlowPathARMVIXL); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 932 | }; |
| 933 | |
| 934 | // Slow path generating a read barrier for a heap reference. |
| 935 | class ReadBarrierForHeapReferenceSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 936 | public: |
| 937 | ReadBarrierForHeapReferenceSlowPathARMVIXL(HInstruction* instruction, |
| 938 | Location out, |
| 939 | Location ref, |
| 940 | Location obj, |
| 941 | uint32_t offset, |
| 942 | Location index) |
| 943 | : SlowPathCodeARMVIXL(instruction), |
| 944 | out_(out), |
| 945 | ref_(ref), |
| 946 | obj_(obj), |
| 947 | offset_(offset), |
| 948 | index_(index) { |
| 949 | DCHECK(kEmitCompilerReadBarrier); |
| 950 | // If `obj` is equal to `out` or `ref`, it means the initial object |
| 951 | // has been overwritten by (or after) the heap object reference load |
| 952 | // to be instrumented, e.g.: |
| 953 | // |
| 954 | // __ LoadFromOffset(kLoadWord, out, out, offset); |
| 955 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
| 956 | // |
| 957 | // In that case, we have lost the information about the original |
| 958 | // object, and the emitted read barrier cannot work properly. |
| 959 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 960 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 961 | } |
| 962 | |
| 963 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 964 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 965 | LocationSummary* locations = instruction_->GetLocations(); |
| 966 | vixl32::Register reg_out = RegisterFrom(out_); |
| 967 | DCHECK(locations->CanCall()); |
| 968 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out.GetCode())); |
| 969 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 970 | instruction_->IsStaticFieldGet() || |
| 971 | instruction_->IsArrayGet() || |
| 972 | instruction_->IsInstanceOf() || |
| 973 | instruction_->IsCheckCast() || |
| 974 | (instruction_->IsInvokeVirtual()) && instruction_->GetLocations()->Intrinsified()) |
| 975 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 976 | << instruction_->DebugName(); |
| 977 | // The read barrier instrumentation of object ArrayGet |
| 978 | // instructions does not support the HIntermediateAddress |
| 979 | // instruction. |
| 980 | DCHECK(!(instruction_->IsArrayGet() && |
| 981 | instruction_->AsArrayGet()->GetArray()->IsIntermediateAddress())); |
| 982 | |
| 983 | __ Bind(GetEntryLabel()); |
| 984 | SaveLiveRegisters(codegen, locations); |
| 985 | |
| 986 | // We may have to change the index's value, but as `index_` is a |
| 987 | // constant member (like other "inputs" of this slow path), |
| 988 | // introduce a copy of it, `index`. |
| 989 | Location index = index_; |
| 990 | if (index_.IsValid()) { |
| 991 | // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
| 992 | if (instruction_->IsArrayGet()) { |
| 993 | // Compute the actual memory offset and store it in `index`. |
| 994 | vixl32::Register index_reg = RegisterFrom(index_); |
| 995 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_reg.GetCode())); |
| 996 | if (codegen->IsCoreCalleeSaveRegister(index_reg.GetCode())) { |
| 997 | // We are about to change the value of `index_reg` (see the |
| 998 | // calls to art::arm::Thumb2Assembler::Lsl and |
| 999 | // art::arm::Thumb2Assembler::AddConstant below), but it has |
| 1000 | // not been saved by the previous call to |
| 1001 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 1002 | // callee-save register -- |
| 1003 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 1004 | // callee-save registers, as it has been designed with the |
| 1005 | // assumption that callee-save registers are supposed to be |
| 1006 | // handled by the called function. So, as a callee-save |
| 1007 | // register, `index_reg` _would_ eventually be saved onto |
| 1008 | // the stack, but it would be too late: we would have |
| 1009 | // changed its value earlier. Therefore, we manually save |
| 1010 | // it here into another freely available register, |
| 1011 | // `free_reg`, chosen of course among the caller-save |
| 1012 | // registers (as a callee-save `free_reg` register would |
| 1013 | // exhibit the same problem). |
| 1014 | // |
| 1015 | // Note we could have requested a temporary register from |
| 1016 | // the register allocator instead; but we prefer not to, as |
| 1017 | // this is a slow path, and we know we can find a |
| 1018 | // caller-save register that is available. |
| 1019 | vixl32::Register free_reg = FindAvailableCallerSaveRegister(codegen); |
| 1020 | __ Mov(free_reg, index_reg); |
| 1021 | index_reg = free_reg; |
| 1022 | index = LocationFrom(index_reg); |
| 1023 | } else { |
| 1024 | // The initial register stored in `index_` has already been |
| 1025 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 1026 | // (as it is not a callee-save register), so we can freely |
| 1027 | // use it. |
| 1028 | } |
| 1029 | // Shifting the index value contained in `index_reg` by the scale |
| 1030 | // factor (2) cannot overflow in practice, as the runtime is |
| 1031 | // unable to allocate object arrays with a size larger than |
| 1032 | // 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 1033 | __ Lsl(index_reg, index_reg, TIMES_4); |
| 1034 | static_assert( |
| 1035 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 1036 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 1037 | __ Add(index_reg, index_reg, offset_); |
| 1038 | } else { |
| 1039 | // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile |
| 1040 | // intrinsics, `index_` is not shifted by a scale factor of 2 |
| 1041 | // (as in the case of ArrayGet), as it is actually an offset |
| 1042 | // to an object field within an object. |
| 1043 | DCHECK(instruction_->IsInvoke()) << instruction_->DebugName(); |
| 1044 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 1045 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 1046 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 1047 | << instruction_->AsInvoke()->GetIntrinsic(); |
| 1048 | DCHECK_EQ(offset_, 0U); |
| 1049 | DCHECK(index_.IsRegisterPair()); |
| 1050 | // UnsafeGet's offset location is a register pair, the low |
| 1051 | // part contains the correct offset. |
| 1052 | index = index_.ToLow(); |
| 1053 | } |
| 1054 | } |
| 1055 | |
| 1056 | // We're moving two or three locations to locations that could |
| 1057 | // overlap, so we need a parallel move resolver. |
| 1058 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 1059 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 1060 | parallel_move.AddMove(ref_, |
| 1061 | LocationFrom(calling_convention.GetRegisterAt(0)), |
| 1062 | Primitive::kPrimNot, |
| 1063 | nullptr); |
| 1064 | parallel_move.AddMove(obj_, |
| 1065 | LocationFrom(calling_convention.GetRegisterAt(1)), |
| 1066 | Primitive::kPrimNot, |
| 1067 | nullptr); |
| 1068 | if (index.IsValid()) { |
| 1069 | parallel_move.AddMove(index, |
| 1070 | LocationFrom(calling_convention.GetRegisterAt(2)), |
| 1071 | Primitive::kPrimInt, |
| 1072 | nullptr); |
| 1073 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 1074 | } else { |
| 1075 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 1076 | __ Mov(calling_convention.GetRegisterAt(2), offset_); |
| 1077 | } |
| 1078 | arm_codegen->InvokeRuntime(kQuickReadBarrierSlow, instruction_, instruction_->GetDexPc(), this); |
| 1079 | CheckEntrypointTypes< |
| 1080 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 1081 | arm_codegen->Move32(out_, LocationFrom(r0)); |
| 1082 | |
| 1083 | RestoreLiveRegisters(codegen, locations); |
| 1084 | __ B(GetExitLabel()); |
| 1085 | } |
| 1086 | |
| 1087 | const char* GetDescription() const OVERRIDE { |
| 1088 | return "ReadBarrierForHeapReferenceSlowPathARMVIXL"; |
| 1089 | } |
| 1090 | |
| 1091 | private: |
| 1092 | vixl32::Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
| 1093 | uint32_t ref = RegisterFrom(ref_).GetCode(); |
| 1094 | uint32_t obj = RegisterFrom(obj_).GetCode(); |
| 1095 | for (uint32_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 1096 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 1097 | return vixl32::Register(i); |
| 1098 | } |
| 1099 | } |
| 1100 | // We shall never fail to find a free caller-save register, as |
| 1101 | // there are more than two core caller-save registers on ARM |
| 1102 | // (meaning it is possible to find one which is different from |
| 1103 | // `ref` and `obj`). |
| 1104 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 1105 | LOG(FATAL) << "Could not find a free caller-save register"; |
| 1106 | UNREACHABLE(); |
| 1107 | } |
| 1108 | |
| 1109 | const Location out_; |
| 1110 | const Location ref_; |
| 1111 | const Location obj_; |
| 1112 | const uint32_t offset_; |
| 1113 | // An additional location containing an index to an array. |
| 1114 | // Only used for HArrayGet and the UnsafeGetObject & |
| 1115 | // UnsafeGetObjectVolatile intrinsics. |
| 1116 | const Location index_; |
| 1117 | |
| 1118 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathARMVIXL); |
| 1119 | }; |
| 1120 | |
| 1121 | // Slow path generating a read barrier for a GC root. |
| 1122 | class ReadBarrierForRootSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 1123 | public: |
| 1124 | ReadBarrierForRootSlowPathARMVIXL(HInstruction* instruction, Location out, Location root) |
| 1125 | : SlowPathCodeARMVIXL(instruction), out_(out), root_(root) { |
| 1126 | DCHECK(kEmitCompilerReadBarrier); |
| 1127 | } |
| 1128 | |
| 1129 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 1130 | LocationSummary* locations = instruction_->GetLocations(); |
| 1131 | vixl32::Register reg_out = RegisterFrom(out_); |
| 1132 | DCHECK(locations->CanCall()); |
| 1133 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out.GetCode())); |
| 1134 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 1135 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 1136 | << instruction_->DebugName(); |
| 1137 | |
| 1138 | __ Bind(GetEntryLabel()); |
| 1139 | SaveLiveRegisters(codegen, locations); |
| 1140 | |
| 1141 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 1142 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 1143 | arm_codegen->Move32(LocationFrom(calling_convention.GetRegisterAt(0)), root_); |
| 1144 | arm_codegen->InvokeRuntime(kQuickReadBarrierForRootSlow, |
| 1145 | instruction_, |
| 1146 | instruction_->GetDexPc(), |
| 1147 | this); |
| 1148 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 1149 | arm_codegen->Move32(out_, LocationFrom(r0)); |
| 1150 | |
| 1151 | RestoreLiveRegisters(codegen, locations); |
| 1152 | __ B(GetExitLabel()); |
| 1153 | } |
| 1154 | |
| 1155 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathARMVIXL"; } |
| 1156 | |
| 1157 | private: |
| 1158 | const Location out_; |
| 1159 | const Location root_; |
| 1160 | |
| 1161 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathARMVIXL); |
| 1162 | }; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 1163 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1164 | inline vixl32::Condition ARMCondition(IfCondition cond) { |
| 1165 | switch (cond) { |
| 1166 | case kCondEQ: return eq; |
| 1167 | case kCondNE: return ne; |
| 1168 | case kCondLT: return lt; |
| 1169 | case kCondLE: return le; |
| 1170 | case kCondGT: return gt; |
| 1171 | case kCondGE: return ge; |
| 1172 | case kCondB: return lo; |
| 1173 | case kCondBE: return ls; |
| 1174 | case kCondA: return hi; |
| 1175 | case kCondAE: return hs; |
| 1176 | } |
| 1177 | LOG(FATAL) << "Unreachable"; |
| 1178 | UNREACHABLE(); |
| 1179 | } |
| 1180 | |
| 1181 | // Maps signed condition to unsigned condition. |
| 1182 | inline vixl32::Condition ARMUnsignedCondition(IfCondition cond) { |
| 1183 | switch (cond) { |
| 1184 | case kCondEQ: return eq; |
| 1185 | case kCondNE: return ne; |
| 1186 | // Signed to unsigned. |
| 1187 | case kCondLT: return lo; |
| 1188 | case kCondLE: return ls; |
| 1189 | case kCondGT: return hi; |
| 1190 | case kCondGE: return hs; |
| 1191 | // Unsigned remain unchanged. |
| 1192 | case kCondB: return lo; |
| 1193 | case kCondBE: return ls; |
| 1194 | case kCondA: return hi; |
| 1195 | case kCondAE: return hs; |
| 1196 | } |
| 1197 | LOG(FATAL) << "Unreachable"; |
| 1198 | UNREACHABLE(); |
| 1199 | } |
| 1200 | |
| 1201 | inline vixl32::Condition ARMFPCondition(IfCondition cond, bool gt_bias) { |
| 1202 | // The ARM condition codes can express all the necessary branches, see the |
| 1203 | // "Meaning (floating-point)" column in the table A8-1 of the ARMv7 reference manual. |
| 1204 | // There is no dex instruction or HIR that would need the missing conditions |
| 1205 | // "equal or unordered" or "not equal". |
| 1206 | switch (cond) { |
| 1207 | case kCondEQ: return eq; |
| 1208 | case kCondNE: return ne /* unordered */; |
| 1209 | case kCondLT: return gt_bias ? cc : lt /* unordered */; |
| 1210 | case kCondLE: return gt_bias ? ls : le /* unordered */; |
| 1211 | case kCondGT: return gt_bias ? hi /* unordered */ : gt; |
| 1212 | case kCondGE: return gt_bias ? cs /* unordered */ : ge; |
| 1213 | default: |
| 1214 | LOG(FATAL) << "UNREACHABLE"; |
| 1215 | UNREACHABLE(); |
| 1216 | } |
| 1217 | } |
| 1218 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 1219 | inline ShiftType ShiftFromOpKind(HDataProcWithShifterOp::OpKind op_kind) { |
| 1220 | switch (op_kind) { |
| 1221 | case HDataProcWithShifterOp::kASR: return ShiftType::ASR; |
| 1222 | case HDataProcWithShifterOp::kLSL: return ShiftType::LSL; |
| 1223 | case HDataProcWithShifterOp::kLSR: return ShiftType::LSR; |
| 1224 | default: |
| 1225 | LOG(FATAL) << "Unexpected op kind " << op_kind; |
| 1226 | UNREACHABLE(); |
| 1227 | } |
| 1228 | } |
| 1229 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1230 | void CodeGeneratorARMVIXL::DumpCoreRegister(std::ostream& stream, int reg) const { |
| 1231 | stream << vixl32::Register(reg); |
| 1232 | } |
| 1233 | |
| 1234 | void CodeGeneratorARMVIXL::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
| 1235 | stream << vixl32::SRegister(reg); |
| 1236 | } |
| 1237 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 1238 | static uint32_t ComputeSRegisterListMask(const SRegisterList& regs) { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1239 | uint32_t mask = 0; |
| 1240 | for (uint32_t i = regs.GetFirstSRegister().GetCode(); |
| 1241 | i <= regs.GetLastSRegister().GetCode(); |
| 1242 | ++i) { |
| 1243 | mask |= (1 << i); |
| 1244 | } |
| 1245 | return mask; |
| 1246 | } |
| 1247 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 1248 | // Saves the register in the stack. Returns the size taken on stack. |
| 1249 | size_t CodeGeneratorARMVIXL::SaveCoreRegister(size_t stack_index ATTRIBUTE_UNUSED, |
| 1250 | uint32_t reg_id ATTRIBUTE_UNUSED) { |
| 1251 | TODO_VIXL32(FATAL); |
| 1252 | return 0; |
| 1253 | } |
| 1254 | |
| 1255 | // Restores the register from the stack. Returns the size taken on stack. |
| 1256 | size_t CodeGeneratorARMVIXL::RestoreCoreRegister(size_t stack_index ATTRIBUTE_UNUSED, |
| 1257 | uint32_t reg_id ATTRIBUTE_UNUSED) { |
| 1258 | TODO_VIXL32(FATAL); |
| 1259 | return 0; |
| 1260 | } |
| 1261 | |
| 1262 | size_t CodeGeneratorARMVIXL::SaveFloatingPointRegister(size_t stack_index ATTRIBUTE_UNUSED, |
| 1263 | uint32_t reg_id ATTRIBUTE_UNUSED) { |
| 1264 | TODO_VIXL32(FATAL); |
| 1265 | return 0; |
| 1266 | } |
| 1267 | |
| 1268 | size_t CodeGeneratorARMVIXL::RestoreFloatingPointRegister(size_t stack_index ATTRIBUTE_UNUSED, |
| 1269 | uint32_t reg_id ATTRIBUTE_UNUSED) { |
| 1270 | TODO_VIXL32(FATAL); |
| 1271 | return 0; |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 1272 | } |
| 1273 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 1274 | static void GenerateDataProcInstruction(HInstruction::InstructionKind kind, |
| 1275 | vixl32::Register out, |
| 1276 | vixl32::Register first, |
| 1277 | const Operand& second, |
| 1278 | CodeGeneratorARMVIXL* codegen) { |
| 1279 | if (second.IsImmediate() && second.GetImmediate() == 0) { |
| 1280 | const Operand in = kind == HInstruction::kAnd |
| 1281 | ? Operand(0) |
| 1282 | : Operand(first); |
| 1283 | |
| 1284 | __ Mov(out, in); |
| 1285 | } else { |
| 1286 | switch (kind) { |
| 1287 | case HInstruction::kAdd: |
| 1288 | __ Add(out, first, second); |
| 1289 | break; |
| 1290 | case HInstruction::kAnd: |
| 1291 | __ And(out, first, second); |
| 1292 | break; |
| 1293 | case HInstruction::kOr: |
| 1294 | __ Orr(out, first, second); |
| 1295 | break; |
| 1296 | case HInstruction::kSub: |
| 1297 | __ Sub(out, first, second); |
| 1298 | break; |
| 1299 | case HInstruction::kXor: |
| 1300 | __ Eor(out, first, second); |
| 1301 | break; |
| 1302 | default: |
| 1303 | LOG(FATAL) << "Unexpected instruction kind: " << kind; |
| 1304 | UNREACHABLE(); |
| 1305 | } |
| 1306 | } |
| 1307 | } |
| 1308 | |
| 1309 | static void GenerateDataProc(HInstruction::InstructionKind kind, |
| 1310 | const Location& out, |
| 1311 | const Location& first, |
| 1312 | const Operand& second_lo, |
| 1313 | const Operand& second_hi, |
| 1314 | CodeGeneratorARMVIXL* codegen) { |
| 1315 | const vixl32::Register first_hi = HighRegisterFrom(first); |
| 1316 | const vixl32::Register first_lo = LowRegisterFrom(first); |
| 1317 | const vixl32::Register out_hi = HighRegisterFrom(out); |
| 1318 | const vixl32::Register out_lo = LowRegisterFrom(out); |
| 1319 | |
| 1320 | if (kind == HInstruction::kAdd) { |
| 1321 | __ Adds(out_lo, first_lo, second_lo); |
| 1322 | __ Adc(out_hi, first_hi, second_hi); |
| 1323 | } else if (kind == HInstruction::kSub) { |
| 1324 | __ Subs(out_lo, first_lo, second_lo); |
| 1325 | __ Sbc(out_hi, first_hi, second_hi); |
| 1326 | } else { |
| 1327 | GenerateDataProcInstruction(kind, out_lo, first_lo, second_lo, codegen); |
| 1328 | GenerateDataProcInstruction(kind, out_hi, first_hi, second_hi, codegen); |
| 1329 | } |
| 1330 | } |
| 1331 | |
| 1332 | static Operand GetShifterOperand(vixl32::Register rm, ShiftType shift, uint32_t shift_imm) { |
| 1333 | return shift_imm == 0 ? Operand(rm) : Operand(rm, shift, shift_imm); |
| 1334 | } |
| 1335 | |
| 1336 | static void GenerateLongDataProc(HDataProcWithShifterOp* instruction, |
| 1337 | CodeGeneratorARMVIXL* codegen) { |
| 1338 | DCHECK_EQ(instruction->GetType(), Primitive::kPrimLong); |
| 1339 | DCHECK(HDataProcWithShifterOp::IsShiftOp(instruction->GetOpKind())); |
| 1340 | |
| 1341 | const LocationSummary* const locations = instruction->GetLocations(); |
| 1342 | const uint32_t shift_value = instruction->GetShiftAmount(); |
| 1343 | const HInstruction::InstructionKind kind = instruction->GetInstrKind(); |
| 1344 | const Location first = locations->InAt(0); |
| 1345 | const Location second = locations->InAt(1); |
| 1346 | const Location out = locations->Out(); |
| 1347 | const vixl32::Register first_hi = HighRegisterFrom(first); |
| 1348 | const vixl32::Register first_lo = LowRegisterFrom(first); |
| 1349 | const vixl32::Register out_hi = HighRegisterFrom(out); |
| 1350 | const vixl32::Register out_lo = LowRegisterFrom(out); |
| 1351 | const vixl32::Register second_hi = HighRegisterFrom(second); |
| 1352 | const vixl32::Register second_lo = LowRegisterFrom(second); |
| 1353 | const ShiftType shift = ShiftFromOpKind(instruction->GetOpKind()); |
| 1354 | |
| 1355 | if (shift_value >= 32) { |
| 1356 | if (shift == ShiftType::LSL) { |
| 1357 | GenerateDataProcInstruction(kind, |
| 1358 | out_hi, |
| 1359 | first_hi, |
| 1360 | Operand(second_lo, ShiftType::LSL, shift_value - 32), |
| 1361 | codegen); |
| 1362 | GenerateDataProcInstruction(kind, out_lo, first_lo, 0, codegen); |
| 1363 | } else if (shift == ShiftType::ASR) { |
| 1364 | GenerateDataProc(kind, |
| 1365 | out, |
| 1366 | first, |
| 1367 | GetShifterOperand(second_hi, ShiftType::ASR, shift_value - 32), |
| 1368 | Operand(second_hi, ShiftType::ASR, 31), |
| 1369 | codegen); |
| 1370 | } else { |
| 1371 | DCHECK_EQ(shift, ShiftType::LSR); |
| 1372 | GenerateDataProc(kind, |
| 1373 | out, |
| 1374 | first, |
| 1375 | GetShifterOperand(second_hi, ShiftType::LSR, shift_value - 32), |
| 1376 | 0, |
| 1377 | codegen); |
| 1378 | } |
| 1379 | } else { |
| 1380 | DCHECK_GT(shift_value, 1U); |
| 1381 | DCHECK_LT(shift_value, 32U); |
| 1382 | |
| 1383 | UseScratchRegisterScope temps(codegen->GetVIXLAssembler()); |
| 1384 | |
| 1385 | if (shift == ShiftType::LSL) { |
| 1386 | // We are not doing this for HInstruction::kAdd because the output will require |
| 1387 | // Location::kOutputOverlap; not applicable to other cases. |
| 1388 | if (kind == HInstruction::kOr || kind == HInstruction::kXor) { |
| 1389 | GenerateDataProcInstruction(kind, |
| 1390 | out_hi, |
| 1391 | first_hi, |
| 1392 | Operand(second_hi, ShiftType::LSL, shift_value), |
| 1393 | codegen); |
| 1394 | GenerateDataProcInstruction(kind, |
| 1395 | out_hi, |
| 1396 | out_hi, |
| 1397 | Operand(second_lo, ShiftType::LSR, 32 - shift_value), |
| 1398 | codegen); |
| 1399 | GenerateDataProcInstruction(kind, |
| 1400 | out_lo, |
| 1401 | first_lo, |
| 1402 | Operand(second_lo, ShiftType::LSL, shift_value), |
| 1403 | codegen); |
| 1404 | } else { |
| 1405 | const vixl32::Register temp = temps.Acquire(); |
| 1406 | |
| 1407 | __ Lsl(temp, second_hi, shift_value); |
| 1408 | __ Orr(temp, temp, Operand(second_lo, ShiftType::LSR, 32 - shift_value)); |
| 1409 | GenerateDataProc(kind, |
| 1410 | out, |
| 1411 | first, |
| 1412 | Operand(second_lo, ShiftType::LSL, shift_value), |
| 1413 | temp, |
| 1414 | codegen); |
| 1415 | } |
| 1416 | } else { |
| 1417 | DCHECK(shift == ShiftType::ASR || shift == ShiftType::LSR); |
| 1418 | |
| 1419 | // We are not doing this for HInstruction::kAdd because the output will require |
| 1420 | // Location::kOutputOverlap; not applicable to other cases. |
| 1421 | if (kind == HInstruction::kOr || kind == HInstruction::kXor) { |
| 1422 | GenerateDataProcInstruction(kind, |
| 1423 | out_lo, |
| 1424 | first_lo, |
| 1425 | Operand(second_lo, ShiftType::LSR, shift_value), |
| 1426 | codegen); |
| 1427 | GenerateDataProcInstruction(kind, |
| 1428 | out_lo, |
| 1429 | out_lo, |
| 1430 | Operand(second_hi, ShiftType::LSL, 32 - shift_value), |
| 1431 | codegen); |
| 1432 | GenerateDataProcInstruction(kind, |
| 1433 | out_hi, |
| 1434 | first_hi, |
| 1435 | Operand(second_hi, shift, shift_value), |
| 1436 | codegen); |
| 1437 | } else { |
| 1438 | const vixl32::Register temp = temps.Acquire(); |
| 1439 | |
| 1440 | __ Lsr(temp, second_lo, shift_value); |
| 1441 | __ Orr(temp, temp, Operand(second_hi, ShiftType::LSL, 32 - shift_value)); |
| 1442 | GenerateDataProc(kind, |
| 1443 | out, |
| 1444 | first, |
| 1445 | temp, |
| 1446 | Operand(second_hi, shift, shift_value), |
| 1447 | codegen); |
| 1448 | } |
| 1449 | } |
| 1450 | } |
| 1451 | } |
| 1452 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1453 | #undef __ |
| 1454 | |
| 1455 | CodeGeneratorARMVIXL::CodeGeneratorARMVIXL(HGraph* graph, |
| 1456 | const ArmInstructionSetFeatures& isa_features, |
| 1457 | const CompilerOptions& compiler_options, |
| 1458 | OptimizingCompilerStats* stats) |
| 1459 | : CodeGenerator(graph, |
| 1460 | kNumberOfCoreRegisters, |
| 1461 | kNumberOfSRegisters, |
| 1462 | kNumberOfRegisterPairs, |
| 1463 | kCoreCalleeSaves.GetList(), |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 1464 | ComputeSRegisterListMask(kFpuCalleeSaves), |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1465 | compiler_options, |
| 1466 | stats), |
| 1467 | block_labels_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 1468 | jump_tables_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1469 | location_builder_(graph, this), |
| 1470 | instruction_visitor_(graph, this), |
| 1471 | move_resolver_(graph->GetArena(), this), |
| 1472 | assembler_(graph->GetArena()), |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 1473 | isa_features_(isa_features), |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 1474 | uint32_literals_(std::less<uint32_t>(), |
| 1475 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 1476 | pc_relative_dex_cache_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 1477 | boot_image_string_patches_(StringReferenceValueComparator(), |
| 1478 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 1479 | pc_relative_string_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 1480 | boot_image_type_patches_(TypeReferenceValueComparator(), |
| 1481 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1482 | pc_relative_type_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1483 | type_bss_entry_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 1484 | jit_string_patches_(StringReferenceValueComparator(), |
| 1485 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1486 | jit_class_patches_(TypeReferenceValueComparator(), |
| 1487 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)) { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1488 | // Always save the LR register to mimic Quick. |
| 1489 | AddAllocatedRegister(Location::RegisterLocation(LR)); |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 1490 | // Give d14 and d15 as scratch registers to VIXL. |
| 1491 | // They are removed from the register allocator in `SetupBlockedRegisters()`. |
| 1492 | // TODO(VIXL): We need two scratch D registers for `EmitSwap` when swapping two double stack |
| 1493 | // slots. If that is sufficiently rare, and we have pressure on FP registers, we could instead |
| 1494 | // spill in `EmitSwap`. But if we actually are guaranteed to have 32 D registers, we could give |
| 1495 | // d30 and d31 to VIXL to avoid removing registers from the allocator. If that is the case, we may |
| 1496 | // also want to investigate giving those 14 other D registers to the allocator. |
| 1497 | GetVIXLAssembler()->GetScratchVRegisterList()->Combine(d14); |
| 1498 | GetVIXLAssembler()->GetScratchVRegisterList()->Combine(d15); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1499 | } |
| 1500 | |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 1501 | void JumpTableARMVIXL::EmitTable(CodeGeneratorARMVIXL* codegen) { |
| 1502 | uint32_t num_entries = switch_instr_->GetNumEntries(); |
| 1503 | DCHECK_GE(num_entries, kPackedSwitchCompareJumpThreshold); |
| 1504 | |
| 1505 | // 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] | 1506 | // underlying code buffer and we have generated a jump table of the right size, using |
| 1507 | // codegen->GetVIXLAssembler()->GetBuffer().Align(); |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 1508 | ExactAssemblyScope aas(codegen->GetVIXLAssembler(), |
| 1509 | num_entries * sizeof(int32_t), |
| 1510 | CodeBufferCheckScope::kMaximumSize); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 1511 | // TODO(VIXL): Check that using lower case bind is fine here. |
| 1512 | codegen->GetVIXLAssembler()->bind(&table_start_); |
Artem Serov | 09a940d | 2016-11-11 16:15:11 +0000 | [diff] [blame] | 1513 | for (uint32_t i = 0; i < num_entries; i++) { |
| 1514 | codegen->GetVIXLAssembler()->place(bb_addresses_[i].get()); |
| 1515 | } |
| 1516 | } |
| 1517 | |
| 1518 | void JumpTableARMVIXL::FixTable(CodeGeneratorARMVIXL* codegen) { |
| 1519 | uint32_t num_entries = switch_instr_->GetNumEntries(); |
| 1520 | DCHECK_GE(num_entries, kPackedSwitchCompareJumpThreshold); |
| 1521 | |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 1522 | const ArenaVector<HBasicBlock*>& successors = switch_instr_->GetBlock()->GetSuccessors(); |
| 1523 | for (uint32_t i = 0; i < num_entries; i++) { |
| 1524 | vixl32::Label* target_label = codegen->GetLabelOf(successors[i]); |
| 1525 | DCHECK(target_label->IsBound()); |
| 1526 | int32_t jump_offset = target_label->GetLocation() - table_start_.GetLocation(); |
| 1527 | // When doing BX to address we need to have lower bit set to 1 in T32. |
| 1528 | if (codegen->GetVIXLAssembler()->IsUsingT32()) { |
| 1529 | jump_offset++; |
| 1530 | } |
| 1531 | DCHECK_GT(jump_offset, std::numeric_limits<int32_t>::min()); |
| 1532 | DCHECK_LE(jump_offset, std::numeric_limits<int32_t>::max()); |
Artem Serov | 09a940d | 2016-11-11 16:15:11 +0000 | [diff] [blame] | 1533 | |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 1534 | bb_addresses_[i].get()->UpdateValue(jump_offset, codegen->GetVIXLAssembler()->GetBuffer()); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 1535 | } |
| 1536 | } |
| 1537 | |
Artem Serov | 09a940d | 2016-11-11 16:15:11 +0000 | [diff] [blame] | 1538 | void CodeGeneratorARMVIXL::FixJumpTables() { |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 1539 | for (auto&& jump_table : jump_tables_) { |
Artem Serov | 09a940d | 2016-11-11 16:15:11 +0000 | [diff] [blame] | 1540 | jump_table->FixTable(this); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 1541 | } |
| 1542 | } |
| 1543 | |
Andreas Gampe | ca620d7 | 2016-11-08 08:09:33 -0800 | [diff] [blame] | 1544 | #define __ reinterpret_cast<ArmVIXLAssembler*>(GetAssembler())->GetVIXLAssembler()-> // NOLINT |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1545 | |
| 1546 | void CodeGeneratorARMVIXL::Finalize(CodeAllocator* allocator) { |
Artem Serov | 09a940d | 2016-11-11 16:15:11 +0000 | [diff] [blame] | 1547 | FixJumpTables(); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1548 | GetAssembler()->FinalizeCode(); |
| 1549 | CodeGenerator::Finalize(allocator); |
| 1550 | } |
| 1551 | |
| 1552 | void CodeGeneratorARMVIXL::SetupBlockedRegisters() const { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1553 | // Stack register, LR and PC are always reserved. |
| 1554 | blocked_core_registers_[SP] = true; |
| 1555 | blocked_core_registers_[LR] = true; |
| 1556 | blocked_core_registers_[PC] = true; |
| 1557 | |
| 1558 | // Reserve thread register. |
| 1559 | blocked_core_registers_[TR] = true; |
| 1560 | |
| 1561 | // Reserve temp register. |
| 1562 | blocked_core_registers_[IP] = true; |
| 1563 | |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 1564 | // Registers s28-s31 (d14-d15) are left to VIXL for scratch registers. |
| 1565 | // (They are given to the `MacroAssembler` in `CodeGeneratorARMVIXL::CodeGeneratorARMVIXL`.) |
| 1566 | blocked_fpu_registers_[28] = true; |
| 1567 | blocked_fpu_registers_[29] = true; |
| 1568 | blocked_fpu_registers_[30] = true; |
| 1569 | blocked_fpu_registers_[31] = true; |
| 1570 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1571 | if (GetGraph()->IsDebuggable()) { |
| 1572 | // Stubs do not save callee-save floating point registers. If the graph |
| 1573 | // is debuggable, we need to deal with these registers differently. For |
| 1574 | // now, just block them. |
| 1575 | for (uint32_t i = kFpuCalleeSaves.GetFirstSRegister().GetCode(); |
| 1576 | i <= kFpuCalleeSaves.GetLastSRegister().GetCode(); |
| 1577 | ++i) { |
| 1578 | blocked_fpu_registers_[i] = true; |
| 1579 | } |
| 1580 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1581 | } |
| 1582 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1583 | InstructionCodeGeneratorARMVIXL::InstructionCodeGeneratorARMVIXL(HGraph* graph, |
| 1584 | CodeGeneratorARMVIXL* codegen) |
| 1585 | : InstructionCodeGenerator(graph, codegen), |
| 1586 | assembler_(codegen->GetAssembler()), |
| 1587 | codegen_(codegen) {} |
| 1588 | |
| 1589 | void CodeGeneratorARMVIXL::ComputeSpillMask() { |
| 1590 | core_spill_mask_ = allocated_registers_.GetCoreRegisters() & core_callee_save_mask_; |
| 1591 | DCHECK_NE(core_spill_mask_, 0u) << "At least the return address register must be saved"; |
| 1592 | // There is no easy instruction to restore just the PC on thumb2. We spill and |
| 1593 | // restore another arbitrary register. |
| 1594 | core_spill_mask_ |= (1 << kCoreAlwaysSpillRegister.GetCode()); |
| 1595 | fpu_spill_mask_ = allocated_registers_.GetFloatingPointRegisters() & fpu_callee_save_mask_; |
| 1596 | // We use vpush and vpop for saving and restoring floating point registers, which take |
| 1597 | // a SRegister and the number of registers to save/restore after that SRegister. We |
| 1598 | // therefore update the `fpu_spill_mask_` to also contain those registers not allocated, |
| 1599 | // but in the range. |
| 1600 | if (fpu_spill_mask_ != 0) { |
| 1601 | uint32_t least_significant_bit = LeastSignificantBit(fpu_spill_mask_); |
| 1602 | uint32_t most_significant_bit = MostSignificantBit(fpu_spill_mask_); |
| 1603 | for (uint32_t i = least_significant_bit + 1 ; i < most_significant_bit; ++i) { |
| 1604 | fpu_spill_mask_ |= (1 << i); |
| 1605 | } |
| 1606 | } |
| 1607 | } |
| 1608 | |
| 1609 | void CodeGeneratorARMVIXL::GenerateFrameEntry() { |
| 1610 | bool skip_overflow_check = |
| 1611 | IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kArm); |
| 1612 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
| 1613 | __ Bind(&frame_entry_label_); |
| 1614 | |
| 1615 | if (HasEmptyFrame()) { |
| 1616 | return; |
| 1617 | } |
| 1618 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1619 | if (!skip_overflow_check) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 1620 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 1621 | vixl32::Register temp = temps.Acquire(); |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 1622 | __ Sub(temp, sp, Operand::From(GetStackOverflowReservedBytes(kArm))); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1623 | // The load must immediately precede RecordPcInfo. |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 1624 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 1625 | vixl32::kMaxInstructionSizeInBytes, |
| 1626 | CodeBufferCheckScope::kMaximumSize); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 1627 | __ ldr(temp, MemOperand(temp)); |
| 1628 | RecordPcInfo(nullptr, 0); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1629 | } |
| 1630 | |
| 1631 | __ Push(RegisterList(core_spill_mask_)); |
| 1632 | GetAssembler()->cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(core_spill_mask_)); |
| 1633 | GetAssembler()->cfi().RelOffsetForMany(DWARFReg(kMethodRegister), |
| 1634 | 0, |
| 1635 | core_spill_mask_, |
| 1636 | kArmWordSize); |
| 1637 | if (fpu_spill_mask_ != 0) { |
| 1638 | uint32_t first = LeastSignificantBit(fpu_spill_mask_); |
| 1639 | |
| 1640 | // Check that list is contiguous. |
| 1641 | DCHECK_EQ(fpu_spill_mask_ >> CTZ(fpu_spill_mask_), ~0u >> (32 - POPCOUNT(fpu_spill_mask_))); |
| 1642 | |
| 1643 | __ Vpush(SRegisterList(vixl32::SRegister(first), POPCOUNT(fpu_spill_mask_))); |
| 1644 | GetAssembler()->cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(fpu_spill_mask_)); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 1645 | GetAssembler()->cfi().RelOffsetForMany(DWARFReg(s0), 0, fpu_spill_mask_, kArmWordSize); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1646 | } |
Scott Wakeling | bffdc70 | 2016-12-07 17:46:03 +0000 | [diff] [blame] | 1647 | |
| 1648 | if (GetGraph()->HasShouldDeoptimizeFlag()) { |
| 1649 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 1650 | vixl32::Register temp = temps.Acquire(); |
| 1651 | // Initialize should_deoptimize flag to 0. |
| 1652 | __ Mov(temp, 0); |
| 1653 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, -kShouldDeoptimizeFlagSize); |
| 1654 | } |
| 1655 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1656 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 1657 | __ Sub(sp, sp, adjust); |
| 1658 | GetAssembler()->cfi().AdjustCFAOffset(adjust); |
Scott Wakeling | bffdc70 | 2016-12-07 17:46:03 +0000 | [diff] [blame] | 1659 | |
| 1660 | // Save the current method if we need it. Note that we do not |
| 1661 | // do this in HCurrentMethod, as the instruction might have been removed |
| 1662 | // in the SSA graph. |
| 1663 | if (RequiresCurrentMethod()) { |
| 1664 | GetAssembler()->StoreToOffset(kStoreWord, kMethodRegister, sp, 0); |
| 1665 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1666 | } |
| 1667 | |
| 1668 | void CodeGeneratorARMVIXL::GenerateFrameExit() { |
| 1669 | if (HasEmptyFrame()) { |
| 1670 | __ Bx(lr); |
| 1671 | return; |
| 1672 | } |
| 1673 | GetAssembler()->cfi().RememberState(); |
| 1674 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 1675 | __ Add(sp, sp, adjust); |
| 1676 | GetAssembler()->cfi().AdjustCFAOffset(-adjust); |
| 1677 | if (fpu_spill_mask_ != 0) { |
| 1678 | uint32_t first = LeastSignificantBit(fpu_spill_mask_); |
| 1679 | |
| 1680 | // Check that list is contiguous. |
| 1681 | DCHECK_EQ(fpu_spill_mask_ >> CTZ(fpu_spill_mask_), ~0u >> (32 - POPCOUNT(fpu_spill_mask_))); |
| 1682 | |
| 1683 | __ Vpop(SRegisterList(vixl32::SRegister(first), POPCOUNT(fpu_spill_mask_))); |
| 1684 | GetAssembler()->cfi().AdjustCFAOffset( |
| 1685 | -static_cast<int>(kArmWordSize) * POPCOUNT(fpu_spill_mask_)); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 1686 | GetAssembler()->cfi().RestoreMany(DWARFReg(vixl32::SRegister(0)), fpu_spill_mask_); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1687 | } |
| 1688 | // Pop LR into PC to return. |
| 1689 | DCHECK_NE(core_spill_mask_ & (1 << kLrCode), 0U); |
| 1690 | uint32_t pop_mask = (core_spill_mask_ & (~(1 << kLrCode))) | 1 << kPcCode; |
| 1691 | __ Pop(RegisterList(pop_mask)); |
| 1692 | GetAssembler()->cfi().RestoreState(); |
| 1693 | GetAssembler()->cfi().DefCFAOffset(GetFrameSize()); |
| 1694 | } |
| 1695 | |
| 1696 | void CodeGeneratorARMVIXL::Bind(HBasicBlock* block) { |
| 1697 | __ Bind(GetLabelOf(block)); |
| 1698 | } |
| 1699 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 1700 | Location InvokeDexCallingConventionVisitorARMVIXL::GetNextLocation(Primitive::Type type) { |
| 1701 | switch (type) { |
| 1702 | case Primitive::kPrimBoolean: |
| 1703 | case Primitive::kPrimByte: |
| 1704 | case Primitive::kPrimChar: |
| 1705 | case Primitive::kPrimShort: |
| 1706 | case Primitive::kPrimInt: |
| 1707 | case Primitive::kPrimNot: { |
| 1708 | uint32_t index = gp_index_++; |
| 1709 | uint32_t stack_index = stack_index_++; |
| 1710 | if (index < calling_convention.GetNumberOfRegisters()) { |
| 1711 | return LocationFrom(calling_convention.GetRegisterAt(index)); |
| 1712 | } else { |
| 1713 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
| 1714 | } |
| 1715 | } |
| 1716 | |
| 1717 | case Primitive::kPrimLong: { |
| 1718 | uint32_t index = gp_index_; |
| 1719 | uint32_t stack_index = stack_index_; |
| 1720 | gp_index_ += 2; |
| 1721 | stack_index_ += 2; |
| 1722 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
| 1723 | if (calling_convention.GetRegisterAt(index).Is(r1)) { |
| 1724 | // Skip R1, and use R2_R3 instead. |
| 1725 | gp_index_++; |
| 1726 | index++; |
| 1727 | } |
| 1728 | } |
| 1729 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
| 1730 | DCHECK_EQ(calling_convention.GetRegisterAt(index).GetCode() + 1, |
| 1731 | calling_convention.GetRegisterAt(index + 1).GetCode()); |
| 1732 | |
| 1733 | return LocationFrom(calling_convention.GetRegisterAt(index), |
| 1734 | calling_convention.GetRegisterAt(index + 1)); |
| 1735 | } else { |
| 1736 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
| 1737 | } |
| 1738 | } |
| 1739 | |
| 1740 | case Primitive::kPrimFloat: { |
| 1741 | uint32_t stack_index = stack_index_++; |
| 1742 | if (float_index_ % 2 == 0) { |
| 1743 | float_index_ = std::max(double_index_, float_index_); |
| 1744 | } |
| 1745 | if (float_index_ < calling_convention.GetNumberOfFpuRegisters()) { |
| 1746 | return LocationFrom(calling_convention.GetFpuRegisterAt(float_index_++)); |
| 1747 | } else { |
| 1748 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
| 1749 | } |
| 1750 | } |
| 1751 | |
| 1752 | case Primitive::kPrimDouble: { |
| 1753 | double_index_ = std::max(double_index_, RoundUp(float_index_, 2)); |
| 1754 | uint32_t stack_index = stack_index_; |
| 1755 | stack_index_ += 2; |
| 1756 | if (double_index_ + 1 < calling_convention.GetNumberOfFpuRegisters()) { |
| 1757 | uint32_t index = double_index_; |
| 1758 | double_index_ += 2; |
| 1759 | Location result = LocationFrom( |
| 1760 | calling_convention.GetFpuRegisterAt(index), |
| 1761 | calling_convention.GetFpuRegisterAt(index + 1)); |
| 1762 | DCHECK(ExpectedPairLayout(result)); |
| 1763 | return result; |
| 1764 | } else { |
| 1765 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
| 1766 | } |
| 1767 | } |
| 1768 | |
| 1769 | case Primitive::kPrimVoid: |
| 1770 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 1771 | break; |
| 1772 | } |
| 1773 | return Location::NoLocation(); |
| 1774 | } |
| 1775 | |
| 1776 | Location InvokeDexCallingConventionVisitorARMVIXL::GetReturnLocation(Primitive::Type type) const { |
| 1777 | switch (type) { |
| 1778 | case Primitive::kPrimBoolean: |
| 1779 | case Primitive::kPrimByte: |
| 1780 | case Primitive::kPrimChar: |
| 1781 | case Primitive::kPrimShort: |
| 1782 | case Primitive::kPrimInt: |
| 1783 | case Primitive::kPrimNot: { |
| 1784 | return LocationFrom(r0); |
| 1785 | } |
| 1786 | |
| 1787 | case Primitive::kPrimFloat: { |
| 1788 | return LocationFrom(s0); |
| 1789 | } |
| 1790 | |
| 1791 | case Primitive::kPrimLong: { |
| 1792 | return LocationFrom(r0, r1); |
| 1793 | } |
| 1794 | |
| 1795 | case Primitive::kPrimDouble: { |
| 1796 | return LocationFrom(s0, s1); |
| 1797 | } |
| 1798 | |
| 1799 | case Primitive::kPrimVoid: |
| 1800 | return Location::NoLocation(); |
| 1801 | } |
| 1802 | |
| 1803 | UNREACHABLE(); |
| 1804 | } |
| 1805 | |
| 1806 | Location InvokeDexCallingConventionVisitorARMVIXL::GetMethodLocation() const { |
| 1807 | return LocationFrom(kMethodRegister); |
| 1808 | } |
| 1809 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 1810 | void CodeGeneratorARMVIXL::Move32(Location destination, Location source) { |
| 1811 | if (source.Equals(destination)) { |
| 1812 | return; |
| 1813 | } |
| 1814 | if (destination.IsRegister()) { |
| 1815 | if (source.IsRegister()) { |
| 1816 | __ Mov(RegisterFrom(destination), RegisterFrom(source)); |
| 1817 | } else if (source.IsFpuRegister()) { |
| 1818 | __ Vmov(RegisterFrom(destination), SRegisterFrom(source)); |
| 1819 | } else { |
| 1820 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 1821 | RegisterFrom(destination), |
| 1822 | sp, |
| 1823 | source.GetStackIndex()); |
| 1824 | } |
| 1825 | } else if (destination.IsFpuRegister()) { |
| 1826 | if (source.IsRegister()) { |
| 1827 | __ Vmov(SRegisterFrom(destination), RegisterFrom(source)); |
| 1828 | } else if (source.IsFpuRegister()) { |
| 1829 | __ Vmov(SRegisterFrom(destination), SRegisterFrom(source)); |
| 1830 | } else { |
| 1831 | GetAssembler()->LoadSFromOffset(SRegisterFrom(destination), sp, source.GetStackIndex()); |
| 1832 | } |
| 1833 | } else { |
| 1834 | DCHECK(destination.IsStackSlot()) << destination; |
| 1835 | if (source.IsRegister()) { |
| 1836 | GetAssembler()->StoreToOffset(kStoreWord, |
| 1837 | RegisterFrom(source), |
| 1838 | sp, |
| 1839 | destination.GetStackIndex()); |
| 1840 | } else if (source.IsFpuRegister()) { |
| 1841 | GetAssembler()->StoreSToOffset(SRegisterFrom(source), sp, destination.GetStackIndex()); |
| 1842 | } else { |
| 1843 | DCHECK(source.IsStackSlot()) << source; |
| 1844 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 1845 | vixl32::Register temp = temps.Acquire(); |
| 1846 | GetAssembler()->LoadFromOffset(kLoadWord, temp, sp, source.GetStackIndex()); |
| 1847 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, destination.GetStackIndex()); |
| 1848 | } |
| 1849 | } |
| 1850 | } |
| 1851 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 1852 | void CodeGeneratorARMVIXL::MoveConstant(Location location, int32_t value) { |
| 1853 | DCHECK(location.IsRegister()); |
| 1854 | __ Mov(RegisterFrom(location), value); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1855 | } |
| 1856 | |
| 1857 | void CodeGeneratorARMVIXL::MoveLocation(Location dst, Location src, Primitive::Type dst_type) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 1858 | // TODO(VIXL): Maybe refactor to have the 'move' implementation here and use it in |
| 1859 | // `ParallelMoveResolverARMVIXL::EmitMove`, as is done in the `arm64` backend. |
| 1860 | HParallelMove move(GetGraph()->GetArena()); |
| 1861 | move.AddMove(src, dst, dst_type, nullptr); |
| 1862 | GetMoveResolver()->EmitNativeCode(&move); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1863 | } |
| 1864 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 1865 | void CodeGeneratorARMVIXL::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1866 | if (location.IsRegister()) { |
| 1867 | locations->AddTemp(location); |
| 1868 | } else if (location.IsRegisterPair()) { |
| 1869 | locations->AddTemp(LocationFrom(LowRegisterFrom(location))); |
| 1870 | locations->AddTemp(LocationFrom(HighRegisterFrom(location))); |
| 1871 | } else { |
| 1872 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1873 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1874 | } |
| 1875 | |
| 1876 | void CodeGeneratorARMVIXL::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 1877 | HInstruction* instruction, |
| 1878 | uint32_t dex_pc, |
| 1879 | SlowPathCode* slow_path) { |
| 1880 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 1881 | __ Ldr(lr, MemOperand(tr, GetThreadOffset<kArmPointerSize>(entrypoint).Int32Value())); |
| 1882 | // Ensure the pc position is recorded immediately after the `blx` instruction. |
| 1883 | // 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] | 1884 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 1885 | vixl32::k16BitT32InstructionSizeInBytes, |
| 1886 | CodeBufferCheckScope::kExactSize); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 1887 | __ blx(lr); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1888 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 1889 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 1890 | } |
| 1891 | } |
| 1892 | |
| 1893 | void CodeGeneratorARMVIXL::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 1894 | HInstruction* instruction, |
| 1895 | SlowPathCode* slow_path) { |
| 1896 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 1897 | __ Ldr(lr, MemOperand(tr, entry_point_offset)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1898 | __ Blx(lr); |
| 1899 | } |
| 1900 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1901 | void InstructionCodeGeneratorARMVIXL::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
| 1902 | DCHECK(!successor->IsExitBlock()); |
| 1903 | HBasicBlock* block = got->GetBlock(); |
| 1904 | HInstruction* previous = got->GetPrevious(); |
| 1905 | HLoopInformation* info = block->GetLoopInformation(); |
| 1906 | |
| 1907 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
| 1908 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck()); |
| 1909 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 1910 | return; |
| 1911 | } |
| 1912 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 1913 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 1914 | } |
| 1915 | if (!codegen_->GoesToNextBlock(block, successor)) { |
| 1916 | __ B(codegen_->GetLabelOf(successor)); |
| 1917 | } |
| 1918 | } |
| 1919 | |
| 1920 | void LocationsBuilderARMVIXL::VisitGoto(HGoto* got) { |
| 1921 | got->SetLocations(nullptr); |
| 1922 | } |
| 1923 | |
| 1924 | void InstructionCodeGeneratorARMVIXL::VisitGoto(HGoto* got) { |
| 1925 | HandleGoto(got, got->GetSuccessor()); |
| 1926 | } |
| 1927 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 1928 | void LocationsBuilderARMVIXL::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1929 | try_boundary->SetLocations(nullptr); |
| 1930 | } |
| 1931 | |
| 1932 | void InstructionCodeGeneratorARMVIXL::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1933 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 1934 | if (!successor->IsExitBlock()) { |
| 1935 | HandleGoto(try_boundary, successor); |
| 1936 | } |
| 1937 | } |
| 1938 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1939 | void LocationsBuilderARMVIXL::VisitExit(HExit* exit) { |
| 1940 | exit->SetLocations(nullptr); |
| 1941 | } |
| 1942 | |
| 1943 | void InstructionCodeGeneratorARMVIXL::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
| 1944 | } |
| 1945 | |
| 1946 | void InstructionCodeGeneratorARMVIXL::GenerateVcmp(HInstruction* instruction) { |
| 1947 | Primitive::Type type = instruction->InputAt(0)->GetType(); |
| 1948 | Location lhs_loc = instruction->GetLocations()->InAt(0); |
| 1949 | Location rhs_loc = instruction->GetLocations()->InAt(1); |
| 1950 | if (rhs_loc.IsConstant()) { |
| 1951 | // 0.0 is the only immediate that can be encoded directly in |
| 1952 | // a VCMP instruction. |
| 1953 | // |
| 1954 | // Both the JLS (section 15.20.1) and the JVMS (section 6.5) |
| 1955 | // specify that in a floating-point comparison, positive zero |
| 1956 | // and negative zero are considered equal, so we can use the |
| 1957 | // literal 0.0 for both cases here. |
| 1958 | // |
| 1959 | // Note however that some methods (Float.equal, Float.compare, |
| 1960 | // Float.compareTo, Double.equal, Double.compare, |
| 1961 | // Double.compareTo, Math.max, Math.min, StrictMath.max, |
| 1962 | // StrictMath.min) consider 0.0 to be (strictly) greater than |
| 1963 | // -0.0. So if we ever translate calls to these methods into a |
| 1964 | // HCompare instruction, we must handle the -0.0 case with |
| 1965 | // care here. |
| 1966 | DCHECK(rhs_loc.GetConstant()->IsArithmeticZero()); |
| 1967 | if (type == Primitive::kPrimFloat) { |
| 1968 | __ Vcmp(F32, InputSRegisterAt(instruction, 0), 0.0); |
| 1969 | } else { |
| 1970 | DCHECK_EQ(type, Primitive::kPrimDouble); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 1971 | __ Vcmp(F64, DRegisterFrom(lhs_loc), 0.0); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1972 | } |
| 1973 | } else { |
| 1974 | if (type == Primitive::kPrimFloat) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 1975 | __ Vcmp(InputSRegisterAt(instruction, 0), InputSRegisterAt(instruction, 1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1976 | } else { |
| 1977 | DCHECK_EQ(type, Primitive::kPrimDouble); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 1978 | __ Vcmp(DRegisterFrom(lhs_loc), DRegisterFrom(rhs_loc)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1979 | } |
| 1980 | } |
| 1981 | } |
| 1982 | |
| 1983 | void InstructionCodeGeneratorARMVIXL::GenerateFPJumps(HCondition* cond, |
| 1984 | vixl32::Label* true_label, |
| 1985 | vixl32::Label* false_label ATTRIBUTE_UNUSED) { |
| 1986 | // To branch on the result of the FP compare we transfer FPSCR to APSR (encoded as PC in VMRS). |
| 1987 | __ Vmrs(RegisterOrAPSR_nzcv(kPcCode), FPSCR); |
| 1988 | __ B(ARMFPCondition(cond->GetCondition(), cond->IsGtBias()), true_label); |
| 1989 | } |
| 1990 | |
| 1991 | void InstructionCodeGeneratorARMVIXL::GenerateLongComparesAndJumps(HCondition* cond, |
| 1992 | vixl32::Label* true_label, |
| 1993 | vixl32::Label* false_label) { |
| 1994 | LocationSummary* locations = cond->GetLocations(); |
| 1995 | Location left = locations->InAt(0); |
| 1996 | Location right = locations->InAt(1); |
| 1997 | IfCondition if_cond = cond->GetCondition(); |
| 1998 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 1999 | vixl32::Register left_high = HighRegisterFrom(left); |
| 2000 | vixl32::Register left_low = LowRegisterFrom(left); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2001 | IfCondition true_high_cond = if_cond; |
| 2002 | IfCondition false_high_cond = cond->GetOppositeCondition(); |
| 2003 | vixl32::Condition final_condition = ARMUnsignedCondition(if_cond); // unsigned on lower part |
| 2004 | |
| 2005 | // Set the conditions for the test, remembering that == needs to be |
| 2006 | // decided using the low words. |
| 2007 | // TODO: consider avoiding jumps with temporary and CMP low+SBC high |
| 2008 | switch (if_cond) { |
| 2009 | case kCondEQ: |
| 2010 | case kCondNE: |
| 2011 | // Nothing to do. |
| 2012 | break; |
| 2013 | case kCondLT: |
| 2014 | false_high_cond = kCondGT; |
| 2015 | break; |
| 2016 | case kCondLE: |
| 2017 | true_high_cond = kCondLT; |
| 2018 | break; |
| 2019 | case kCondGT: |
| 2020 | false_high_cond = kCondLT; |
| 2021 | break; |
| 2022 | case kCondGE: |
| 2023 | true_high_cond = kCondGT; |
| 2024 | break; |
| 2025 | case kCondB: |
| 2026 | false_high_cond = kCondA; |
| 2027 | break; |
| 2028 | case kCondBE: |
| 2029 | true_high_cond = kCondB; |
| 2030 | break; |
| 2031 | case kCondA: |
| 2032 | false_high_cond = kCondB; |
| 2033 | break; |
| 2034 | case kCondAE: |
| 2035 | true_high_cond = kCondA; |
| 2036 | break; |
| 2037 | } |
| 2038 | if (right.IsConstant()) { |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 2039 | int64_t value = Int64ConstantFrom(right); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2040 | int32_t val_low = Low32Bits(value); |
| 2041 | int32_t val_high = High32Bits(value); |
| 2042 | |
| 2043 | __ Cmp(left_high, val_high); |
| 2044 | if (if_cond == kCondNE) { |
| 2045 | __ B(ARMCondition(true_high_cond), true_label); |
| 2046 | } else if (if_cond == kCondEQ) { |
| 2047 | __ B(ARMCondition(false_high_cond), false_label); |
| 2048 | } else { |
| 2049 | __ B(ARMCondition(true_high_cond), true_label); |
| 2050 | __ B(ARMCondition(false_high_cond), false_label); |
| 2051 | } |
| 2052 | // Must be equal high, so compare the lows. |
| 2053 | __ Cmp(left_low, val_low); |
| 2054 | } else { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2055 | vixl32::Register right_high = HighRegisterFrom(right); |
| 2056 | vixl32::Register right_low = LowRegisterFrom(right); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2057 | |
| 2058 | __ Cmp(left_high, right_high); |
| 2059 | if (if_cond == kCondNE) { |
| 2060 | __ B(ARMCondition(true_high_cond), true_label); |
| 2061 | } else if (if_cond == kCondEQ) { |
| 2062 | __ B(ARMCondition(false_high_cond), false_label); |
| 2063 | } else { |
| 2064 | __ B(ARMCondition(true_high_cond), true_label); |
| 2065 | __ B(ARMCondition(false_high_cond), false_label); |
| 2066 | } |
| 2067 | // Must be equal high, so compare the lows. |
| 2068 | __ Cmp(left_low, right_low); |
| 2069 | } |
| 2070 | // The last comparison might be unsigned. |
| 2071 | // TODO: optimize cases where this is always true/false |
| 2072 | __ B(final_condition, true_label); |
| 2073 | } |
| 2074 | |
| 2075 | void InstructionCodeGeneratorARMVIXL::GenerateCompareTestAndBranch(HCondition* condition, |
| 2076 | vixl32::Label* true_target_in, |
| 2077 | vixl32::Label* false_target_in) { |
| 2078 | // Generated branching requires both targets to be explicit. If either of the |
| 2079 | // targets is nullptr (fallthrough) use and bind `fallthrough` instead. |
| 2080 | vixl32::Label fallthrough; |
| 2081 | vixl32::Label* true_target = (true_target_in == nullptr) ? &fallthrough : true_target_in; |
| 2082 | vixl32::Label* false_target = (false_target_in == nullptr) ? &fallthrough : false_target_in; |
| 2083 | |
| 2084 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 2085 | switch (type) { |
| 2086 | case Primitive::kPrimLong: |
| 2087 | GenerateLongComparesAndJumps(condition, true_target, false_target); |
| 2088 | break; |
| 2089 | case Primitive::kPrimFloat: |
| 2090 | case Primitive::kPrimDouble: |
| 2091 | GenerateVcmp(condition); |
| 2092 | GenerateFPJumps(condition, true_target, false_target); |
| 2093 | break; |
| 2094 | default: |
| 2095 | LOG(FATAL) << "Unexpected compare type " << type; |
| 2096 | } |
| 2097 | |
| 2098 | if (false_target != &fallthrough) { |
| 2099 | __ B(false_target); |
| 2100 | } |
| 2101 | |
| 2102 | if (true_target_in == nullptr || false_target_in == nullptr) { |
| 2103 | __ Bind(&fallthrough); |
| 2104 | } |
| 2105 | } |
| 2106 | |
| 2107 | void InstructionCodeGeneratorARMVIXL::GenerateTestAndBranch(HInstruction* instruction, |
| 2108 | size_t condition_input_index, |
| 2109 | vixl32::Label* true_target, |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 2110 | vixl32::Label* false_target, |
| 2111 | bool far_target) { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2112 | HInstruction* cond = instruction->InputAt(condition_input_index); |
| 2113 | |
| 2114 | if (true_target == nullptr && false_target == nullptr) { |
| 2115 | // Nothing to do. The code always falls through. |
| 2116 | return; |
| 2117 | } else if (cond->IsIntConstant()) { |
| 2118 | // Constant condition, statically compared against "true" (integer value 1). |
| 2119 | if (cond->AsIntConstant()->IsTrue()) { |
| 2120 | if (true_target != nullptr) { |
| 2121 | __ B(true_target); |
| 2122 | } |
| 2123 | } else { |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 2124 | DCHECK(cond->AsIntConstant()->IsFalse()) << Int32ConstantFrom(cond); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2125 | if (false_target != nullptr) { |
| 2126 | __ B(false_target); |
| 2127 | } |
| 2128 | } |
| 2129 | return; |
| 2130 | } |
| 2131 | |
| 2132 | // The following code generates these patterns: |
| 2133 | // (1) true_target == nullptr && false_target != nullptr |
| 2134 | // - opposite condition true => branch to false_target |
| 2135 | // (2) true_target != nullptr && false_target == nullptr |
| 2136 | // - condition true => branch to true_target |
| 2137 | // (3) true_target != nullptr && false_target != nullptr |
| 2138 | // - condition true => branch to true_target |
| 2139 | // - branch to false_target |
| 2140 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 2141 | // Condition has been materialized, compare the output to 0. |
| 2142 | if (kIsDebugBuild) { |
| 2143 | Location cond_val = instruction->GetLocations()->InAt(condition_input_index); |
| 2144 | DCHECK(cond_val.IsRegister()); |
| 2145 | } |
| 2146 | if (true_target == nullptr) { |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 2147 | __ CompareAndBranchIfZero(InputRegisterAt(instruction, condition_input_index), |
| 2148 | false_target, |
| 2149 | far_target); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2150 | } else { |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 2151 | __ CompareAndBranchIfNonZero(InputRegisterAt(instruction, condition_input_index), |
| 2152 | true_target, |
| 2153 | far_target); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2154 | } |
| 2155 | } else { |
| 2156 | // Condition has not been materialized. Use its inputs as the comparison and |
| 2157 | // its condition as the branch condition. |
| 2158 | HCondition* condition = cond->AsCondition(); |
| 2159 | |
| 2160 | // If this is a long or FP comparison that has been folded into |
| 2161 | // the HCondition, generate the comparison directly. |
| 2162 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 2163 | if (type == Primitive::kPrimLong || Primitive::IsFloatingPointType(type)) { |
| 2164 | GenerateCompareTestAndBranch(condition, true_target, false_target); |
| 2165 | return; |
| 2166 | } |
| 2167 | |
| 2168 | LocationSummary* locations = cond->GetLocations(); |
| 2169 | DCHECK(locations->InAt(0).IsRegister()); |
| 2170 | vixl32::Register left = InputRegisterAt(cond, 0); |
| 2171 | Location right = locations->InAt(1); |
| 2172 | if (right.IsRegister()) { |
| 2173 | __ Cmp(left, InputRegisterAt(cond, 1)); |
| 2174 | } else { |
| 2175 | DCHECK(right.IsConstant()); |
| 2176 | __ Cmp(left, CodeGenerator::GetInt32ValueOf(right.GetConstant())); |
| 2177 | } |
| 2178 | if (true_target == nullptr) { |
| 2179 | __ B(ARMCondition(condition->GetOppositeCondition()), false_target); |
| 2180 | } else { |
| 2181 | __ B(ARMCondition(condition->GetCondition()), true_target); |
| 2182 | } |
| 2183 | } |
| 2184 | |
| 2185 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 2186 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 2187 | if (true_target != nullptr && false_target != nullptr) { |
| 2188 | __ B(false_target); |
| 2189 | } |
| 2190 | } |
| 2191 | |
| 2192 | void LocationsBuilderARMVIXL::VisitIf(HIf* if_instr) { |
| 2193 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); |
| 2194 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
| 2195 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2196 | } |
| 2197 | } |
| 2198 | |
| 2199 | void InstructionCodeGeneratorARMVIXL::VisitIf(HIf* if_instr) { |
| 2200 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 2201 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2202 | vixl32::Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 2203 | nullptr : codegen_->GetLabelOf(true_successor); |
| 2204 | vixl32::Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 2205 | nullptr : codegen_->GetLabelOf(false_successor); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2206 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
| 2207 | } |
| 2208 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 2209 | void LocationsBuilderARMVIXL::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 2210 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 2211 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
| 2212 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| 2213 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
| 2214 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2215 | } |
| 2216 | } |
| 2217 | |
| 2218 | void InstructionCodeGeneratorARMVIXL::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 2219 | SlowPathCodeARMVIXL* slow_path = |
| 2220 | deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathARMVIXL>(deoptimize); |
| 2221 | GenerateTestAndBranch(deoptimize, |
| 2222 | /* condition_input_index */ 0, |
| 2223 | slow_path->GetEntryLabel(), |
| 2224 | /* false_target */ nullptr); |
| 2225 | } |
| 2226 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2227 | void LocationsBuilderARMVIXL::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 2228 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 2229 | LocationSummary(flag, LocationSummary::kNoCall); |
| 2230 | locations->SetOut(Location::RequiresRegister()); |
| 2231 | } |
| 2232 | |
| 2233 | void InstructionCodeGeneratorARMVIXL::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 2234 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 2235 | OutputRegister(flag), |
| 2236 | sp, |
| 2237 | codegen_->GetStackOffsetOfShouldDeoptimizeFlag()); |
| 2238 | } |
| 2239 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2240 | void LocationsBuilderARMVIXL::VisitSelect(HSelect* select) { |
| 2241 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(select); |
| 2242 | if (Primitive::IsFloatingPointType(select->GetType())) { |
| 2243 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2244 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2245 | } else { |
| 2246 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2247 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2248 | } |
| 2249 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
| 2250 | locations->SetInAt(2, Location::RequiresRegister()); |
| 2251 | } |
| 2252 | locations->SetOut(Location::SameAsFirstInput()); |
| 2253 | } |
| 2254 | |
| 2255 | void InstructionCodeGeneratorARMVIXL::VisitSelect(HSelect* select) { |
| 2256 | LocationSummary* locations = select->GetLocations(); |
| 2257 | vixl32::Label false_target; |
| 2258 | GenerateTestAndBranch(select, |
| 2259 | /* condition_input_index */ 2, |
| 2260 | /* true_target */ nullptr, |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 2261 | &false_target, |
| 2262 | /* far_target */ false); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2263 | codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType()); |
| 2264 | __ Bind(&false_target); |
| 2265 | } |
| 2266 | |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 2267 | void LocationsBuilderARMVIXL::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| 2268 | new (GetGraph()->GetArena()) LocationSummary(info); |
| 2269 | } |
| 2270 | |
| 2271 | void InstructionCodeGeneratorARMVIXL::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 2272 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
| 2273 | } |
| 2274 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2275 | void CodeGeneratorARMVIXL::GenerateNop() { |
| 2276 | __ Nop(); |
| 2277 | } |
| 2278 | |
| 2279 | void LocationsBuilderARMVIXL::HandleCondition(HCondition* cond) { |
| 2280 | LocationSummary* locations = |
| 2281 | new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall); |
| 2282 | // Handle the long/FP comparisons made in instruction simplification. |
| 2283 | switch (cond->InputAt(0)->GetType()) { |
| 2284 | case Primitive::kPrimLong: |
| 2285 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2286 | locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1))); |
| 2287 | if (!cond->IsEmittedAtUseSite()) { |
| 2288 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 2289 | } |
| 2290 | break; |
| 2291 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2292 | case Primitive::kPrimFloat: |
| 2293 | case Primitive::kPrimDouble: |
| 2294 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 2295 | locations->SetInAt(1, ArithmeticZeroOrFpuRegister(cond->InputAt(1))); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2296 | if (!cond->IsEmittedAtUseSite()) { |
| 2297 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2298 | } |
| 2299 | break; |
| 2300 | |
| 2301 | default: |
| 2302 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2303 | locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1))); |
| 2304 | if (!cond->IsEmittedAtUseSite()) { |
| 2305 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2306 | } |
| 2307 | } |
| 2308 | } |
| 2309 | |
| 2310 | void InstructionCodeGeneratorARMVIXL::HandleCondition(HCondition* cond) { |
| 2311 | if (cond->IsEmittedAtUseSite()) { |
| 2312 | return; |
| 2313 | } |
| 2314 | |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 2315 | Location right = cond->GetLocations()->InAt(1); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2316 | vixl32::Register out = OutputRegister(cond); |
| 2317 | vixl32::Label true_label, false_label; |
| 2318 | |
| 2319 | switch (cond->InputAt(0)->GetType()) { |
| 2320 | default: { |
| 2321 | // Integer case. |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 2322 | if (right.IsRegister()) { |
| 2323 | __ Cmp(InputRegisterAt(cond, 0), InputOperandAt(cond, 1)); |
| 2324 | } else { |
| 2325 | DCHECK(right.IsConstant()); |
| 2326 | __ Cmp(InputRegisterAt(cond, 0), |
| 2327 | CodeGenerator::GetInt32ValueOf(right.GetConstant())); |
| 2328 | } |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 2329 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 2330 | 3 * vixl32::kMaxInstructionSizeInBytes, |
| 2331 | CodeBufferCheckScope::kMaximumSize); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2332 | __ ite(ARMCondition(cond->GetCondition())); |
| 2333 | __ mov(ARMCondition(cond->GetCondition()), OutputRegister(cond), 1); |
| 2334 | __ mov(ARMCondition(cond->GetOppositeCondition()), OutputRegister(cond), 0); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2335 | return; |
| 2336 | } |
| 2337 | case Primitive::kPrimLong: |
| 2338 | GenerateLongComparesAndJumps(cond, &true_label, &false_label); |
| 2339 | break; |
| 2340 | case Primitive::kPrimFloat: |
| 2341 | case Primitive::kPrimDouble: |
| 2342 | GenerateVcmp(cond); |
| 2343 | GenerateFPJumps(cond, &true_label, &false_label); |
| 2344 | break; |
| 2345 | } |
| 2346 | |
| 2347 | // Convert the jumps into the result. |
| 2348 | vixl32::Label done_label; |
| 2349 | |
| 2350 | // False case: result = 0. |
| 2351 | __ Bind(&false_label); |
| 2352 | __ Mov(out, 0); |
| 2353 | __ B(&done_label); |
| 2354 | |
| 2355 | // True case: result = 1. |
| 2356 | __ Bind(&true_label); |
| 2357 | __ Mov(out, 1); |
| 2358 | __ Bind(&done_label); |
| 2359 | } |
| 2360 | |
| 2361 | void LocationsBuilderARMVIXL::VisitEqual(HEqual* comp) { |
| 2362 | HandleCondition(comp); |
| 2363 | } |
| 2364 | |
| 2365 | void InstructionCodeGeneratorARMVIXL::VisitEqual(HEqual* comp) { |
| 2366 | HandleCondition(comp); |
| 2367 | } |
| 2368 | |
| 2369 | void LocationsBuilderARMVIXL::VisitNotEqual(HNotEqual* comp) { |
| 2370 | HandleCondition(comp); |
| 2371 | } |
| 2372 | |
| 2373 | void InstructionCodeGeneratorARMVIXL::VisitNotEqual(HNotEqual* comp) { |
| 2374 | HandleCondition(comp); |
| 2375 | } |
| 2376 | |
| 2377 | void LocationsBuilderARMVIXL::VisitLessThan(HLessThan* comp) { |
| 2378 | HandleCondition(comp); |
| 2379 | } |
| 2380 | |
| 2381 | void InstructionCodeGeneratorARMVIXL::VisitLessThan(HLessThan* comp) { |
| 2382 | HandleCondition(comp); |
| 2383 | } |
| 2384 | |
| 2385 | void LocationsBuilderARMVIXL::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| 2386 | HandleCondition(comp); |
| 2387 | } |
| 2388 | |
| 2389 | void InstructionCodeGeneratorARMVIXL::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| 2390 | HandleCondition(comp); |
| 2391 | } |
| 2392 | |
| 2393 | void LocationsBuilderARMVIXL::VisitGreaterThan(HGreaterThan* comp) { |
| 2394 | HandleCondition(comp); |
| 2395 | } |
| 2396 | |
| 2397 | void InstructionCodeGeneratorARMVIXL::VisitGreaterThan(HGreaterThan* comp) { |
| 2398 | HandleCondition(comp); |
| 2399 | } |
| 2400 | |
| 2401 | void LocationsBuilderARMVIXL::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| 2402 | HandleCondition(comp); |
| 2403 | } |
| 2404 | |
| 2405 | void InstructionCodeGeneratorARMVIXL::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| 2406 | HandleCondition(comp); |
| 2407 | } |
| 2408 | |
| 2409 | void LocationsBuilderARMVIXL::VisitBelow(HBelow* comp) { |
| 2410 | HandleCondition(comp); |
| 2411 | } |
| 2412 | |
| 2413 | void InstructionCodeGeneratorARMVIXL::VisitBelow(HBelow* comp) { |
| 2414 | HandleCondition(comp); |
| 2415 | } |
| 2416 | |
| 2417 | void LocationsBuilderARMVIXL::VisitBelowOrEqual(HBelowOrEqual* comp) { |
| 2418 | HandleCondition(comp); |
| 2419 | } |
| 2420 | |
| 2421 | void InstructionCodeGeneratorARMVIXL::VisitBelowOrEqual(HBelowOrEqual* comp) { |
| 2422 | HandleCondition(comp); |
| 2423 | } |
| 2424 | |
| 2425 | void LocationsBuilderARMVIXL::VisitAbove(HAbove* comp) { |
| 2426 | HandleCondition(comp); |
| 2427 | } |
| 2428 | |
| 2429 | void InstructionCodeGeneratorARMVIXL::VisitAbove(HAbove* comp) { |
| 2430 | HandleCondition(comp); |
| 2431 | } |
| 2432 | |
| 2433 | void LocationsBuilderARMVIXL::VisitAboveOrEqual(HAboveOrEqual* comp) { |
| 2434 | HandleCondition(comp); |
| 2435 | } |
| 2436 | |
| 2437 | void InstructionCodeGeneratorARMVIXL::VisitAboveOrEqual(HAboveOrEqual* comp) { |
| 2438 | HandleCondition(comp); |
| 2439 | } |
| 2440 | |
| 2441 | void LocationsBuilderARMVIXL::VisitIntConstant(HIntConstant* constant) { |
| 2442 | LocationSummary* locations = |
| 2443 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 2444 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2445 | } |
| 2446 | |
| 2447 | void InstructionCodeGeneratorARMVIXL::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
| 2448 | // Will be generated at use site. |
| 2449 | } |
| 2450 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2451 | void LocationsBuilderARMVIXL::VisitNullConstant(HNullConstant* constant) { |
| 2452 | LocationSummary* locations = |
| 2453 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 2454 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2455 | } |
| 2456 | |
| 2457 | void InstructionCodeGeneratorARMVIXL::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
| 2458 | // Will be generated at use site. |
| 2459 | } |
| 2460 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2461 | void LocationsBuilderARMVIXL::VisitLongConstant(HLongConstant* constant) { |
| 2462 | LocationSummary* locations = |
| 2463 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 2464 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2465 | } |
| 2466 | |
| 2467 | void InstructionCodeGeneratorARMVIXL::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
| 2468 | // Will be generated at use site. |
| 2469 | } |
| 2470 | |
Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 2471 | void LocationsBuilderARMVIXL::VisitFloatConstant(HFloatConstant* constant) { |
| 2472 | LocationSummary* locations = |
| 2473 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 2474 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2475 | } |
| 2476 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 2477 | void InstructionCodeGeneratorARMVIXL::VisitFloatConstant( |
| 2478 | HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 2479 | // Will be generated at use site. |
| 2480 | } |
| 2481 | |
| 2482 | void LocationsBuilderARMVIXL::VisitDoubleConstant(HDoubleConstant* constant) { |
| 2483 | LocationSummary* locations = |
| 2484 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 2485 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2486 | } |
| 2487 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 2488 | void InstructionCodeGeneratorARMVIXL::VisitDoubleConstant( |
| 2489 | HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 2490 | // Will be generated at use site. |
| 2491 | } |
| 2492 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2493 | void LocationsBuilderARMVIXL::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 2494 | memory_barrier->SetLocations(nullptr); |
| 2495 | } |
| 2496 | |
| 2497 | void InstructionCodeGeneratorARMVIXL::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 2498 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
| 2499 | } |
| 2500 | |
| 2501 | void LocationsBuilderARMVIXL::VisitReturnVoid(HReturnVoid* ret) { |
| 2502 | ret->SetLocations(nullptr); |
| 2503 | } |
| 2504 | |
| 2505 | void InstructionCodeGeneratorARMVIXL::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
| 2506 | codegen_->GenerateFrameExit(); |
| 2507 | } |
| 2508 | |
| 2509 | void LocationsBuilderARMVIXL::VisitReturn(HReturn* ret) { |
| 2510 | LocationSummary* locations = |
| 2511 | new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall); |
| 2512 | locations->SetInAt(0, parameter_visitor_.GetReturnLocation(ret->InputAt(0)->GetType())); |
| 2513 | } |
| 2514 | |
| 2515 | void InstructionCodeGeneratorARMVIXL::VisitReturn(HReturn* ret ATTRIBUTE_UNUSED) { |
| 2516 | codegen_->GenerateFrameExit(); |
| 2517 | } |
| 2518 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 2519 | void LocationsBuilderARMVIXL::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2520 | // The trampoline uses the same calling convention as dex calling conventions, |
| 2521 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 2522 | // the method_idx. |
| 2523 | HandleInvoke(invoke); |
| 2524 | } |
| 2525 | |
| 2526 | void InstructionCodeGeneratorARMVIXL::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2527 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 2528 | } |
| 2529 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2530 | void LocationsBuilderARMVIXL::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
| 2531 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2532 | // art::PrepareForRegisterAllocation. |
| 2533 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
| 2534 | |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 2535 | IntrinsicLocationsBuilderARMVIXL intrinsic(codegen_); |
| 2536 | if (intrinsic.TryDispatch(invoke)) { |
| 2537 | if (invoke->GetLocations()->CanCall() && invoke->HasPcRelativeDexCache()) { |
| 2538 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::Any()); |
| 2539 | } |
| 2540 | return; |
| 2541 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2542 | |
| 2543 | HandleInvoke(invoke); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 2544 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2545 | // For PC-relative dex cache the invoke has an extra input, the PC-relative address base. |
| 2546 | if (invoke->HasPcRelativeDexCache()) { |
| 2547 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::RequiresRegister()); |
| 2548 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2549 | } |
| 2550 | |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 2551 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARMVIXL* codegen) { |
| 2552 | if (invoke->GetLocations()->Intrinsified()) { |
| 2553 | IntrinsicCodeGeneratorARMVIXL intrinsic(codegen); |
| 2554 | intrinsic.Dispatch(invoke); |
| 2555 | return true; |
| 2556 | } |
| 2557 | return false; |
| 2558 | } |
| 2559 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2560 | void InstructionCodeGeneratorARMVIXL::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
| 2561 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2562 | // art::PrepareForRegisterAllocation. |
| 2563 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
| 2564 | |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 2565 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2566 | return; |
| 2567 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2568 | |
| 2569 | LocationSummary* locations = invoke->GetLocations(); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2570 | codegen_->GenerateStaticOrDirectCall( |
| 2571 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2572 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 2573 | } |
| 2574 | |
| 2575 | void LocationsBuilderARMVIXL::HandleInvoke(HInvoke* invoke) { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2576 | InvokeDexCallingConventionVisitorARMVIXL calling_convention_visitor; |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2577 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
| 2578 | } |
| 2579 | |
| 2580 | void LocationsBuilderARMVIXL::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 2581 | IntrinsicLocationsBuilderARMVIXL intrinsic(codegen_); |
| 2582 | if (intrinsic.TryDispatch(invoke)) { |
| 2583 | return; |
| 2584 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2585 | |
| 2586 | HandleInvoke(invoke); |
| 2587 | } |
| 2588 | |
| 2589 | void InstructionCodeGeneratorARMVIXL::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 2590 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2591 | return; |
| 2592 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2593 | |
| 2594 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2595 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 2596 | DCHECK(!codegen_->IsLeafMethod()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2597 | } |
| 2598 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 2599 | void LocationsBuilderARMVIXL::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2600 | HandleInvoke(invoke); |
| 2601 | // Add the hidden argument. |
| 2602 | invoke->GetLocations()->AddTemp(LocationFrom(r12)); |
| 2603 | } |
| 2604 | |
| 2605 | void InstructionCodeGeneratorARMVIXL::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2606 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
| 2607 | LocationSummary* locations = invoke->GetLocations(); |
| 2608 | vixl32::Register temp = RegisterFrom(locations->GetTemp(0)); |
| 2609 | vixl32::Register hidden_reg = RegisterFrom(locations->GetTemp(1)); |
| 2610 | Location receiver = locations->InAt(0); |
| 2611 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2612 | |
| 2613 | DCHECK(!receiver.IsStackSlot()); |
| 2614 | |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 2615 | // Ensure the pc position is recorded immediately after the `ldr` instruction. |
| 2616 | { |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 2617 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 2618 | vixl32::kMaxInstructionSizeInBytes, |
| 2619 | CodeBufferCheckScope::kMaximumSize); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 2620 | // /* HeapReference<Class> */ temp = receiver->klass_ |
| 2621 | __ ldr(temp, MemOperand(RegisterFrom(receiver), class_offset)); |
| 2622 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
| 2623 | } |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 2624 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 2625 | // emit a read barrier for the previous class reference load. |
| 2626 | // However this is not required in practice, as this is an |
| 2627 | // intermediate/temporary reference and because the current |
| 2628 | // concurrent copying collector keeps the from-space memory |
| 2629 | // intact/accessible until the end of the marking phase (the |
| 2630 | // concurrent copying collector may not in the future). |
| 2631 | GetAssembler()->MaybeUnpoisonHeapReference(temp); |
| 2632 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 2633 | temp, |
| 2634 | temp, |
| 2635 | mirror::Class::ImtPtrOffset(kArmPointerSize).Uint32Value()); |
| 2636 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
| 2637 | invoke->GetImtIndex(), kArmPointerSize)); |
| 2638 | // temp = temp->GetImtEntryAt(method_offset); |
| 2639 | GetAssembler()->LoadFromOffset(kLoadWord, temp, temp, method_offset); |
| 2640 | uint32_t entry_point = |
| 2641 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize).Int32Value(); |
| 2642 | // LR = temp->GetEntryPoint(); |
| 2643 | GetAssembler()->LoadFromOffset(kLoadWord, lr, temp, entry_point); |
| 2644 | |
| 2645 | // Set the hidden (in r12) argument. It is done here, right before a BLX to prevent other |
| 2646 | // instruction from clobbering it as they might use r12 as a scratch register. |
| 2647 | DCHECK(hidden_reg.Is(r12)); |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 2648 | |
| 2649 | { |
| 2650 | // The VIXL macro assembler may clobber any of the scratch registers that are available to it, |
| 2651 | // so it checks if the application is using them (by passing them to the macro assembler |
| 2652 | // methods). The following application of UseScratchRegisterScope corrects VIXL's notion of |
| 2653 | // what is available, and is the opposite of the standard usage: Instead of requesting a |
| 2654 | // temporary location, it imposes an external constraint (i.e. a specific register is reserved |
| 2655 | // for the hidden argument). Note that this works even if VIXL needs a scratch register itself |
| 2656 | // (to materialize the constant), since the destination register becomes available for such use |
| 2657 | // internally for the duration of the macro instruction. |
| 2658 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2659 | temps.Exclude(hidden_reg); |
| 2660 | __ Mov(hidden_reg, invoke->GetDexMethodIndex()); |
| 2661 | } |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 2662 | { |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 2663 | // Ensure the pc position is recorded immediately after the `blx` instruction. |
| 2664 | // 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] | 2665 | ExactAssemblyScope aas(GetVIXLAssembler(), |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 2666 | vixl32::k16BitT32InstructionSizeInBytes, |
| 2667 | CodeBufferCheckScope::kExactSize); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 2668 | // LR(); |
| 2669 | __ blx(lr); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 2670 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 2671 | DCHECK(!codegen_->IsLeafMethod()); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 2672 | } |
| 2673 | } |
| 2674 | |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 2675 | void LocationsBuilderARMVIXL::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 2676 | HandleInvoke(invoke); |
| 2677 | } |
| 2678 | |
| 2679 | void InstructionCodeGeneratorARMVIXL::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 2680 | codegen_->GenerateInvokePolymorphicCall(invoke); |
| 2681 | } |
| 2682 | |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 2683 | void LocationsBuilderARMVIXL::VisitNeg(HNeg* neg) { |
| 2684 | LocationSummary* locations = |
| 2685 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 2686 | switch (neg->GetResultType()) { |
| 2687 | case Primitive::kPrimInt: { |
| 2688 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2689 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2690 | break; |
| 2691 | } |
| 2692 | case Primitive::kPrimLong: { |
| 2693 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2694 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 2695 | break; |
| 2696 | } |
| 2697 | |
| 2698 | case Primitive::kPrimFloat: |
| 2699 | case Primitive::kPrimDouble: |
| 2700 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2701 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 2702 | break; |
| 2703 | |
| 2704 | default: |
| 2705 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2706 | } |
| 2707 | } |
| 2708 | |
| 2709 | void InstructionCodeGeneratorARMVIXL::VisitNeg(HNeg* neg) { |
| 2710 | LocationSummary* locations = neg->GetLocations(); |
| 2711 | Location out = locations->Out(); |
| 2712 | Location in = locations->InAt(0); |
| 2713 | switch (neg->GetResultType()) { |
| 2714 | case Primitive::kPrimInt: |
| 2715 | __ Rsb(OutputRegister(neg), InputRegisterAt(neg, 0), 0); |
| 2716 | break; |
| 2717 | |
| 2718 | case Primitive::kPrimLong: |
| 2719 | // out.lo = 0 - in.lo (and update the carry/borrow (C) flag) |
| 2720 | __ Rsbs(LowRegisterFrom(out), LowRegisterFrom(in), 0); |
| 2721 | // We cannot emit an RSC (Reverse Subtract with Carry) |
| 2722 | // instruction here, as it does not exist in the Thumb-2 |
| 2723 | // instruction set. We use the following approach |
| 2724 | // using SBC and SUB instead. |
| 2725 | // |
| 2726 | // out.hi = -C |
| 2727 | __ Sbc(HighRegisterFrom(out), HighRegisterFrom(out), HighRegisterFrom(out)); |
| 2728 | // out.hi = out.hi - in.hi |
| 2729 | __ Sub(HighRegisterFrom(out), HighRegisterFrom(out), HighRegisterFrom(in)); |
| 2730 | break; |
| 2731 | |
| 2732 | case Primitive::kPrimFloat: |
| 2733 | case Primitive::kPrimDouble: |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 2734 | __ Vneg(OutputVRegister(neg), InputVRegister(neg)); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 2735 | break; |
| 2736 | |
| 2737 | default: |
| 2738 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2739 | } |
| 2740 | } |
| 2741 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2742 | void LocationsBuilderARMVIXL::VisitTypeConversion(HTypeConversion* conversion) { |
| 2743 | Primitive::Type result_type = conversion->GetResultType(); |
| 2744 | Primitive::Type input_type = conversion->GetInputType(); |
| 2745 | DCHECK_NE(result_type, input_type); |
| 2746 | |
| 2747 | // The float-to-long, double-to-long and long-to-float type conversions |
| 2748 | // rely on a call to the runtime. |
| 2749 | LocationSummary::CallKind call_kind = |
| 2750 | (((input_type == Primitive::kPrimFloat || input_type == Primitive::kPrimDouble) |
| 2751 | && result_type == Primitive::kPrimLong) |
| 2752 | || (input_type == Primitive::kPrimLong && result_type == Primitive::kPrimFloat)) |
| 2753 | ? LocationSummary::kCallOnMainOnly |
| 2754 | : LocationSummary::kNoCall; |
| 2755 | LocationSummary* locations = |
| 2756 | new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind); |
| 2757 | |
| 2758 | // The Java language does not allow treating boolean as an integral type but |
| 2759 | // our bit representation makes it safe. |
| 2760 | |
| 2761 | switch (result_type) { |
| 2762 | case Primitive::kPrimByte: |
| 2763 | switch (input_type) { |
| 2764 | case Primitive::kPrimLong: |
| 2765 | // Type conversion from long to byte is a result of code transformations. |
| 2766 | case Primitive::kPrimBoolean: |
| 2767 | // Boolean input is a result of code transformations. |
| 2768 | case Primitive::kPrimShort: |
| 2769 | case Primitive::kPrimInt: |
| 2770 | case Primitive::kPrimChar: |
| 2771 | // Processing a Dex `int-to-byte' instruction. |
| 2772 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2773 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2774 | break; |
| 2775 | |
| 2776 | default: |
| 2777 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2778 | << " to " << result_type; |
| 2779 | } |
| 2780 | break; |
| 2781 | |
| 2782 | case Primitive::kPrimShort: |
| 2783 | switch (input_type) { |
| 2784 | case Primitive::kPrimLong: |
| 2785 | // Type conversion from long to short is a result of code transformations. |
| 2786 | case Primitive::kPrimBoolean: |
| 2787 | // Boolean input is a result of code transformations. |
| 2788 | case Primitive::kPrimByte: |
| 2789 | case Primitive::kPrimInt: |
| 2790 | case Primitive::kPrimChar: |
| 2791 | // Processing a Dex `int-to-short' instruction. |
| 2792 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2793 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2794 | break; |
| 2795 | |
| 2796 | default: |
| 2797 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2798 | << " to " << result_type; |
| 2799 | } |
| 2800 | break; |
| 2801 | |
| 2802 | case Primitive::kPrimInt: |
| 2803 | switch (input_type) { |
| 2804 | case Primitive::kPrimLong: |
| 2805 | // Processing a Dex `long-to-int' instruction. |
| 2806 | locations->SetInAt(0, Location::Any()); |
| 2807 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2808 | break; |
| 2809 | |
| 2810 | case Primitive::kPrimFloat: |
| 2811 | // Processing a Dex `float-to-int' instruction. |
| 2812 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2813 | locations->SetOut(Location::RequiresRegister()); |
| 2814 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2815 | break; |
| 2816 | |
| 2817 | case Primitive::kPrimDouble: |
| 2818 | // Processing a Dex `double-to-int' instruction. |
| 2819 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2820 | locations->SetOut(Location::RequiresRegister()); |
| 2821 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2822 | break; |
| 2823 | |
| 2824 | default: |
| 2825 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2826 | << " to " << result_type; |
| 2827 | } |
| 2828 | break; |
| 2829 | |
| 2830 | case Primitive::kPrimLong: |
| 2831 | switch (input_type) { |
| 2832 | case Primitive::kPrimBoolean: |
| 2833 | // Boolean input is a result of code transformations. |
| 2834 | case Primitive::kPrimByte: |
| 2835 | case Primitive::kPrimShort: |
| 2836 | case Primitive::kPrimInt: |
| 2837 | case Primitive::kPrimChar: |
| 2838 | // Processing a Dex `int-to-long' instruction. |
| 2839 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2840 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2841 | break; |
| 2842 | |
| 2843 | case Primitive::kPrimFloat: { |
| 2844 | // Processing a Dex `float-to-long' instruction. |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2845 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 2846 | locations->SetInAt(0, LocationFrom(calling_convention.GetFpuRegisterAt(0))); |
| 2847 | locations->SetOut(LocationFrom(r0, r1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2848 | break; |
| 2849 | } |
| 2850 | |
| 2851 | case Primitive::kPrimDouble: { |
| 2852 | // Processing a Dex `double-to-long' instruction. |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2853 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 2854 | locations->SetInAt(0, LocationFrom(calling_convention.GetFpuRegisterAt(0), |
| 2855 | calling_convention.GetFpuRegisterAt(1))); |
| 2856 | locations->SetOut(LocationFrom(r0, r1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2857 | break; |
| 2858 | } |
| 2859 | |
| 2860 | default: |
| 2861 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2862 | << " to " << result_type; |
| 2863 | } |
| 2864 | break; |
| 2865 | |
| 2866 | case Primitive::kPrimChar: |
| 2867 | switch (input_type) { |
| 2868 | case Primitive::kPrimLong: |
| 2869 | // Type conversion from long to char is a result of code transformations. |
| 2870 | case Primitive::kPrimBoolean: |
| 2871 | // Boolean input is a result of code transformations. |
| 2872 | case Primitive::kPrimByte: |
| 2873 | case Primitive::kPrimShort: |
| 2874 | case Primitive::kPrimInt: |
| 2875 | // Processing a Dex `int-to-char' instruction. |
| 2876 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2877 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2878 | break; |
| 2879 | |
| 2880 | default: |
| 2881 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2882 | << " to " << result_type; |
| 2883 | } |
| 2884 | break; |
| 2885 | |
| 2886 | case Primitive::kPrimFloat: |
| 2887 | switch (input_type) { |
| 2888 | case Primitive::kPrimBoolean: |
| 2889 | // Boolean input is a result of code transformations. |
| 2890 | case Primitive::kPrimByte: |
| 2891 | case Primitive::kPrimShort: |
| 2892 | case Primitive::kPrimInt: |
| 2893 | case Primitive::kPrimChar: |
| 2894 | // Processing a Dex `int-to-float' instruction. |
| 2895 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2896 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2897 | break; |
| 2898 | |
| 2899 | case Primitive::kPrimLong: { |
| 2900 | // Processing a Dex `long-to-float' instruction. |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2901 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 2902 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0), |
| 2903 | calling_convention.GetRegisterAt(1))); |
| 2904 | locations->SetOut(LocationFrom(calling_convention.GetFpuRegisterAt(0))); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2905 | break; |
| 2906 | } |
| 2907 | |
| 2908 | case Primitive::kPrimDouble: |
| 2909 | // Processing a Dex `double-to-float' instruction. |
| 2910 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2911 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 2912 | break; |
| 2913 | |
| 2914 | default: |
| 2915 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2916 | << " to " << result_type; |
| 2917 | }; |
| 2918 | break; |
| 2919 | |
| 2920 | case Primitive::kPrimDouble: |
| 2921 | switch (input_type) { |
| 2922 | case Primitive::kPrimBoolean: |
| 2923 | // Boolean input is a result of code transformations. |
| 2924 | case Primitive::kPrimByte: |
| 2925 | case Primitive::kPrimShort: |
| 2926 | case Primitive::kPrimInt: |
| 2927 | case Primitive::kPrimChar: |
| 2928 | // Processing a Dex `int-to-double' instruction. |
| 2929 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2930 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2931 | break; |
| 2932 | |
| 2933 | case Primitive::kPrimLong: |
| 2934 | // Processing a Dex `long-to-double' instruction. |
| 2935 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2936 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2937 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2938 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2939 | break; |
| 2940 | |
| 2941 | case Primitive::kPrimFloat: |
| 2942 | // Processing a Dex `float-to-double' instruction. |
| 2943 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2944 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 2945 | break; |
| 2946 | |
| 2947 | default: |
| 2948 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2949 | << " to " << result_type; |
| 2950 | }; |
| 2951 | break; |
| 2952 | |
| 2953 | default: |
| 2954 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2955 | << " to " << result_type; |
| 2956 | } |
| 2957 | } |
| 2958 | |
| 2959 | void InstructionCodeGeneratorARMVIXL::VisitTypeConversion(HTypeConversion* conversion) { |
| 2960 | LocationSummary* locations = conversion->GetLocations(); |
| 2961 | Location out = locations->Out(); |
| 2962 | Location in = locations->InAt(0); |
| 2963 | Primitive::Type result_type = conversion->GetResultType(); |
| 2964 | Primitive::Type input_type = conversion->GetInputType(); |
| 2965 | DCHECK_NE(result_type, input_type); |
| 2966 | switch (result_type) { |
| 2967 | case Primitive::kPrimByte: |
| 2968 | switch (input_type) { |
| 2969 | case Primitive::kPrimLong: |
| 2970 | // Type conversion from long to byte is a result of code transformations. |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2971 | __ Sbfx(OutputRegister(conversion), LowRegisterFrom(in), 0, 8); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2972 | break; |
| 2973 | case Primitive::kPrimBoolean: |
| 2974 | // Boolean input is a result of code transformations. |
| 2975 | case Primitive::kPrimShort: |
| 2976 | case Primitive::kPrimInt: |
| 2977 | case Primitive::kPrimChar: |
| 2978 | // Processing a Dex `int-to-byte' instruction. |
| 2979 | __ Sbfx(OutputRegister(conversion), InputRegisterAt(conversion, 0), 0, 8); |
| 2980 | break; |
| 2981 | |
| 2982 | default: |
| 2983 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2984 | << " to " << result_type; |
| 2985 | } |
| 2986 | break; |
| 2987 | |
| 2988 | case Primitive::kPrimShort: |
| 2989 | switch (input_type) { |
| 2990 | case Primitive::kPrimLong: |
| 2991 | // Type conversion from long to short is a result of code transformations. |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2992 | __ Sbfx(OutputRegister(conversion), LowRegisterFrom(in), 0, 16); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2993 | break; |
| 2994 | case Primitive::kPrimBoolean: |
| 2995 | // Boolean input is a result of code transformations. |
| 2996 | case Primitive::kPrimByte: |
| 2997 | case Primitive::kPrimInt: |
| 2998 | case Primitive::kPrimChar: |
| 2999 | // Processing a Dex `int-to-short' instruction. |
| 3000 | __ Sbfx(OutputRegister(conversion), InputRegisterAt(conversion, 0), 0, 16); |
| 3001 | break; |
| 3002 | |
| 3003 | default: |
| 3004 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3005 | << " to " << result_type; |
| 3006 | } |
| 3007 | break; |
| 3008 | |
| 3009 | case Primitive::kPrimInt: |
| 3010 | switch (input_type) { |
| 3011 | case Primitive::kPrimLong: |
| 3012 | // Processing a Dex `long-to-int' instruction. |
| 3013 | DCHECK(out.IsRegister()); |
| 3014 | if (in.IsRegisterPair()) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3015 | __ Mov(OutputRegister(conversion), LowRegisterFrom(in)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3016 | } else if (in.IsDoubleStackSlot()) { |
| 3017 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 3018 | OutputRegister(conversion), |
| 3019 | sp, |
| 3020 | in.GetStackIndex()); |
| 3021 | } else { |
| 3022 | DCHECK(in.IsConstant()); |
| 3023 | DCHECK(in.GetConstant()->IsLongConstant()); |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 3024 | int32_t value = Int32ConstantFrom(in); |
| 3025 | __ Mov(OutputRegister(conversion), value); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3026 | } |
| 3027 | break; |
| 3028 | |
| 3029 | case Primitive::kPrimFloat: { |
| 3030 | // Processing a Dex `float-to-int' instruction. |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3031 | vixl32::SRegister temp = LowSRegisterFrom(locations->GetTemp(0)); |
Scott Wakeling | fb0b7d4 | 2016-10-28 16:11:08 +0100 | [diff] [blame] | 3032 | __ Vcvt(S32, F32, temp, InputSRegisterAt(conversion, 0)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3033 | __ Vmov(OutputRegister(conversion), temp); |
| 3034 | break; |
| 3035 | } |
| 3036 | |
| 3037 | case Primitive::kPrimDouble: { |
| 3038 | // Processing a Dex `double-to-int' instruction. |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3039 | vixl32::SRegister temp_s = LowSRegisterFrom(locations->GetTemp(0)); |
Scott Wakeling | fb0b7d4 | 2016-10-28 16:11:08 +0100 | [diff] [blame] | 3040 | __ Vcvt(S32, F64, temp_s, DRegisterFrom(in)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3041 | __ Vmov(OutputRegister(conversion), temp_s); |
| 3042 | break; |
| 3043 | } |
| 3044 | |
| 3045 | default: |
| 3046 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3047 | << " to " << result_type; |
| 3048 | } |
| 3049 | break; |
| 3050 | |
| 3051 | case Primitive::kPrimLong: |
| 3052 | switch (input_type) { |
| 3053 | case Primitive::kPrimBoolean: |
| 3054 | // Boolean input is a result of code transformations. |
| 3055 | case Primitive::kPrimByte: |
| 3056 | case Primitive::kPrimShort: |
| 3057 | case Primitive::kPrimInt: |
| 3058 | case Primitive::kPrimChar: |
| 3059 | // Processing a Dex `int-to-long' instruction. |
| 3060 | DCHECK(out.IsRegisterPair()); |
| 3061 | DCHECK(in.IsRegister()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3062 | __ Mov(LowRegisterFrom(out), InputRegisterAt(conversion, 0)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3063 | // Sign extension. |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3064 | __ Asr(HighRegisterFrom(out), LowRegisterFrom(out), 31); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3065 | break; |
| 3066 | |
| 3067 | case Primitive::kPrimFloat: |
| 3068 | // Processing a Dex `float-to-long' instruction. |
| 3069 | codegen_->InvokeRuntime(kQuickF2l, conversion, conversion->GetDexPc()); |
| 3070 | CheckEntrypointTypes<kQuickF2l, int64_t, float>(); |
| 3071 | break; |
| 3072 | |
| 3073 | case Primitive::kPrimDouble: |
| 3074 | // Processing a Dex `double-to-long' instruction. |
| 3075 | codegen_->InvokeRuntime(kQuickD2l, conversion, conversion->GetDexPc()); |
| 3076 | CheckEntrypointTypes<kQuickD2l, int64_t, double>(); |
| 3077 | break; |
| 3078 | |
| 3079 | default: |
| 3080 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3081 | << " to " << result_type; |
| 3082 | } |
| 3083 | break; |
| 3084 | |
| 3085 | case Primitive::kPrimChar: |
| 3086 | switch (input_type) { |
| 3087 | case Primitive::kPrimLong: |
| 3088 | // Type conversion from long to char is a result of code transformations. |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3089 | __ Ubfx(OutputRegister(conversion), LowRegisterFrom(in), 0, 16); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3090 | break; |
| 3091 | case Primitive::kPrimBoolean: |
| 3092 | // Boolean input is a result of code transformations. |
| 3093 | case Primitive::kPrimByte: |
| 3094 | case Primitive::kPrimShort: |
| 3095 | case Primitive::kPrimInt: |
| 3096 | // Processing a Dex `int-to-char' instruction. |
| 3097 | __ Ubfx(OutputRegister(conversion), InputRegisterAt(conversion, 0), 0, 16); |
| 3098 | break; |
| 3099 | |
| 3100 | default: |
| 3101 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3102 | << " to " << result_type; |
| 3103 | } |
| 3104 | break; |
| 3105 | |
| 3106 | case Primitive::kPrimFloat: |
| 3107 | switch (input_type) { |
| 3108 | case Primitive::kPrimBoolean: |
| 3109 | // Boolean input is a result of code transformations. |
| 3110 | case Primitive::kPrimByte: |
| 3111 | case Primitive::kPrimShort: |
| 3112 | case Primitive::kPrimInt: |
| 3113 | case Primitive::kPrimChar: { |
| 3114 | // Processing a Dex `int-to-float' instruction. |
| 3115 | __ Vmov(OutputSRegister(conversion), InputRegisterAt(conversion, 0)); |
Scott Wakeling | fb0b7d4 | 2016-10-28 16:11:08 +0100 | [diff] [blame] | 3116 | __ Vcvt(F32, S32, OutputSRegister(conversion), OutputSRegister(conversion)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3117 | break; |
| 3118 | } |
| 3119 | |
| 3120 | case Primitive::kPrimLong: |
| 3121 | // Processing a Dex `long-to-float' instruction. |
| 3122 | codegen_->InvokeRuntime(kQuickL2f, conversion, conversion->GetDexPc()); |
| 3123 | CheckEntrypointTypes<kQuickL2f, float, int64_t>(); |
| 3124 | break; |
| 3125 | |
| 3126 | case Primitive::kPrimDouble: |
| 3127 | // Processing a Dex `double-to-float' instruction. |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 3128 | __ Vcvt(F32, F64, OutputSRegister(conversion), DRegisterFrom(in)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3129 | break; |
| 3130 | |
| 3131 | default: |
| 3132 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3133 | << " to " << result_type; |
| 3134 | }; |
| 3135 | break; |
| 3136 | |
| 3137 | case Primitive::kPrimDouble: |
| 3138 | switch (input_type) { |
| 3139 | case Primitive::kPrimBoolean: |
| 3140 | // Boolean input is a result of code transformations. |
| 3141 | case Primitive::kPrimByte: |
| 3142 | case Primitive::kPrimShort: |
| 3143 | case Primitive::kPrimInt: |
| 3144 | case Primitive::kPrimChar: { |
| 3145 | // Processing a Dex `int-to-double' instruction. |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3146 | __ Vmov(LowSRegisterFrom(out), InputRegisterAt(conversion, 0)); |
Scott Wakeling | fb0b7d4 | 2016-10-28 16:11:08 +0100 | [diff] [blame] | 3147 | __ Vcvt(F64, S32, DRegisterFrom(out), LowSRegisterFrom(out)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3148 | break; |
| 3149 | } |
| 3150 | |
| 3151 | case Primitive::kPrimLong: { |
| 3152 | // Processing a Dex `long-to-double' instruction. |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3153 | vixl32::Register low = LowRegisterFrom(in); |
| 3154 | vixl32::Register high = HighRegisterFrom(in); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3155 | vixl32::SRegister out_s = LowSRegisterFrom(out); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 3156 | vixl32::DRegister out_d = DRegisterFrom(out); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3157 | vixl32::SRegister temp_s = LowSRegisterFrom(locations->GetTemp(0)); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 3158 | vixl32::DRegister temp_d = DRegisterFrom(locations->GetTemp(0)); |
Scott Wakeling | fb0b7d4 | 2016-10-28 16:11:08 +0100 | [diff] [blame] | 3159 | vixl32::DRegister constant_d = DRegisterFrom(locations->GetTemp(1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3160 | |
| 3161 | // temp_d = int-to-double(high) |
| 3162 | __ Vmov(temp_s, high); |
Scott Wakeling | fb0b7d4 | 2016-10-28 16:11:08 +0100 | [diff] [blame] | 3163 | __ Vcvt(F64, S32, temp_d, temp_s); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3164 | // constant_d = k2Pow32EncodingForDouble |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3165 | __ Vmov(constant_d, bit_cast<double, int64_t>(k2Pow32EncodingForDouble)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3166 | // out_d = unsigned-to-double(low) |
| 3167 | __ Vmov(out_s, low); |
| 3168 | __ Vcvt(F64, U32, out_d, out_s); |
| 3169 | // out_d += temp_d * constant_d |
| 3170 | __ Vmla(F64, out_d, temp_d, constant_d); |
| 3171 | break; |
| 3172 | } |
| 3173 | |
| 3174 | case Primitive::kPrimFloat: |
| 3175 | // Processing a Dex `float-to-double' instruction. |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 3176 | __ Vcvt(F64, F32, DRegisterFrom(out), InputSRegisterAt(conversion, 0)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3177 | break; |
| 3178 | |
| 3179 | default: |
| 3180 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3181 | << " to " << result_type; |
| 3182 | }; |
| 3183 | break; |
| 3184 | |
| 3185 | default: |
| 3186 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3187 | << " to " << result_type; |
| 3188 | } |
| 3189 | } |
| 3190 | |
| 3191 | void LocationsBuilderARMVIXL::VisitAdd(HAdd* add) { |
| 3192 | LocationSummary* locations = |
| 3193 | new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall); |
| 3194 | switch (add->GetResultType()) { |
| 3195 | case Primitive::kPrimInt: { |
| 3196 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3197 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
| 3198 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3199 | break; |
| 3200 | } |
| 3201 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3202 | case Primitive::kPrimLong: { |
| 3203 | locations->SetInAt(0, Location::RequiresRegister()); |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 3204 | locations->SetInAt(1, ArmEncodableConstantOrRegister(add->InputAt(1), ADD)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3205 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3206 | break; |
| 3207 | } |
| 3208 | |
| 3209 | case Primitive::kPrimFloat: |
| 3210 | case Primitive::kPrimDouble: { |
| 3211 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3212 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3213 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3214 | break; |
| 3215 | } |
| 3216 | |
| 3217 | default: |
| 3218 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
| 3219 | } |
| 3220 | } |
| 3221 | |
| 3222 | void InstructionCodeGeneratorARMVIXL::VisitAdd(HAdd* add) { |
| 3223 | LocationSummary* locations = add->GetLocations(); |
| 3224 | Location out = locations->Out(); |
| 3225 | Location first = locations->InAt(0); |
| 3226 | Location second = locations->InAt(1); |
| 3227 | |
| 3228 | switch (add->GetResultType()) { |
| 3229 | case Primitive::kPrimInt: { |
| 3230 | __ Add(OutputRegister(add), InputRegisterAt(add, 0), InputOperandAt(add, 1)); |
| 3231 | } |
| 3232 | break; |
| 3233 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3234 | case Primitive::kPrimLong: { |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 3235 | if (second.IsConstant()) { |
| 3236 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant())); |
| 3237 | GenerateAddLongConst(out, first, value); |
| 3238 | } else { |
| 3239 | DCHECK(second.IsRegisterPair()); |
| 3240 | __ Adds(LowRegisterFrom(out), LowRegisterFrom(first), LowRegisterFrom(second)); |
| 3241 | __ Adc(HighRegisterFrom(out), HighRegisterFrom(first), HighRegisterFrom(second)); |
| 3242 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3243 | break; |
| 3244 | } |
| 3245 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3246 | case Primitive::kPrimFloat: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3247 | case Primitive::kPrimDouble: |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3248 | __ Vadd(OutputVRegister(add), InputVRegisterAt(add, 0), InputVRegisterAt(add, 1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3249 | break; |
| 3250 | |
| 3251 | default: |
| 3252 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
| 3253 | } |
| 3254 | } |
| 3255 | |
| 3256 | void LocationsBuilderARMVIXL::VisitSub(HSub* sub) { |
| 3257 | LocationSummary* locations = |
| 3258 | new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); |
| 3259 | switch (sub->GetResultType()) { |
| 3260 | case Primitive::kPrimInt: { |
| 3261 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3262 | locations->SetInAt(1, Location::RegisterOrConstant(sub->InputAt(1))); |
| 3263 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3264 | break; |
| 3265 | } |
| 3266 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3267 | case Primitive::kPrimLong: { |
| 3268 | locations->SetInAt(0, Location::RequiresRegister()); |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 3269 | locations->SetInAt(1, ArmEncodableConstantOrRegister(sub->InputAt(1), SUB)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3270 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3271 | break; |
| 3272 | } |
| 3273 | case Primitive::kPrimFloat: |
| 3274 | case Primitive::kPrimDouble: { |
| 3275 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3276 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3277 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3278 | break; |
| 3279 | } |
| 3280 | default: |
| 3281 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
| 3282 | } |
| 3283 | } |
| 3284 | |
| 3285 | void InstructionCodeGeneratorARMVIXL::VisitSub(HSub* sub) { |
| 3286 | LocationSummary* locations = sub->GetLocations(); |
| 3287 | Location out = locations->Out(); |
| 3288 | Location first = locations->InAt(0); |
| 3289 | Location second = locations->InAt(1); |
| 3290 | switch (sub->GetResultType()) { |
| 3291 | case Primitive::kPrimInt: { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3292 | __ Sub(OutputRegister(sub), InputRegisterAt(sub, 0), InputOperandAt(sub, 1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3293 | break; |
| 3294 | } |
| 3295 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3296 | case Primitive::kPrimLong: { |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 3297 | if (second.IsConstant()) { |
| 3298 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant())); |
| 3299 | GenerateAddLongConst(out, first, -value); |
| 3300 | } else { |
| 3301 | DCHECK(second.IsRegisterPair()); |
| 3302 | __ Subs(LowRegisterFrom(out), LowRegisterFrom(first), LowRegisterFrom(second)); |
| 3303 | __ Sbc(HighRegisterFrom(out), HighRegisterFrom(first), HighRegisterFrom(second)); |
| 3304 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3305 | break; |
| 3306 | } |
| 3307 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3308 | case Primitive::kPrimFloat: |
| 3309 | case Primitive::kPrimDouble: |
| 3310 | __ Vsub(OutputVRegister(sub), InputVRegisterAt(sub, 0), InputVRegisterAt(sub, 1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3311 | break; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3312 | |
| 3313 | default: |
| 3314 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
| 3315 | } |
| 3316 | } |
| 3317 | |
| 3318 | void LocationsBuilderARMVIXL::VisitMul(HMul* mul) { |
| 3319 | LocationSummary* locations = |
| 3320 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 3321 | switch (mul->GetResultType()) { |
| 3322 | case Primitive::kPrimInt: |
| 3323 | case Primitive::kPrimLong: { |
| 3324 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3325 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3326 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3327 | break; |
| 3328 | } |
| 3329 | |
| 3330 | case Primitive::kPrimFloat: |
| 3331 | case Primitive::kPrimDouble: { |
| 3332 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3333 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3334 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3335 | break; |
| 3336 | } |
| 3337 | |
| 3338 | default: |
| 3339 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 3340 | } |
| 3341 | } |
| 3342 | |
| 3343 | void InstructionCodeGeneratorARMVIXL::VisitMul(HMul* mul) { |
| 3344 | LocationSummary* locations = mul->GetLocations(); |
| 3345 | Location out = locations->Out(); |
| 3346 | Location first = locations->InAt(0); |
| 3347 | Location second = locations->InAt(1); |
| 3348 | switch (mul->GetResultType()) { |
| 3349 | case Primitive::kPrimInt: { |
| 3350 | __ Mul(OutputRegister(mul), InputRegisterAt(mul, 0), InputRegisterAt(mul, 1)); |
| 3351 | break; |
| 3352 | } |
| 3353 | case Primitive::kPrimLong: { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3354 | vixl32::Register out_hi = HighRegisterFrom(out); |
| 3355 | vixl32::Register out_lo = LowRegisterFrom(out); |
| 3356 | vixl32::Register in1_hi = HighRegisterFrom(first); |
| 3357 | vixl32::Register in1_lo = LowRegisterFrom(first); |
| 3358 | vixl32::Register in2_hi = HighRegisterFrom(second); |
| 3359 | vixl32::Register in2_lo = LowRegisterFrom(second); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3360 | |
| 3361 | // Extra checks to protect caused by the existence of R1_R2. |
| 3362 | // The algorithm is wrong if out.hi is either in1.lo or in2.lo: |
| 3363 | // (e.g. in1=r0_r1, in2=r2_r3 and out=r1_r2); |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 3364 | DCHECK(!out_hi.Is(in1_lo)); |
| 3365 | DCHECK(!out_hi.Is(in2_lo)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3366 | |
| 3367 | // input: in1 - 64 bits, in2 - 64 bits |
| 3368 | // output: out |
| 3369 | // formula: out.hi : out.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo |
| 3370 | // parts: out.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32] |
| 3371 | // parts: out.lo = (in1.lo * in2.lo)[31:0] |
| 3372 | |
| 3373 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 3374 | vixl32::Register temp = temps.Acquire(); |
| 3375 | // temp <- in1.lo * in2.hi |
| 3376 | __ Mul(temp, in1_lo, in2_hi); |
| 3377 | // out.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3378 | __ Mla(out_hi, in1_hi, in2_lo, temp); |
| 3379 | // out.lo <- (in1.lo * in2.lo)[31:0]; |
| 3380 | __ Umull(out_lo, temp, in1_lo, in2_lo); |
| 3381 | // 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] | 3382 | __ Add(out_hi, out_hi, temp); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3383 | break; |
| 3384 | } |
| 3385 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3386 | case Primitive::kPrimFloat: |
| 3387 | case Primitive::kPrimDouble: |
| 3388 | __ Vmul(OutputVRegister(mul), InputVRegisterAt(mul, 0), InputVRegisterAt(mul, 1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3389 | break; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3390 | |
| 3391 | default: |
| 3392 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 3393 | } |
| 3394 | } |
| 3395 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3396 | void InstructionCodeGeneratorARMVIXL::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 3397 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3398 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 3399 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3400 | Location second = instruction->GetLocations()->InAt(1); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3401 | DCHECK(second.IsConstant()); |
| 3402 | |
| 3403 | vixl32::Register out = OutputRegister(instruction); |
| 3404 | vixl32::Register dividend = InputRegisterAt(instruction, 0); |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 3405 | int32_t imm = Int32ConstantFrom(second); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3406 | DCHECK(imm == 1 || imm == -1); |
| 3407 | |
| 3408 | if (instruction->IsRem()) { |
| 3409 | __ Mov(out, 0); |
| 3410 | } else { |
| 3411 | if (imm == 1) { |
| 3412 | __ Mov(out, dividend); |
| 3413 | } else { |
| 3414 | __ Rsb(out, dividend, 0); |
| 3415 | } |
| 3416 | } |
| 3417 | } |
| 3418 | |
| 3419 | void InstructionCodeGeneratorARMVIXL::DivRemByPowerOfTwo(HBinaryOperation* instruction) { |
| 3420 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3421 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 3422 | |
| 3423 | LocationSummary* locations = instruction->GetLocations(); |
| 3424 | Location second = locations->InAt(1); |
| 3425 | DCHECK(second.IsConstant()); |
| 3426 | |
| 3427 | vixl32::Register out = OutputRegister(instruction); |
| 3428 | vixl32::Register dividend = InputRegisterAt(instruction, 0); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3429 | vixl32::Register temp = RegisterFrom(locations->GetTemp(0)); |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 3430 | int32_t imm = Int32ConstantFrom(second); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3431 | uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm)); |
| 3432 | int ctz_imm = CTZ(abs_imm); |
| 3433 | |
| 3434 | if (ctz_imm == 1) { |
| 3435 | __ Lsr(temp, dividend, 32 - ctz_imm); |
| 3436 | } else { |
| 3437 | __ Asr(temp, dividend, 31); |
| 3438 | __ Lsr(temp, temp, 32 - ctz_imm); |
| 3439 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3440 | __ Add(out, temp, dividend); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3441 | |
| 3442 | if (instruction->IsDiv()) { |
| 3443 | __ Asr(out, out, ctz_imm); |
| 3444 | if (imm < 0) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3445 | __ Rsb(out, out, 0); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3446 | } |
| 3447 | } else { |
| 3448 | __ Ubfx(out, out, 0, ctz_imm); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3449 | __ Sub(out, out, temp); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3450 | } |
| 3451 | } |
| 3452 | |
| 3453 | void InstructionCodeGeneratorARMVIXL::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 3454 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3455 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 3456 | |
| 3457 | LocationSummary* locations = instruction->GetLocations(); |
| 3458 | Location second = locations->InAt(1); |
| 3459 | DCHECK(second.IsConstant()); |
| 3460 | |
| 3461 | vixl32::Register out = OutputRegister(instruction); |
| 3462 | vixl32::Register dividend = InputRegisterAt(instruction, 0); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3463 | vixl32::Register temp1 = RegisterFrom(locations->GetTemp(0)); |
| 3464 | vixl32::Register temp2 = RegisterFrom(locations->GetTemp(1)); |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 3465 | int32_t imm = Int32ConstantFrom(second); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3466 | |
| 3467 | int64_t magic; |
| 3468 | int shift; |
| 3469 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 3470 | |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 3471 | // TODO(VIXL): Change the static cast to Operand::From() after VIXL is fixed. |
| 3472 | __ Mov(temp1, static_cast<int32_t>(magic)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3473 | __ Smull(temp2, temp1, dividend, temp1); |
| 3474 | |
| 3475 | if (imm > 0 && magic < 0) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3476 | __ Add(temp1, temp1, dividend); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3477 | } else if (imm < 0 && magic > 0) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3478 | __ Sub(temp1, temp1, dividend); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3479 | } |
| 3480 | |
| 3481 | if (shift != 0) { |
| 3482 | __ Asr(temp1, temp1, shift); |
| 3483 | } |
| 3484 | |
| 3485 | if (instruction->IsDiv()) { |
| 3486 | __ Sub(out, temp1, Operand(temp1, vixl32::Shift(ASR), 31)); |
| 3487 | } else { |
| 3488 | __ Sub(temp1, temp1, Operand(temp1, vixl32::Shift(ASR), 31)); |
| 3489 | // TODO: Strength reduction for mls. |
| 3490 | __ Mov(temp2, imm); |
| 3491 | __ Mls(out, temp1, temp2, dividend); |
| 3492 | } |
| 3493 | } |
| 3494 | |
| 3495 | void InstructionCodeGeneratorARMVIXL::GenerateDivRemConstantIntegral( |
| 3496 | HBinaryOperation* instruction) { |
| 3497 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3498 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 3499 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3500 | Location second = instruction->GetLocations()->InAt(1); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3501 | DCHECK(second.IsConstant()); |
| 3502 | |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 3503 | int32_t imm = Int32ConstantFrom(second); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3504 | if (imm == 0) { |
| 3505 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 3506 | } else if (imm == 1 || imm == -1) { |
| 3507 | DivRemOneOrMinusOne(instruction); |
| 3508 | } else if (IsPowerOfTwo(AbsOrMin(imm))) { |
| 3509 | DivRemByPowerOfTwo(instruction); |
| 3510 | } else { |
| 3511 | DCHECK(imm <= -2 || imm >= 2); |
| 3512 | GenerateDivRemWithAnyConstant(instruction); |
| 3513 | } |
| 3514 | } |
| 3515 | |
| 3516 | void LocationsBuilderARMVIXL::VisitDiv(HDiv* div) { |
| 3517 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 3518 | if (div->GetResultType() == Primitive::kPrimLong) { |
| 3519 | // pLdiv runtime call. |
| 3520 | call_kind = LocationSummary::kCallOnMainOnly; |
| 3521 | } else if (div->GetResultType() == Primitive::kPrimInt && div->InputAt(1)->IsConstant()) { |
| 3522 | // sdiv will be replaced by other instruction sequence. |
| 3523 | } else if (div->GetResultType() == Primitive::kPrimInt && |
| 3524 | !codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 3525 | // pIdivmod runtime call. |
| 3526 | call_kind = LocationSummary::kCallOnMainOnly; |
| 3527 | } |
| 3528 | |
| 3529 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind); |
| 3530 | |
| 3531 | switch (div->GetResultType()) { |
| 3532 | case Primitive::kPrimInt: { |
| 3533 | if (div->InputAt(1)->IsConstant()) { |
| 3534 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3535 | locations->SetInAt(1, Location::ConstantLocation(div->InputAt(1)->AsConstant())); |
| 3536 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 3537 | int32_t value = Int32ConstantFrom(div->InputAt(1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3538 | if (value == 1 || value == 0 || value == -1) { |
| 3539 | // No temp register required. |
| 3540 | } else { |
| 3541 | locations->AddTemp(Location::RequiresRegister()); |
| 3542 | if (!IsPowerOfTwo(AbsOrMin(value))) { |
| 3543 | locations->AddTemp(Location::RequiresRegister()); |
| 3544 | } |
| 3545 | } |
| 3546 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 3547 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3548 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3549 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3550 | } else { |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 3551 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 3552 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 3553 | locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(1))); |
Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 3554 | // 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] | 3555 | // we only need the former. |
| 3556 | locations->SetOut(LocationFrom(r0)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3557 | } |
| 3558 | break; |
| 3559 | } |
| 3560 | case Primitive::kPrimLong: { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 3561 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 3562 | locations->SetInAt(0, LocationFrom( |
| 3563 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3564 | locations->SetInAt(1, LocationFrom( |
| 3565 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 3566 | locations->SetOut(LocationFrom(r0, r1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3567 | break; |
| 3568 | } |
| 3569 | case Primitive::kPrimFloat: |
| 3570 | case Primitive::kPrimDouble: { |
| 3571 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3572 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3573 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3574 | break; |
| 3575 | } |
| 3576 | |
| 3577 | default: |
| 3578 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3579 | } |
| 3580 | } |
| 3581 | |
| 3582 | void InstructionCodeGeneratorARMVIXL::VisitDiv(HDiv* div) { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 3583 | Location lhs = div->GetLocations()->InAt(0); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3584 | Location rhs = div->GetLocations()->InAt(1); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3585 | |
| 3586 | switch (div->GetResultType()) { |
| 3587 | case Primitive::kPrimInt: { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3588 | if (rhs.IsConstant()) { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3589 | GenerateDivRemConstantIntegral(div); |
| 3590 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 3591 | __ Sdiv(OutputRegister(div), InputRegisterAt(div, 0), InputRegisterAt(div, 1)); |
| 3592 | } else { |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 3593 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 3594 | DCHECK(calling_convention.GetRegisterAt(0).Is(RegisterFrom(lhs))); |
| 3595 | DCHECK(calling_convention.GetRegisterAt(1).Is(RegisterFrom(rhs))); |
| 3596 | DCHECK(r0.Is(OutputRegister(div))); |
| 3597 | |
| 3598 | codegen_->InvokeRuntime(kQuickIdivmod, div, div->GetDexPc()); |
| 3599 | CheckEntrypointTypes<kQuickIdivmod, int32_t, int32_t, int32_t>(); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3600 | } |
| 3601 | break; |
| 3602 | } |
| 3603 | |
| 3604 | case Primitive::kPrimLong: { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 3605 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 3606 | DCHECK(calling_convention.GetRegisterAt(0).Is(LowRegisterFrom(lhs))); |
| 3607 | DCHECK(calling_convention.GetRegisterAt(1).Is(HighRegisterFrom(lhs))); |
| 3608 | DCHECK(calling_convention.GetRegisterAt(2).Is(LowRegisterFrom(rhs))); |
| 3609 | DCHECK(calling_convention.GetRegisterAt(3).Is(HighRegisterFrom(rhs))); |
| 3610 | DCHECK(LowRegisterFrom(div->GetLocations()->Out()).Is(r0)); |
| 3611 | DCHECK(HighRegisterFrom(div->GetLocations()->Out()).Is(r1)); |
| 3612 | |
| 3613 | codegen_->InvokeRuntime(kQuickLdiv, div, div->GetDexPc()); |
| 3614 | CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>(); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3615 | break; |
| 3616 | } |
| 3617 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3618 | case Primitive::kPrimFloat: |
| 3619 | case Primitive::kPrimDouble: |
| 3620 | __ Vdiv(OutputVRegister(div), InputVRegisterAt(div, 0), InputVRegisterAt(div, 1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3621 | break; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3622 | |
| 3623 | default: |
| 3624 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3625 | } |
| 3626 | } |
| 3627 | |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 3628 | void LocationsBuilderARMVIXL::VisitRem(HRem* rem) { |
| 3629 | Primitive::Type type = rem->GetResultType(); |
| 3630 | |
| 3631 | // Most remainders are implemented in the runtime. |
| 3632 | LocationSummary::CallKind call_kind = LocationSummary::kCallOnMainOnly; |
| 3633 | if (rem->GetResultType() == Primitive::kPrimInt && rem->InputAt(1)->IsConstant()) { |
| 3634 | // sdiv will be replaced by other instruction sequence. |
| 3635 | call_kind = LocationSummary::kNoCall; |
| 3636 | } else if ((rem->GetResultType() == Primitive::kPrimInt) |
| 3637 | && codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 3638 | // Have hardware divide instruction for int, do it with three instructions. |
| 3639 | call_kind = LocationSummary::kNoCall; |
| 3640 | } |
| 3641 | |
| 3642 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind); |
| 3643 | |
| 3644 | switch (type) { |
| 3645 | case Primitive::kPrimInt: { |
| 3646 | if (rem->InputAt(1)->IsConstant()) { |
| 3647 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3648 | locations->SetInAt(1, Location::ConstantLocation(rem->InputAt(1)->AsConstant())); |
| 3649 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 3650 | int32_t value = Int32ConstantFrom(rem->InputAt(1)); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 3651 | if (value == 1 || value == 0 || value == -1) { |
| 3652 | // No temp register required. |
| 3653 | } else { |
| 3654 | locations->AddTemp(Location::RequiresRegister()); |
| 3655 | if (!IsPowerOfTwo(AbsOrMin(value))) { |
| 3656 | locations->AddTemp(Location::RequiresRegister()); |
| 3657 | } |
| 3658 | } |
| 3659 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 3660 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3661 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3662 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3663 | locations->AddTemp(Location::RequiresRegister()); |
| 3664 | } else { |
| 3665 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 3666 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 3667 | locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(1))); |
Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 3668 | // 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] | 3669 | // we only need the latter. |
| 3670 | locations->SetOut(LocationFrom(r1)); |
| 3671 | } |
| 3672 | break; |
| 3673 | } |
| 3674 | case Primitive::kPrimLong: { |
| 3675 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 3676 | locations->SetInAt(0, LocationFrom( |
| 3677 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3678 | locations->SetInAt(1, LocationFrom( |
| 3679 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 3680 | // The runtime helper puts the output in R2,R3. |
| 3681 | locations->SetOut(LocationFrom(r2, r3)); |
| 3682 | break; |
| 3683 | } |
| 3684 | case Primitive::kPrimFloat: { |
| 3685 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 3686 | locations->SetInAt(0, LocationFrom(calling_convention.GetFpuRegisterAt(0))); |
| 3687 | locations->SetInAt(1, LocationFrom(calling_convention.GetFpuRegisterAt(1))); |
| 3688 | locations->SetOut(LocationFrom(s0)); |
| 3689 | break; |
| 3690 | } |
| 3691 | |
| 3692 | case Primitive::kPrimDouble: { |
| 3693 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 3694 | locations->SetInAt(0, LocationFrom( |
| 3695 | calling_convention.GetFpuRegisterAt(0), calling_convention.GetFpuRegisterAt(1))); |
| 3696 | locations->SetInAt(1, LocationFrom( |
| 3697 | calling_convention.GetFpuRegisterAt(2), calling_convention.GetFpuRegisterAt(3))); |
| 3698 | locations->SetOut(LocationFrom(s0, s1)); |
| 3699 | break; |
| 3700 | } |
| 3701 | |
| 3702 | default: |
| 3703 | LOG(FATAL) << "Unexpected rem type " << type; |
| 3704 | } |
| 3705 | } |
| 3706 | |
| 3707 | void InstructionCodeGeneratorARMVIXL::VisitRem(HRem* rem) { |
| 3708 | LocationSummary* locations = rem->GetLocations(); |
| 3709 | Location second = locations->InAt(1); |
| 3710 | |
| 3711 | Primitive::Type type = rem->GetResultType(); |
| 3712 | switch (type) { |
| 3713 | case Primitive::kPrimInt: { |
| 3714 | vixl32::Register reg1 = InputRegisterAt(rem, 0); |
| 3715 | vixl32::Register out_reg = OutputRegister(rem); |
| 3716 | if (second.IsConstant()) { |
| 3717 | GenerateDivRemConstantIntegral(rem); |
| 3718 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 3719 | vixl32::Register reg2 = RegisterFrom(second); |
| 3720 | vixl32::Register temp = RegisterFrom(locations->GetTemp(0)); |
| 3721 | |
| 3722 | // temp = reg1 / reg2 (integer division) |
| 3723 | // dest = reg1 - temp * reg2 |
| 3724 | __ Sdiv(temp, reg1, reg2); |
| 3725 | __ Mls(out_reg, temp, reg2, reg1); |
| 3726 | } else { |
| 3727 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 3728 | DCHECK(reg1.Is(calling_convention.GetRegisterAt(0))); |
| 3729 | DCHECK(RegisterFrom(second).Is(calling_convention.GetRegisterAt(1))); |
| 3730 | DCHECK(out_reg.Is(r1)); |
| 3731 | |
| 3732 | codegen_->InvokeRuntime(kQuickIdivmod, rem, rem->GetDexPc()); |
| 3733 | CheckEntrypointTypes<kQuickIdivmod, int32_t, int32_t, int32_t>(); |
| 3734 | } |
| 3735 | break; |
| 3736 | } |
| 3737 | |
| 3738 | case Primitive::kPrimLong: { |
| 3739 | codegen_->InvokeRuntime(kQuickLmod, rem, rem->GetDexPc()); |
| 3740 | CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>(); |
| 3741 | break; |
| 3742 | } |
| 3743 | |
| 3744 | case Primitive::kPrimFloat: { |
| 3745 | codegen_->InvokeRuntime(kQuickFmodf, rem, rem->GetDexPc()); |
| 3746 | CheckEntrypointTypes<kQuickFmodf, float, float, float>(); |
| 3747 | break; |
| 3748 | } |
| 3749 | |
| 3750 | case Primitive::kPrimDouble: { |
| 3751 | codegen_->InvokeRuntime(kQuickFmod, rem, rem->GetDexPc()); |
| 3752 | CheckEntrypointTypes<kQuickFmod, double, double, double>(); |
| 3753 | break; |
| 3754 | } |
| 3755 | |
| 3756 | default: |
| 3757 | LOG(FATAL) << "Unexpected rem type " << type; |
| 3758 | } |
| 3759 | } |
| 3760 | |
| 3761 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3762 | void LocationsBuilderARMVIXL::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 3763 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3764 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3765 | } |
| 3766 | |
| 3767 | void InstructionCodeGeneratorARMVIXL::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 3768 | DivZeroCheckSlowPathARMVIXL* slow_path = |
| 3769 | new (GetGraph()->GetArena()) DivZeroCheckSlowPathARMVIXL(instruction); |
| 3770 | codegen_->AddSlowPath(slow_path); |
| 3771 | |
| 3772 | LocationSummary* locations = instruction->GetLocations(); |
| 3773 | Location value = locations->InAt(0); |
| 3774 | |
| 3775 | switch (instruction->GetType()) { |
| 3776 | case Primitive::kPrimBoolean: |
| 3777 | case Primitive::kPrimByte: |
| 3778 | case Primitive::kPrimChar: |
| 3779 | case Primitive::kPrimShort: |
| 3780 | case Primitive::kPrimInt: { |
| 3781 | if (value.IsRegister()) { |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 3782 | __ CompareAndBranchIfZero(InputRegisterAt(instruction, 0), slow_path->GetEntryLabel()); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3783 | } else { |
| 3784 | DCHECK(value.IsConstant()) << value; |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 3785 | if (Int32ConstantFrom(value) == 0) { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3786 | __ B(slow_path->GetEntryLabel()); |
| 3787 | } |
| 3788 | } |
| 3789 | break; |
| 3790 | } |
| 3791 | case Primitive::kPrimLong: { |
| 3792 | if (value.IsRegisterPair()) { |
| 3793 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 3794 | vixl32::Register temp = temps.Acquire(); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3795 | __ Orrs(temp, LowRegisterFrom(value), HighRegisterFrom(value)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3796 | __ B(eq, slow_path->GetEntryLabel()); |
| 3797 | } else { |
| 3798 | DCHECK(value.IsConstant()) << value; |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 3799 | if (Int64ConstantFrom(value) == 0) { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3800 | __ B(slow_path->GetEntryLabel()); |
| 3801 | } |
| 3802 | } |
| 3803 | break; |
| 3804 | } |
| 3805 | default: |
| 3806 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
| 3807 | } |
| 3808 | } |
| 3809 | |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 3810 | void InstructionCodeGeneratorARMVIXL::HandleIntegerRotate(HRor* ror) { |
| 3811 | LocationSummary* locations = ror->GetLocations(); |
| 3812 | vixl32::Register in = InputRegisterAt(ror, 0); |
| 3813 | Location rhs = locations->InAt(1); |
| 3814 | vixl32::Register out = OutputRegister(ror); |
| 3815 | |
| 3816 | if (rhs.IsConstant()) { |
| 3817 | // Arm32 and Thumb2 assemblers require a rotation on the interval [1,31], |
| 3818 | // so map all rotations to a +ve. equivalent in that range. |
| 3819 | // (e.g. left *or* right by -2 bits == 30 bits in the same direction.) |
| 3820 | uint32_t rot = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()) & 0x1F; |
| 3821 | if (rot) { |
| 3822 | // Rotate, mapping left rotations to right equivalents if necessary. |
| 3823 | // (e.g. left by 2 bits == right by 30.) |
| 3824 | __ Ror(out, in, rot); |
| 3825 | } else if (!out.Is(in)) { |
| 3826 | __ Mov(out, in); |
| 3827 | } |
| 3828 | } else { |
| 3829 | __ Ror(out, in, RegisterFrom(rhs)); |
| 3830 | } |
| 3831 | } |
| 3832 | |
| 3833 | // Gain some speed by mapping all Long rotates onto equivalent pairs of Integer |
| 3834 | // rotates by swapping input regs (effectively rotating by the first 32-bits of |
| 3835 | // a larger rotation) or flipping direction (thus treating larger right/left |
| 3836 | // rotations as sub-word sized rotations in the other direction) as appropriate. |
| 3837 | void InstructionCodeGeneratorARMVIXL::HandleLongRotate(HRor* ror) { |
| 3838 | LocationSummary* locations = ror->GetLocations(); |
| 3839 | vixl32::Register in_reg_lo = LowRegisterFrom(locations->InAt(0)); |
| 3840 | vixl32::Register in_reg_hi = HighRegisterFrom(locations->InAt(0)); |
| 3841 | Location rhs = locations->InAt(1); |
| 3842 | vixl32::Register out_reg_lo = LowRegisterFrom(locations->Out()); |
| 3843 | vixl32::Register out_reg_hi = HighRegisterFrom(locations->Out()); |
| 3844 | |
| 3845 | if (rhs.IsConstant()) { |
| 3846 | uint64_t rot = CodeGenerator::GetInt64ValueOf(rhs.GetConstant()); |
| 3847 | // Map all rotations to +ve. equivalents on the interval [0,63]. |
| 3848 | rot &= kMaxLongShiftDistance; |
| 3849 | // For rotates over a word in size, 'pre-rotate' by 32-bits to keep rotate |
| 3850 | // logic below to a simple pair of binary orr. |
| 3851 | // (e.g. 34 bits == in_reg swap + 2 bits right.) |
| 3852 | if (rot >= kArmBitsPerWord) { |
| 3853 | rot -= kArmBitsPerWord; |
| 3854 | std::swap(in_reg_hi, in_reg_lo); |
| 3855 | } |
| 3856 | // Rotate, or mov to out for zero or word size rotations. |
| 3857 | if (rot != 0u) { |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 3858 | __ Lsr(out_reg_hi, in_reg_hi, Operand::From(rot)); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 3859 | __ 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] | 3860 | __ Lsr(out_reg_lo, in_reg_lo, Operand::From(rot)); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 3861 | __ Orr(out_reg_lo, out_reg_lo, Operand(in_reg_hi, ShiftType::LSL, kArmBitsPerWord - rot)); |
| 3862 | } else { |
| 3863 | __ Mov(out_reg_lo, in_reg_lo); |
| 3864 | __ Mov(out_reg_hi, in_reg_hi); |
| 3865 | } |
| 3866 | } else { |
| 3867 | vixl32::Register shift_right = RegisterFrom(locations->GetTemp(0)); |
| 3868 | vixl32::Register shift_left = RegisterFrom(locations->GetTemp(1)); |
| 3869 | vixl32::Label end; |
| 3870 | vixl32::Label shift_by_32_plus_shift_right; |
| 3871 | |
| 3872 | __ And(shift_right, RegisterFrom(rhs), 0x1F); |
| 3873 | __ Lsrs(shift_left, RegisterFrom(rhs), 6); |
Scott Wakeling | bffdc70 | 2016-12-07 17:46:03 +0000 | [diff] [blame] | 3874 | __ Rsb(LeaveFlags, shift_left, shift_right, Operand::From(kArmBitsPerWord)); |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 3875 | __ B(cc, &shift_by_32_plus_shift_right, /* far_target */ false); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 3876 | |
| 3877 | // out_reg_hi = (reg_hi << shift_left) | (reg_lo >> shift_right). |
| 3878 | // out_reg_lo = (reg_lo << shift_left) | (reg_hi >> shift_right). |
| 3879 | __ Lsl(out_reg_hi, in_reg_hi, shift_left); |
| 3880 | __ Lsr(out_reg_lo, in_reg_lo, shift_right); |
| 3881 | __ Add(out_reg_hi, out_reg_hi, out_reg_lo); |
| 3882 | __ Lsl(out_reg_lo, in_reg_lo, shift_left); |
| 3883 | __ Lsr(shift_left, in_reg_hi, shift_right); |
| 3884 | __ Add(out_reg_lo, out_reg_lo, shift_left); |
| 3885 | __ B(&end); |
| 3886 | |
| 3887 | __ Bind(&shift_by_32_plus_shift_right); // Shift by 32+shift_right. |
| 3888 | // out_reg_hi = (reg_hi >> shift_right) | (reg_lo << shift_left). |
| 3889 | // out_reg_lo = (reg_lo >> shift_right) | (reg_hi << shift_left). |
| 3890 | __ Lsr(out_reg_hi, in_reg_hi, shift_right); |
| 3891 | __ Lsl(out_reg_lo, in_reg_lo, shift_left); |
| 3892 | __ Add(out_reg_hi, out_reg_hi, out_reg_lo); |
| 3893 | __ Lsr(out_reg_lo, in_reg_lo, shift_right); |
| 3894 | __ Lsl(shift_right, in_reg_hi, shift_left); |
| 3895 | __ Add(out_reg_lo, out_reg_lo, shift_right); |
| 3896 | |
| 3897 | __ Bind(&end); |
| 3898 | } |
| 3899 | } |
| 3900 | |
| 3901 | void LocationsBuilderARMVIXL::VisitRor(HRor* ror) { |
| 3902 | LocationSummary* locations = |
| 3903 | new (GetGraph()->GetArena()) LocationSummary(ror, LocationSummary::kNoCall); |
| 3904 | switch (ror->GetResultType()) { |
| 3905 | case Primitive::kPrimInt: { |
| 3906 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3907 | locations->SetInAt(1, Location::RegisterOrConstant(ror->InputAt(1))); |
| 3908 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3909 | break; |
| 3910 | } |
| 3911 | case Primitive::kPrimLong: { |
| 3912 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3913 | if (ror->InputAt(1)->IsConstant()) { |
| 3914 | locations->SetInAt(1, Location::ConstantLocation(ror->InputAt(1)->AsConstant())); |
| 3915 | } else { |
| 3916 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3917 | locations->AddTemp(Location::RequiresRegister()); |
| 3918 | locations->AddTemp(Location::RequiresRegister()); |
| 3919 | } |
| 3920 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 3921 | break; |
| 3922 | } |
| 3923 | default: |
| 3924 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 3925 | } |
| 3926 | } |
| 3927 | |
| 3928 | void InstructionCodeGeneratorARMVIXL::VisitRor(HRor* ror) { |
| 3929 | Primitive::Type type = ror->GetResultType(); |
| 3930 | switch (type) { |
| 3931 | case Primitive::kPrimInt: { |
| 3932 | HandleIntegerRotate(ror); |
| 3933 | break; |
| 3934 | } |
| 3935 | case Primitive::kPrimLong: { |
| 3936 | HandleLongRotate(ror); |
| 3937 | break; |
| 3938 | } |
| 3939 | default: |
| 3940 | LOG(FATAL) << "Unexpected operation type " << type; |
| 3941 | UNREACHABLE(); |
| 3942 | } |
| 3943 | } |
| 3944 | |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 3945 | void LocationsBuilderARMVIXL::HandleShift(HBinaryOperation* op) { |
| 3946 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3947 | |
| 3948 | LocationSummary* locations = |
| 3949 | new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall); |
| 3950 | |
| 3951 | switch (op->GetResultType()) { |
| 3952 | case Primitive::kPrimInt: { |
| 3953 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3954 | if (op->InputAt(1)->IsConstant()) { |
| 3955 | locations->SetInAt(1, Location::ConstantLocation(op->InputAt(1)->AsConstant())); |
| 3956 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3957 | } else { |
| 3958 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3959 | // Make the output overlap, as it will be used to hold the masked |
| 3960 | // second input. |
| 3961 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 3962 | } |
| 3963 | break; |
| 3964 | } |
| 3965 | case Primitive::kPrimLong: { |
| 3966 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3967 | if (op->InputAt(1)->IsConstant()) { |
| 3968 | locations->SetInAt(1, Location::ConstantLocation(op->InputAt(1)->AsConstant())); |
| 3969 | // For simplicity, use kOutputOverlap even though we only require that low registers |
| 3970 | // don't clash with high registers which the register allocator currently guarantees. |
| 3971 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 3972 | } else { |
| 3973 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3974 | locations->AddTemp(Location::RequiresRegister()); |
| 3975 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 3976 | } |
| 3977 | break; |
| 3978 | } |
| 3979 | default: |
| 3980 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
| 3981 | } |
| 3982 | } |
| 3983 | |
| 3984 | void InstructionCodeGeneratorARMVIXL::HandleShift(HBinaryOperation* op) { |
| 3985 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3986 | |
| 3987 | LocationSummary* locations = op->GetLocations(); |
| 3988 | Location out = locations->Out(); |
| 3989 | Location first = locations->InAt(0); |
| 3990 | Location second = locations->InAt(1); |
| 3991 | |
| 3992 | Primitive::Type type = op->GetResultType(); |
| 3993 | switch (type) { |
| 3994 | case Primitive::kPrimInt: { |
| 3995 | vixl32::Register out_reg = OutputRegister(op); |
| 3996 | vixl32::Register first_reg = InputRegisterAt(op, 0); |
| 3997 | if (second.IsRegister()) { |
| 3998 | vixl32::Register second_reg = RegisterFrom(second); |
| 3999 | // ARM doesn't mask the shift count so we need to do it ourselves. |
| 4000 | __ And(out_reg, second_reg, kMaxIntShiftDistance); |
| 4001 | if (op->IsShl()) { |
| 4002 | __ Lsl(out_reg, first_reg, out_reg); |
| 4003 | } else if (op->IsShr()) { |
| 4004 | __ Asr(out_reg, first_reg, out_reg); |
| 4005 | } else { |
| 4006 | __ Lsr(out_reg, first_reg, out_reg); |
| 4007 | } |
| 4008 | } else { |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 4009 | int32_t cst = Int32ConstantFrom(second); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4010 | uint32_t shift_value = cst & kMaxIntShiftDistance; |
| 4011 | if (shift_value == 0) { // ARM does not support shifting with 0 immediate. |
| 4012 | __ Mov(out_reg, first_reg); |
| 4013 | } else if (op->IsShl()) { |
| 4014 | __ Lsl(out_reg, first_reg, shift_value); |
| 4015 | } else if (op->IsShr()) { |
| 4016 | __ Asr(out_reg, first_reg, shift_value); |
| 4017 | } else { |
| 4018 | __ Lsr(out_reg, first_reg, shift_value); |
| 4019 | } |
| 4020 | } |
| 4021 | break; |
| 4022 | } |
| 4023 | case Primitive::kPrimLong: { |
| 4024 | vixl32::Register o_h = HighRegisterFrom(out); |
| 4025 | vixl32::Register o_l = LowRegisterFrom(out); |
| 4026 | |
| 4027 | vixl32::Register high = HighRegisterFrom(first); |
| 4028 | vixl32::Register low = LowRegisterFrom(first); |
| 4029 | |
| 4030 | if (second.IsRegister()) { |
| 4031 | vixl32::Register temp = RegisterFrom(locations->GetTemp(0)); |
| 4032 | |
| 4033 | vixl32::Register second_reg = RegisterFrom(second); |
| 4034 | |
| 4035 | if (op->IsShl()) { |
| 4036 | __ And(o_l, second_reg, kMaxLongShiftDistance); |
| 4037 | // Shift the high part |
| 4038 | __ Lsl(o_h, high, o_l); |
| 4039 | // Shift the low part and `or` what overflew on the high part |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 4040 | __ Rsb(temp, o_l, Operand::From(kArmBitsPerWord)); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4041 | __ Lsr(temp, low, temp); |
| 4042 | __ Orr(o_h, o_h, temp); |
| 4043 | // If the shift is > 32 bits, override the high part |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 4044 | __ Subs(temp, o_l, Operand::From(kArmBitsPerWord)); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4045 | { |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 4046 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 4047 | 2 * vixl32::kMaxInstructionSizeInBytes, |
| 4048 | CodeBufferCheckScope::kMaximumSize); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4049 | __ it(pl); |
| 4050 | __ lsl(pl, o_h, low, temp); |
| 4051 | } |
| 4052 | // Shift the low part |
| 4053 | __ Lsl(o_l, low, o_l); |
| 4054 | } else if (op->IsShr()) { |
| 4055 | __ And(o_h, second_reg, kMaxLongShiftDistance); |
| 4056 | // Shift the low part |
| 4057 | __ Lsr(o_l, low, o_h); |
| 4058 | // Shift the high part and `or` what underflew on the low part |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 4059 | __ Rsb(temp, o_h, Operand::From(kArmBitsPerWord)); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4060 | __ Lsl(temp, high, temp); |
| 4061 | __ Orr(o_l, o_l, temp); |
| 4062 | // If the shift is > 32 bits, override the low part |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 4063 | __ Subs(temp, o_h, Operand::From(kArmBitsPerWord)); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4064 | { |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 4065 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 4066 | 2 * vixl32::kMaxInstructionSizeInBytes, |
| 4067 | CodeBufferCheckScope::kMaximumSize); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4068 | __ it(pl); |
| 4069 | __ asr(pl, o_l, high, temp); |
| 4070 | } |
| 4071 | // Shift the high part |
| 4072 | __ Asr(o_h, high, o_h); |
| 4073 | } else { |
| 4074 | __ And(o_h, second_reg, kMaxLongShiftDistance); |
| 4075 | // same as Shr except we use `Lsr`s and not `Asr`s |
| 4076 | __ Lsr(o_l, low, o_h); |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 4077 | __ Rsb(temp, o_h, Operand::From(kArmBitsPerWord)); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4078 | __ Lsl(temp, high, temp); |
| 4079 | __ Orr(o_l, o_l, temp); |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 4080 | __ Subs(temp, o_h, Operand::From(kArmBitsPerWord)); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4081 | { |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 4082 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 4083 | 2 * vixl32::kMaxInstructionSizeInBytes, |
| 4084 | CodeBufferCheckScope::kMaximumSize); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4085 | __ it(pl); |
| 4086 | __ lsr(pl, o_l, high, temp); |
| 4087 | } |
| 4088 | __ Lsr(o_h, high, o_h); |
| 4089 | } |
| 4090 | } else { |
| 4091 | // Register allocator doesn't create partial overlap. |
| 4092 | DCHECK(!o_l.Is(high)); |
| 4093 | DCHECK(!o_h.Is(low)); |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 4094 | int32_t cst = Int32ConstantFrom(second); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4095 | uint32_t shift_value = cst & kMaxLongShiftDistance; |
| 4096 | if (shift_value > 32) { |
| 4097 | if (op->IsShl()) { |
| 4098 | __ Lsl(o_h, low, shift_value - 32); |
| 4099 | __ Mov(o_l, 0); |
| 4100 | } else if (op->IsShr()) { |
| 4101 | __ Asr(o_l, high, shift_value - 32); |
| 4102 | __ Asr(o_h, high, 31); |
| 4103 | } else { |
| 4104 | __ Lsr(o_l, high, shift_value - 32); |
| 4105 | __ Mov(o_h, 0); |
| 4106 | } |
| 4107 | } else if (shift_value == 32) { |
| 4108 | if (op->IsShl()) { |
| 4109 | __ Mov(o_h, low); |
| 4110 | __ Mov(o_l, 0); |
| 4111 | } else if (op->IsShr()) { |
| 4112 | __ Mov(o_l, high); |
| 4113 | __ Asr(o_h, high, 31); |
| 4114 | } else { |
| 4115 | __ Mov(o_l, high); |
| 4116 | __ Mov(o_h, 0); |
| 4117 | } |
| 4118 | } else if (shift_value == 1) { |
| 4119 | if (op->IsShl()) { |
| 4120 | __ Lsls(o_l, low, 1); |
| 4121 | __ Adc(o_h, high, high); |
| 4122 | } else if (op->IsShr()) { |
| 4123 | __ Asrs(o_h, high, 1); |
| 4124 | __ Rrx(o_l, low); |
| 4125 | } else { |
| 4126 | __ Lsrs(o_h, high, 1); |
| 4127 | __ Rrx(o_l, low); |
| 4128 | } |
| 4129 | } else { |
| 4130 | DCHECK(2 <= shift_value && shift_value < 32) << shift_value; |
| 4131 | if (op->IsShl()) { |
| 4132 | __ Lsl(o_h, high, shift_value); |
| 4133 | __ Orr(o_h, o_h, Operand(low, ShiftType::LSR, 32 - shift_value)); |
| 4134 | __ Lsl(o_l, low, shift_value); |
| 4135 | } else if (op->IsShr()) { |
| 4136 | __ Lsr(o_l, low, shift_value); |
| 4137 | __ Orr(o_l, o_l, Operand(high, ShiftType::LSL, 32 - shift_value)); |
| 4138 | __ Asr(o_h, high, shift_value); |
| 4139 | } else { |
| 4140 | __ Lsr(o_l, low, shift_value); |
| 4141 | __ Orr(o_l, o_l, Operand(high, ShiftType::LSL, 32 - shift_value)); |
| 4142 | __ Lsr(o_h, high, shift_value); |
| 4143 | } |
| 4144 | } |
| 4145 | } |
| 4146 | break; |
| 4147 | } |
| 4148 | default: |
| 4149 | LOG(FATAL) << "Unexpected operation type " << type; |
| 4150 | UNREACHABLE(); |
| 4151 | } |
| 4152 | } |
| 4153 | |
| 4154 | void LocationsBuilderARMVIXL::VisitShl(HShl* shl) { |
| 4155 | HandleShift(shl); |
| 4156 | } |
| 4157 | |
| 4158 | void InstructionCodeGeneratorARMVIXL::VisitShl(HShl* shl) { |
| 4159 | HandleShift(shl); |
| 4160 | } |
| 4161 | |
| 4162 | void LocationsBuilderARMVIXL::VisitShr(HShr* shr) { |
| 4163 | HandleShift(shr); |
| 4164 | } |
| 4165 | |
| 4166 | void InstructionCodeGeneratorARMVIXL::VisitShr(HShr* shr) { |
| 4167 | HandleShift(shr); |
| 4168 | } |
| 4169 | |
| 4170 | void LocationsBuilderARMVIXL::VisitUShr(HUShr* ushr) { |
| 4171 | HandleShift(ushr); |
| 4172 | } |
| 4173 | |
| 4174 | void InstructionCodeGeneratorARMVIXL::VisitUShr(HUShr* ushr) { |
| 4175 | HandleShift(ushr); |
| 4176 | } |
| 4177 | |
| 4178 | void LocationsBuilderARMVIXL::VisitNewInstance(HNewInstance* instruction) { |
| 4179 | LocationSummary* locations = |
| 4180 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
| 4181 | if (instruction->IsStringAlloc()) { |
| 4182 | locations->AddTemp(LocationFrom(kMethodRegister)); |
| 4183 | } else { |
| 4184 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4185 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4186 | } |
| 4187 | locations->SetOut(LocationFrom(r0)); |
| 4188 | } |
| 4189 | |
| 4190 | void InstructionCodeGeneratorARMVIXL::VisitNewInstance(HNewInstance* instruction) { |
| 4191 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 4192 | // of poisoning the reference. |
| 4193 | if (instruction->IsStringAlloc()) { |
| 4194 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 4195 | vixl32::Register temp = RegisterFrom(instruction->GetLocations()->GetTemp(0)); |
| 4196 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize); |
| 4197 | GetAssembler()->LoadFromOffset(kLoadWord, temp, tr, QUICK_ENTRY_POINT(pNewEmptyString)); |
| 4198 | GetAssembler()->LoadFromOffset(kLoadWord, lr, temp, code_offset.Int32Value()); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 4199 | // 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] | 4200 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 4201 | vixl32::k16BitT32InstructionSizeInBytes, |
| 4202 | CodeBufferCheckScope::kExactSize); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4203 | __ blx(lr); |
| 4204 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 4205 | } else { |
| 4206 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
Nicolas Geoffray | 0d3998b | 2017-01-12 15:35:12 +0000 | [diff] [blame] | 4207 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4208 | } |
| 4209 | } |
| 4210 | |
| 4211 | void LocationsBuilderARMVIXL::VisitNewArray(HNewArray* instruction) { |
| 4212 | LocationSummary* locations = |
| 4213 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
| 4214 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4215 | locations->SetOut(LocationFrom(r0)); |
Nicolas Geoffray | 8c7c4f1 | 2017-01-26 10:13:11 +0000 | [diff] [blame] | 4216 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 4217 | locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(1))); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4218 | } |
| 4219 | |
| 4220 | void InstructionCodeGeneratorARMVIXL::VisitNewArray(HNewArray* instruction) { |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4221 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 4222 | // of poisoning the reference. |
Artem Serov | 7b3672e | 2017-02-03 17:30:34 +0000 | [diff] [blame] | 4223 | QuickEntrypointEnum entrypoint = |
| 4224 | CodeGenerator::GetArrayAllocationEntrypoint(instruction->GetLoadClass()->GetClass()); |
| 4225 | codegen_->InvokeRuntime(entrypoint, instruction, instruction->GetDexPc()); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4226 | CheckEntrypointTypes<kQuickAllocArrayResolved, void*, mirror::Class*, int32_t>(); |
Artem Serov | 7b3672e | 2017-02-03 17:30:34 +0000 | [diff] [blame] | 4227 | DCHECK(!codegen_->IsLeafMethod()); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4228 | } |
| 4229 | |
| 4230 | void LocationsBuilderARMVIXL::VisitParameterValue(HParameterValue* instruction) { |
| 4231 | LocationSummary* locations = |
| 4232 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4233 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 4234 | if (location.IsStackSlot()) { |
| 4235 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 4236 | } else if (location.IsDoubleStackSlot()) { |
| 4237 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 4238 | } |
| 4239 | locations->SetOut(location); |
| 4240 | } |
| 4241 | |
| 4242 | void InstructionCodeGeneratorARMVIXL::VisitParameterValue( |
| 4243 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
| 4244 | // Nothing to do, the parameter is already at its location. |
| 4245 | } |
| 4246 | |
| 4247 | void LocationsBuilderARMVIXL::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 4248 | LocationSummary* locations = |
| 4249 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4250 | locations->SetOut(LocationFrom(kMethodRegister)); |
| 4251 | } |
| 4252 | |
| 4253 | void InstructionCodeGeneratorARMVIXL::VisitCurrentMethod( |
| 4254 | HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
| 4255 | // Nothing to do, the method is already at its location. |
| 4256 | } |
| 4257 | |
| 4258 | void LocationsBuilderARMVIXL::VisitNot(HNot* not_) { |
| 4259 | LocationSummary* locations = |
| 4260 | new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall); |
| 4261 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4262 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4263 | } |
| 4264 | |
| 4265 | void InstructionCodeGeneratorARMVIXL::VisitNot(HNot* not_) { |
| 4266 | LocationSummary* locations = not_->GetLocations(); |
| 4267 | Location out = locations->Out(); |
| 4268 | Location in = locations->InAt(0); |
| 4269 | switch (not_->GetResultType()) { |
| 4270 | case Primitive::kPrimInt: |
| 4271 | __ Mvn(OutputRegister(not_), InputRegisterAt(not_, 0)); |
| 4272 | break; |
| 4273 | |
| 4274 | case Primitive::kPrimLong: |
| 4275 | __ Mvn(LowRegisterFrom(out), LowRegisterFrom(in)); |
| 4276 | __ Mvn(HighRegisterFrom(out), HighRegisterFrom(in)); |
| 4277 | break; |
| 4278 | |
| 4279 | default: |
| 4280 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 4281 | } |
| 4282 | } |
| 4283 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 4284 | void LocationsBuilderARMVIXL::VisitBooleanNot(HBooleanNot* bool_not) { |
| 4285 | LocationSummary* locations = |
| 4286 | new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall); |
| 4287 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4288 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4289 | } |
| 4290 | |
| 4291 | void InstructionCodeGeneratorARMVIXL::VisitBooleanNot(HBooleanNot* bool_not) { |
| 4292 | __ Eor(OutputRegister(bool_not), InputRegister(bool_not), 1); |
| 4293 | } |
| 4294 | |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4295 | void LocationsBuilderARMVIXL::VisitCompare(HCompare* compare) { |
| 4296 | LocationSummary* locations = |
| 4297 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
| 4298 | switch (compare->InputAt(0)->GetType()) { |
| 4299 | case Primitive::kPrimBoolean: |
| 4300 | case Primitive::kPrimByte: |
| 4301 | case Primitive::kPrimShort: |
| 4302 | case Primitive::kPrimChar: |
| 4303 | case Primitive::kPrimInt: |
| 4304 | case Primitive::kPrimLong: { |
| 4305 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4306 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4307 | // Output overlaps because it is written before doing the low comparison. |
| 4308 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 4309 | break; |
| 4310 | } |
| 4311 | case Primitive::kPrimFloat: |
| 4312 | case Primitive::kPrimDouble: { |
| 4313 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4314 | locations->SetInAt(1, ArithmeticZeroOrFpuRegister(compare->InputAt(1))); |
| 4315 | locations->SetOut(Location::RequiresRegister()); |
| 4316 | break; |
| 4317 | } |
| 4318 | default: |
| 4319 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 4320 | } |
| 4321 | } |
| 4322 | |
| 4323 | void InstructionCodeGeneratorARMVIXL::VisitCompare(HCompare* compare) { |
| 4324 | LocationSummary* locations = compare->GetLocations(); |
| 4325 | vixl32::Register out = OutputRegister(compare); |
| 4326 | Location left = locations->InAt(0); |
| 4327 | Location right = locations->InAt(1); |
| 4328 | |
| 4329 | vixl32::Label less, greater, done; |
| 4330 | Primitive::Type type = compare->InputAt(0)->GetType(); |
| 4331 | vixl32::Condition less_cond = vixl32::Condition(kNone); |
| 4332 | switch (type) { |
| 4333 | case Primitive::kPrimBoolean: |
| 4334 | case Primitive::kPrimByte: |
| 4335 | case Primitive::kPrimShort: |
| 4336 | case Primitive::kPrimChar: |
| 4337 | case Primitive::kPrimInt: { |
| 4338 | // Emit move to `out` before the `Cmp`, as `Mov` might affect the status flags. |
| 4339 | __ Mov(out, 0); |
| 4340 | __ Cmp(RegisterFrom(left), RegisterFrom(right)); // Signed compare. |
| 4341 | less_cond = lt; |
| 4342 | break; |
| 4343 | } |
| 4344 | case Primitive::kPrimLong: { |
| 4345 | __ Cmp(HighRegisterFrom(left), HighRegisterFrom(right)); // Signed compare. |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 4346 | __ B(lt, &less, /* far_target */ false); |
| 4347 | __ B(gt, &greater, /* far_target */ false); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4348 | // Emit move to `out` before the last `Cmp`, as `Mov` might affect the status flags. |
| 4349 | __ Mov(out, 0); |
| 4350 | __ Cmp(LowRegisterFrom(left), LowRegisterFrom(right)); // Unsigned compare. |
| 4351 | less_cond = lo; |
| 4352 | break; |
| 4353 | } |
| 4354 | case Primitive::kPrimFloat: |
| 4355 | case Primitive::kPrimDouble: { |
| 4356 | __ Mov(out, 0); |
| 4357 | GenerateVcmp(compare); |
| 4358 | // To branch on the FP compare result we transfer FPSCR to APSR (encoded as PC in VMRS). |
| 4359 | __ Vmrs(RegisterOrAPSR_nzcv(kPcCode), FPSCR); |
| 4360 | less_cond = ARMFPCondition(kCondLT, compare->IsGtBias()); |
| 4361 | break; |
| 4362 | } |
| 4363 | default: |
| 4364 | LOG(FATAL) << "Unexpected compare type " << type; |
| 4365 | UNREACHABLE(); |
| 4366 | } |
| 4367 | |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 4368 | __ B(eq, &done, /* far_target */ false); |
| 4369 | __ B(less_cond, &less, /* far_target */ false); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4370 | |
| 4371 | __ Bind(&greater); |
| 4372 | __ Mov(out, 1); |
| 4373 | __ B(&done); |
| 4374 | |
| 4375 | __ Bind(&less); |
| 4376 | __ Mov(out, -1); |
| 4377 | |
| 4378 | __ Bind(&done); |
| 4379 | } |
| 4380 | |
| 4381 | void LocationsBuilderARMVIXL::VisitPhi(HPhi* instruction) { |
| 4382 | LocationSummary* locations = |
| 4383 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4384 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
| 4385 | locations->SetInAt(i, Location::Any()); |
| 4386 | } |
| 4387 | locations->SetOut(Location::Any()); |
| 4388 | } |
| 4389 | |
| 4390 | void InstructionCodeGeneratorARMVIXL::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
| 4391 | LOG(FATAL) << "Unreachable"; |
| 4392 | } |
| 4393 | |
| 4394 | void CodeGeneratorARMVIXL::GenerateMemoryBarrier(MemBarrierKind kind) { |
| 4395 | // TODO (ported from quick): revisit ARM barrier kinds. |
| 4396 | DmbOptions flavor = DmbOptions::ISH; // Quiet C++ warnings. |
| 4397 | switch (kind) { |
| 4398 | case MemBarrierKind::kAnyStore: |
| 4399 | case MemBarrierKind::kLoadAny: |
| 4400 | case MemBarrierKind::kAnyAny: { |
| 4401 | flavor = DmbOptions::ISH; |
| 4402 | break; |
| 4403 | } |
| 4404 | case MemBarrierKind::kStoreStore: { |
| 4405 | flavor = DmbOptions::ISHST; |
| 4406 | break; |
| 4407 | } |
| 4408 | default: |
| 4409 | LOG(FATAL) << "Unexpected memory barrier " << kind; |
| 4410 | } |
| 4411 | __ Dmb(flavor); |
| 4412 | } |
| 4413 | |
| 4414 | void InstructionCodeGeneratorARMVIXL::GenerateWideAtomicLoad(vixl32::Register addr, |
| 4415 | uint32_t offset, |
| 4416 | vixl32::Register out_lo, |
| 4417 | vixl32::Register out_hi) { |
| 4418 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 4419 | if (offset != 0) { |
| 4420 | vixl32::Register temp = temps.Acquire(); |
| 4421 | __ Add(temp, addr, offset); |
| 4422 | addr = temp; |
| 4423 | } |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 4424 | __ Ldrexd(out_lo, out_hi, MemOperand(addr)); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4425 | } |
| 4426 | |
| 4427 | void InstructionCodeGeneratorARMVIXL::GenerateWideAtomicStore(vixl32::Register addr, |
| 4428 | uint32_t offset, |
| 4429 | vixl32::Register value_lo, |
| 4430 | vixl32::Register value_hi, |
| 4431 | vixl32::Register temp1, |
| 4432 | vixl32::Register temp2, |
| 4433 | HInstruction* instruction) { |
| 4434 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 4435 | vixl32::Label fail; |
| 4436 | if (offset != 0) { |
| 4437 | vixl32::Register temp = temps.Acquire(); |
| 4438 | __ Add(temp, addr, offset); |
| 4439 | addr = temp; |
| 4440 | } |
| 4441 | __ Bind(&fail); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 4442 | { |
| 4443 | // Ensure the pc position is recorded immediately after the `ldrexd` instruction. |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 4444 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 4445 | vixl32::kMaxInstructionSizeInBytes, |
| 4446 | CodeBufferCheckScope::kMaximumSize); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 4447 | // We need a load followed by store. (The address used in a STREX instruction must |
| 4448 | // be the same as the address in the most recently executed LDREX instruction.) |
| 4449 | __ ldrexd(temp1, temp2, MemOperand(addr)); |
| 4450 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4451 | } |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 4452 | __ Strexd(temp1, value_lo, value_hi, MemOperand(addr)); |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 4453 | __ CompareAndBranchIfNonZero(temp1, &fail); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4454 | } |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 4455 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4456 | void LocationsBuilderARMVIXL::HandleFieldSet( |
| 4457 | HInstruction* instruction, const FieldInfo& field_info) { |
| 4458 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4459 | |
| 4460 | LocationSummary* locations = |
| 4461 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4462 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4463 | |
| 4464 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4465 | if (Primitive::IsFloatingPointType(field_type)) { |
| 4466 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4467 | } else { |
| 4468 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4469 | } |
| 4470 | |
| 4471 | bool is_wide = field_type == Primitive::kPrimLong || field_type == Primitive::kPrimDouble; |
| 4472 | bool generate_volatile = field_info.IsVolatile() |
| 4473 | && is_wide |
| 4474 | && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
| 4475 | bool needs_write_barrier = |
| 4476 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
| 4477 | // Temporary registers for the write barrier. |
| 4478 | // TODO: consider renaming StoreNeedsWriteBarrier to StoreNeedsGCMark. |
| 4479 | if (needs_write_barrier) { |
| 4480 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for reference poisoning too. |
| 4481 | locations->AddTemp(Location::RequiresRegister()); |
| 4482 | } else if (generate_volatile) { |
| 4483 | // ARM encoding have some additional constraints for ldrexd/strexd: |
| 4484 | // - registers need to be consecutive |
| 4485 | // - the first register should be even but not R14. |
| 4486 | // We don't test for ARM yet, and the assertion makes sure that we |
| 4487 | // revisit this if we ever enable ARM encoding. |
| 4488 | DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet()); |
| 4489 | |
| 4490 | locations->AddTemp(Location::RequiresRegister()); |
| 4491 | locations->AddTemp(Location::RequiresRegister()); |
| 4492 | if (field_type == Primitive::kPrimDouble) { |
| 4493 | // For doubles we need two more registers to copy the value. |
| 4494 | locations->AddTemp(LocationFrom(r2)); |
| 4495 | locations->AddTemp(LocationFrom(r3)); |
| 4496 | } |
| 4497 | } |
| 4498 | } |
| 4499 | |
| 4500 | void InstructionCodeGeneratorARMVIXL::HandleFieldSet(HInstruction* instruction, |
| 4501 | const FieldInfo& field_info, |
| 4502 | bool value_can_be_null) { |
| 4503 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4504 | |
| 4505 | LocationSummary* locations = instruction->GetLocations(); |
| 4506 | vixl32::Register base = InputRegisterAt(instruction, 0); |
| 4507 | Location value = locations->InAt(1); |
| 4508 | |
| 4509 | bool is_volatile = field_info.IsVolatile(); |
| 4510 | bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
| 4511 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4512 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 4513 | bool needs_write_barrier = |
| 4514 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
| 4515 | |
| 4516 | if (is_volatile) { |
| 4517 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
| 4518 | } |
| 4519 | |
| 4520 | switch (field_type) { |
| 4521 | case Primitive::kPrimBoolean: |
| 4522 | case Primitive::kPrimByte: { |
| 4523 | GetAssembler()->StoreToOffset(kStoreByte, RegisterFrom(value), base, offset); |
| 4524 | break; |
| 4525 | } |
| 4526 | |
| 4527 | case Primitive::kPrimShort: |
| 4528 | case Primitive::kPrimChar: { |
| 4529 | GetAssembler()->StoreToOffset(kStoreHalfword, RegisterFrom(value), base, offset); |
| 4530 | break; |
| 4531 | } |
| 4532 | |
| 4533 | case Primitive::kPrimInt: |
| 4534 | case Primitive::kPrimNot: { |
| 4535 | if (kPoisonHeapReferences && needs_write_barrier) { |
| 4536 | // Note that in the case where `value` is a null reference, |
| 4537 | // we do not enter this block, as a null reference does not |
| 4538 | // need poisoning. |
| 4539 | DCHECK_EQ(field_type, Primitive::kPrimNot); |
| 4540 | vixl32::Register temp = RegisterFrom(locations->GetTemp(0)); |
| 4541 | __ Mov(temp, RegisterFrom(value)); |
| 4542 | GetAssembler()->PoisonHeapReference(temp); |
| 4543 | GetAssembler()->StoreToOffset(kStoreWord, temp, base, offset); |
| 4544 | } else { |
| 4545 | GetAssembler()->StoreToOffset(kStoreWord, RegisterFrom(value), base, offset); |
| 4546 | } |
| 4547 | break; |
| 4548 | } |
| 4549 | |
| 4550 | case Primitive::kPrimLong: { |
| 4551 | if (is_volatile && !atomic_ldrd_strd) { |
| 4552 | GenerateWideAtomicStore(base, |
| 4553 | offset, |
| 4554 | LowRegisterFrom(value), |
| 4555 | HighRegisterFrom(value), |
| 4556 | RegisterFrom(locations->GetTemp(0)), |
| 4557 | RegisterFrom(locations->GetTemp(1)), |
| 4558 | instruction); |
| 4559 | } else { |
| 4560 | GetAssembler()->StoreToOffset(kStoreWordPair, LowRegisterFrom(value), base, offset); |
| 4561 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4562 | } |
| 4563 | break; |
| 4564 | } |
| 4565 | |
| 4566 | case Primitive::kPrimFloat: { |
| 4567 | GetAssembler()->StoreSToOffset(SRegisterFrom(value), base, offset); |
| 4568 | break; |
| 4569 | } |
| 4570 | |
| 4571 | case Primitive::kPrimDouble: { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 4572 | vixl32::DRegister value_reg = DRegisterFrom(value); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4573 | if (is_volatile && !atomic_ldrd_strd) { |
| 4574 | vixl32::Register value_reg_lo = RegisterFrom(locations->GetTemp(0)); |
| 4575 | vixl32::Register value_reg_hi = RegisterFrom(locations->GetTemp(1)); |
| 4576 | |
| 4577 | __ Vmov(value_reg_lo, value_reg_hi, value_reg); |
| 4578 | |
| 4579 | GenerateWideAtomicStore(base, |
| 4580 | offset, |
| 4581 | value_reg_lo, |
| 4582 | value_reg_hi, |
| 4583 | RegisterFrom(locations->GetTemp(2)), |
| 4584 | RegisterFrom(locations->GetTemp(3)), |
| 4585 | instruction); |
| 4586 | } else { |
| 4587 | GetAssembler()->StoreDToOffset(value_reg, base, offset); |
| 4588 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4589 | } |
| 4590 | break; |
| 4591 | } |
| 4592 | |
| 4593 | case Primitive::kPrimVoid: |
| 4594 | LOG(FATAL) << "Unreachable type " << field_type; |
| 4595 | UNREACHABLE(); |
| 4596 | } |
| 4597 | |
| 4598 | // Longs and doubles are handled in the switch. |
| 4599 | if (field_type != Primitive::kPrimLong && field_type != Primitive::kPrimDouble) { |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 4600 | // TODO(VIXL): Here and for other calls to `MaybeRecordImplicitNullCheck` in this method, we |
| 4601 | // should use a scope and the assembler to emit the store instruction to guarantee that we |
| 4602 | // record the pc at the correct position. But the `Assembler` does not automatically handle |
| 4603 | // unencodable offsets. Practically, everything is fine because the helper and VIXL, at the time |
| 4604 | // of writing, do generate the store instruction last. |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4605 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4606 | } |
| 4607 | |
| 4608 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 4609 | vixl32::Register temp = RegisterFrom(locations->GetTemp(0)); |
| 4610 | vixl32::Register card = RegisterFrom(locations->GetTemp(1)); |
| 4611 | codegen_->MarkGCCard(temp, card, base, RegisterFrom(value), value_can_be_null); |
| 4612 | } |
| 4613 | |
| 4614 | if (is_volatile) { |
| 4615 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
| 4616 | } |
| 4617 | } |
| 4618 | |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4619 | void LocationsBuilderARMVIXL::HandleFieldGet(HInstruction* instruction, |
| 4620 | const FieldInfo& field_info) { |
| 4621 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 4622 | |
| 4623 | bool object_field_get_with_read_barrier = |
| 4624 | kEmitCompilerReadBarrier && (field_info.GetFieldType() == Primitive::kPrimNot); |
| 4625 | LocationSummary* locations = |
| 4626 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 4627 | object_field_get_with_read_barrier ? |
| 4628 | LocationSummary::kCallOnSlowPath : |
| 4629 | LocationSummary::kNoCall); |
| 4630 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| 4631 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| 4632 | } |
| 4633 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4634 | |
| 4635 | bool volatile_for_double = field_info.IsVolatile() |
| 4636 | && (field_info.GetFieldType() == Primitive::kPrimDouble) |
| 4637 | && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
| 4638 | // The output overlaps in case of volatile long: we don't want the |
| 4639 | // code generated by GenerateWideAtomicLoad to overwrite the |
| 4640 | // object's location. Likewise, in the case of an object field get |
| 4641 | // with read barriers enabled, we do not want the load to overwrite |
| 4642 | // the object's location, as we need it to emit the read barrier. |
| 4643 | bool overlap = (field_info.IsVolatile() && (field_info.GetFieldType() == Primitive::kPrimLong)) || |
| 4644 | object_field_get_with_read_barrier; |
| 4645 | |
| 4646 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 4647 | locations->SetOut(Location::RequiresFpuRegister()); |
| 4648 | } else { |
| 4649 | locations->SetOut(Location::RequiresRegister(), |
| 4650 | (overlap ? Location::kOutputOverlap : Location::kNoOutputOverlap)); |
| 4651 | } |
| 4652 | if (volatile_for_double) { |
| 4653 | // ARM encoding have some additional constraints for ldrexd/strexd: |
| 4654 | // - registers need to be consecutive |
| 4655 | // - the first register should be even but not R14. |
| 4656 | // We don't test for ARM yet, and the assertion makes sure that we |
| 4657 | // revisit this if we ever enable ARM encoding. |
| 4658 | DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet()); |
| 4659 | locations->AddTemp(Location::RequiresRegister()); |
| 4660 | locations->AddTemp(Location::RequiresRegister()); |
| 4661 | } else if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| 4662 | // We need a temporary register for the read barrier marking slow |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 4663 | // path in CodeGeneratorARMVIXL::GenerateFieldLoadWithBakerReadBarrier. |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4664 | locations->AddTemp(Location::RequiresRegister()); |
| 4665 | } |
| 4666 | } |
| 4667 | |
| 4668 | Location LocationsBuilderARMVIXL::ArithmeticZeroOrFpuRegister(HInstruction* input) { |
| 4669 | DCHECK(Primitive::IsFloatingPointType(input->GetType())) << input->GetType(); |
| 4670 | if ((input->IsFloatConstant() && (input->AsFloatConstant()->IsArithmeticZero())) || |
| 4671 | (input->IsDoubleConstant() && (input->AsDoubleConstant()->IsArithmeticZero()))) { |
| 4672 | return Location::ConstantLocation(input->AsConstant()); |
| 4673 | } else { |
| 4674 | return Location::RequiresFpuRegister(); |
| 4675 | } |
| 4676 | } |
| 4677 | |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 4678 | Location LocationsBuilderARMVIXL::ArmEncodableConstantOrRegister(HInstruction* constant, |
| 4679 | Opcode opcode) { |
| 4680 | DCHECK(!Primitive::IsFloatingPointType(constant->GetType())); |
| 4681 | if (constant->IsConstant() && |
| 4682 | CanEncodeConstantAsImmediate(constant->AsConstant(), opcode)) { |
| 4683 | return Location::ConstantLocation(constant->AsConstant()); |
| 4684 | } |
| 4685 | return Location::RequiresRegister(); |
| 4686 | } |
| 4687 | |
| 4688 | bool LocationsBuilderARMVIXL::CanEncodeConstantAsImmediate(HConstant* input_cst, |
| 4689 | Opcode opcode) { |
| 4690 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(input_cst)); |
| 4691 | if (Primitive::Is64BitType(input_cst->GetType())) { |
| 4692 | Opcode high_opcode = opcode; |
| 4693 | SetCc low_set_cc = kCcDontCare; |
| 4694 | switch (opcode) { |
| 4695 | case SUB: |
| 4696 | // Flip the operation to an ADD. |
| 4697 | value = -value; |
| 4698 | opcode = ADD; |
| 4699 | FALLTHROUGH_INTENDED; |
| 4700 | case ADD: |
| 4701 | if (Low32Bits(value) == 0u) { |
| 4702 | return CanEncodeConstantAsImmediate(High32Bits(value), opcode, kCcDontCare); |
| 4703 | } |
| 4704 | high_opcode = ADC; |
| 4705 | low_set_cc = kCcSet; |
| 4706 | break; |
| 4707 | default: |
| 4708 | break; |
| 4709 | } |
| 4710 | return CanEncodeConstantAsImmediate(Low32Bits(value), opcode, low_set_cc) && |
| 4711 | CanEncodeConstantAsImmediate(High32Bits(value), high_opcode, kCcDontCare); |
| 4712 | } else { |
| 4713 | return CanEncodeConstantAsImmediate(Low32Bits(value), opcode); |
| 4714 | } |
| 4715 | } |
| 4716 | |
| 4717 | // TODO(VIXL): Replace art::arm::SetCc` with `vixl32::FlagsUpdate after flags set optimization |
| 4718 | // enabled. |
| 4719 | bool LocationsBuilderARMVIXL::CanEncodeConstantAsImmediate(uint32_t value, |
| 4720 | Opcode opcode, |
| 4721 | SetCc set_cc) { |
| 4722 | ArmVIXLAssembler* assembler = codegen_->GetAssembler(); |
| 4723 | if (assembler->ShifterOperandCanHold(opcode, value, set_cc)) { |
| 4724 | return true; |
| 4725 | } |
| 4726 | Opcode neg_opcode = kNoOperand; |
| 4727 | switch (opcode) { |
| 4728 | case AND: neg_opcode = BIC; value = ~value; break; |
| 4729 | case ORR: neg_opcode = ORN; value = ~value; break; |
| 4730 | case ADD: neg_opcode = SUB; value = -value; break; |
| 4731 | case ADC: neg_opcode = SBC; value = ~value; break; |
| 4732 | case SUB: neg_opcode = ADD; value = -value; break; |
| 4733 | case SBC: neg_opcode = ADC; value = ~value; break; |
| 4734 | default: |
| 4735 | return false; |
| 4736 | } |
| 4737 | return assembler->ShifterOperandCanHold(neg_opcode, value, set_cc); |
| 4738 | } |
| 4739 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4740 | void InstructionCodeGeneratorARMVIXL::HandleFieldGet(HInstruction* instruction, |
| 4741 | const FieldInfo& field_info) { |
| 4742 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 4743 | |
| 4744 | LocationSummary* locations = instruction->GetLocations(); |
| 4745 | vixl32::Register base = InputRegisterAt(instruction, 0); |
| 4746 | Location out = locations->Out(); |
| 4747 | bool is_volatile = field_info.IsVolatile(); |
| 4748 | bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
| 4749 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4750 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 4751 | |
| 4752 | switch (field_type) { |
| 4753 | case Primitive::kPrimBoolean: |
| 4754 | GetAssembler()->LoadFromOffset(kLoadUnsignedByte, RegisterFrom(out), base, offset); |
| 4755 | break; |
| 4756 | |
| 4757 | case Primitive::kPrimByte: |
| 4758 | GetAssembler()->LoadFromOffset(kLoadSignedByte, RegisterFrom(out), base, offset); |
| 4759 | break; |
| 4760 | |
| 4761 | case Primitive::kPrimShort: |
| 4762 | GetAssembler()->LoadFromOffset(kLoadSignedHalfword, RegisterFrom(out), base, offset); |
| 4763 | break; |
| 4764 | |
| 4765 | case Primitive::kPrimChar: |
| 4766 | GetAssembler()->LoadFromOffset(kLoadUnsignedHalfword, RegisterFrom(out), base, offset); |
| 4767 | break; |
| 4768 | |
| 4769 | case Primitive::kPrimInt: |
| 4770 | GetAssembler()->LoadFromOffset(kLoadWord, RegisterFrom(out), base, offset); |
| 4771 | break; |
| 4772 | |
| 4773 | case Primitive::kPrimNot: { |
| 4774 | // /* HeapReference<Object> */ out = *(base + offset) |
| 4775 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 4776 | Location temp_loc = locations->GetTemp(0); |
| 4777 | // Note that a potential implicit null check is handled in this |
| 4778 | // CodeGeneratorARMVIXL::GenerateFieldLoadWithBakerReadBarrier call. |
| 4779 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 4780 | instruction, out, base, offset, temp_loc, /* needs_null_check */ true); |
| 4781 | if (is_volatile) { |
| 4782 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4783 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4784 | } else { |
| 4785 | GetAssembler()->LoadFromOffset(kLoadWord, RegisterFrom(out), base, offset); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4786 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4787 | if (is_volatile) { |
| 4788 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4789 | } |
| 4790 | // If read barriers are enabled, emit read barriers other than |
| 4791 | // Baker's using a slow path (and also unpoison the loaded |
| 4792 | // reference, if heap poisoning is enabled). |
| 4793 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, locations->InAt(0), offset); |
| 4794 | } |
| 4795 | break; |
| 4796 | } |
| 4797 | |
| 4798 | case Primitive::kPrimLong: |
| 4799 | if (is_volatile && !atomic_ldrd_strd) { |
| 4800 | GenerateWideAtomicLoad(base, offset, LowRegisterFrom(out), HighRegisterFrom(out)); |
| 4801 | } else { |
| 4802 | GetAssembler()->LoadFromOffset(kLoadWordPair, LowRegisterFrom(out), base, offset); |
| 4803 | } |
| 4804 | break; |
| 4805 | |
| 4806 | case Primitive::kPrimFloat: |
| 4807 | GetAssembler()->LoadSFromOffset(SRegisterFrom(out), base, offset); |
| 4808 | break; |
| 4809 | |
| 4810 | case Primitive::kPrimDouble: { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 4811 | vixl32::DRegister out_dreg = DRegisterFrom(out); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4812 | if (is_volatile && !atomic_ldrd_strd) { |
| 4813 | vixl32::Register lo = RegisterFrom(locations->GetTemp(0)); |
| 4814 | vixl32::Register hi = RegisterFrom(locations->GetTemp(1)); |
| 4815 | GenerateWideAtomicLoad(base, offset, lo, hi); |
| 4816 | // TODO(VIXL): Do we need to be immediately after the ldrexd instruction? If so we need a |
| 4817 | // scope. |
| 4818 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4819 | __ Vmov(out_dreg, lo, hi); |
| 4820 | } else { |
| 4821 | GetAssembler()->LoadDFromOffset(out_dreg, base, offset); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4822 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4823 | } |
| 4824 | break; |
| 4825 | } |
| 4826 | |
| 4827 | case Primitive::kPrimVoid: |
| 4828 | LOG(FATAL) << "Unreachable type " << field_type; |
| 4829 | UNREACHABLE(); |
| 4830 | } |
| 4831 | |
| 4832 | if (field_type == Primitive::kPrimNot || field_type == Primitive::kPrimDouble) { |
| 4833 | // Potential implicit null checks, in the case of reference or |
| 4834 | // double fields, are handled in the previous switch statement. |
| 4835 | } else { |
| 4836 | // 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] | 4837 | // TODO(VIXL): Here and for other calls to `MaybeRecordImplicitNullCheck` in this method, we |
| 4838 | // should use a scope and the assembler to emit the load instruction to guarantee that we |
| 4839 | // record the pc at the correct position. But the `Assembler` does not automatically handle |
| 4840 | // unencodable offsets. Practically, everything is fine because the helper and VIXL, at the time |
| 4841 | // of writing, do generate the store instruction last. |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4842 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4843 | } |
| 4844 | |
| 4845 | if (is_volatile) { |
| 4846 | if (field_type == Primitive::kPrimNot) { |
| 4847 | // Memory barriers, in the case of references, are also handled |
| 4848 | // in the previous switch statement. |
| 4849 | } else { |
| 4850 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4851 | } |
| 4852 | } |
| 4853 | } |
| 4854 | |
| 4855 | void LocationsBuilderARMVIXL::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 4856 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4857 | } |
| 4858 | |
| 4859 | void InstructionCodeGeneratorARMVIXL::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 4860 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
| 4861 | } |
| 4862 | |
| 4863 | void LocationsBuilderARMVIXL::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 4864 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4865 | } |
| 4866 | |
| 4867 | void InstructionCodeGeneratorARMVIXL::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 4868 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4869 | } |
| 4870 | |
| 4871 | void LocationsBuilderARMVIXL::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4872 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4873 | } |
| 4874 | |
| 4875 | void InstructionCodeGeneratorARMVIXL::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4876 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4877 | } |
| 4878 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 4879 | void LocationsBuilderARMVIXL::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 4880 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4881 | } |
| 4882 | |
| 4883 | void InstructionCodeGeneratorARMVIXL::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 4884 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
| 4885 | } |
| 4886 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 4887 | void LocationsBuilderARMVIXL::VisitUnresolvedInstanceFieldGet( |
| 4888 | HUnresolvedInstanceFieldGet* instruction) { |
| 4889 | FieldAccessCallingConventionARMVIXL calling_convention; |
| 4890 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4891 | instruction, instruction->GetFieldType(), calling_convention); |
| 4892 | } |
| 4893 | |
| 4894 | void InstructionCodeGeneratorARMVIXL::VisitUnresolvedInstanceFieldGet( |
| 4895 | HUnresolvedInstanceFieldGet* instruction) { |
| 4896 | FieldAccessCallingConventionARMVIXL calling_convention; |
| 4897 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4898 | instruction->GetFieldType(), |
| 4899 | instruction->GetFieldIndex(), |
| 4900 | instruction->GetDexPc(), |
| 4901 | calling_convention); |
| 4902 | } |
| 4903 | |
| 4904 | void LocationsBuilderARMVIXL::VisitUnresolvedInstanceFieldSet( |
| 4905 | HUnresolvedInstanceFieldSet* instruction) { |
| 4906 | FieldAccessCallingConventionARMVIXL calling_convention; |
| 4907 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4908 | instruction, instruction->GetFieldType(), calling_convention); |
| 4909 | } |
| 4910 | |
| 4911 | void InstructionCodeGeneratorARMVIXL::VisitUnresolvedInstanceFieldSet( |
| 4912 | HUnresolvedInstanceFieldSet* instruction) { |
| 4913 | FieldAccessCallingConventionARMVIXL calling_convention; |
| 4914 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4915 | instruction->GetFieldType(), |
| 4916 | instruction->GetFieldIndex(), |
| 4917 | instruction->GetDexPc(), |
| 4918 | calling_convention); |
| 4919 | } |
| 4920 | |
| 4921 | void LocationsBuilderARMVIXL::VisitUnresolvedStaticFieldGet( |
| 4922 | HUnresolvedStaticFieldGet* instruction) { |
| 4923 | FieldAccessCallingConventionARMVIXL calling_convention; |
| 4924 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4925 | instruction, instruction->GetFieldType(), calling_convention); |
| 4926 | } |
| 4927 | |
| 4928 | void InstructionCodeGeneratorARMVIXL::VisitUnresolvedStaticFieldGet( |
| 4929 | HUnresolvedStaticFieldGet* instruction) { |
| 4930 | FieldAccessCallingConventionARMVIXL calling_convention; |
| 4931 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4932 | instruction->GetFieldType(), |
| 4933 | instruction->GetFieldIndex(), |
| 4934 | instruction->GetDexPc(), |
| 4935 | calling_convention); |
| 4936 | } |
| 4937 | |
| 4938 | void LocationsBuilderARMVIXL::VisitUnresolvedStaticFieldSet( |
| 4939 | HUnresolvedStaticFieldSet* instruction) { |
| 4940 | FieldAccessCallingConventionARMVIXL calling_convention; |
| 4941 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4942 | instruction, instruction->GetFieldType(), calling_convention); |
| 4943 | } |
| 4944 | |
| 4945 | void InstructionCodeGeneratorARMVIXL::VisitUnresolvedStaticFieldSet( |
| 4946 | HUnresolvedStaticFieldSet* instruction) { |
| 4947 | FieldAccessCallingConventionARMVIXL calling_convention; |
| 4948 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4949 | instruction->GetFieldType(), |
| 4950 | instruction->GetFieldIndex(), |
| 4951 | instruction->GetDexPc(), |
| 4952 | calling_convention); |
| 4953 | } |
| 4954 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4955 | void LocationsBuilderARMVIXL::VisitNullCheck(HNullCheck* instruction) { |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 4956 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4957 | locations->SetInAt(0, Location::RequiresRegister()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4958 | } |
| 4959 | |
| 4960 | void CodeGeneratorARMVIXL::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 4961 | if (CanMoveNullCheckToUser(instruction)) { |
| 4962 | return; |
| 4963 | } |
| 4964 | |
| 4965 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 4966 | // Ensure the pc position is recorded immediately after the `ldr` instruction. |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 4967 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 4968 | vixl32::kMaxInstructionSizeInBytes, |
| 4969 | CodeBufferCheckScope::kMaximumSize); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4970 | __ ldr(temps.Acquire(), MemOperand(InputRegisterAt(instruction, 0))); |
| 4971 | RecordPcInfo(instruction, instruction->GetDexPc()); |
| 4972 | } |
| 4973 | |
| 4974 | void CodeGeneratorARMVIXL::GenerateExplicitNullCheck(HNullCheck* instruction) { |
| 4975 | NullCheckSlowPathARMVIXL* slow_path = |
| 4976 | new (GetGraph()->GetArena()) NullCheckSlowPathARMVIXL(instruction); |
| 4977 | AddSlowPath(slow_path); |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 4978 | __ CompareAndBranchIfZero(InputRegisterAt(instruction, 0), slow_path->GetEntryLabel()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4979 | } |
| 4980 | |
| 4981 | void InstructionCodeGeneratorARMVIXL::VisitNullCheck(HNullCheck* instruction) { |
| 4982 | codegen_->GenerateNullCheck(instruction); |
| 4983 | } |
| 4984 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 4985 | static LoadOperandType GetLoadOperandType(Primitive::Type type) { |
| 4986 | switch (type) { |
| 4987 | case Primitive::kPrimNot: |
| 4988 | return kLoadWord; |
| 4989 | case Primitive::kPrimBoolean: |
| 4990 | return kLoadUnsignedByte; |
| 4991 | case Primitive::kPrimByte: |
| 4992 | return kLoadSignedByte; |
| 4993 | case Primitive::kPrimChar: |
| 4994 | return kLoadUnsignedHalfword; |
| 4995 | case Primitive::kPrimShort: |
| 4996 | return kLoadSignedHalfword; |
| 4997 | case Primitive::kPrimInt: |
| 4998 | return kLoadWord; |
| 4999 | case Primitive::kPrimLong: |
| 5000 | return kLoadWordPair; |
| 5001 | case Primitive::kPrimFloat: |
| 5002 | return kLoadSWord; |
| 5003 | case Primitive::kPrimDouble: |
| 5004 | return kLoadDWord; |
| 5005 | default: |
| 5006 | LOG(FATAL) << "Unreachable type " << type; |
| 5007 | UNREACHABLE(); |
| 5008 | } |
| 5009 | } |
| 5010 | |
| 5011 | static StoreOperandType GetStoreOperandType(Primitive::Type type) { |
| 5012 | switch (type) { |
| 5013 | case Primitive::kPrimNot: |
| 5014 | return kStoreWord; |
| 5015 | case Primitive::kPrimBoolean: |
| 5016 | case Primitive::kPrimByte: |
| 5017 | return kStoreByte; |
| 5018 | case Primitive::kPrimChar: |
| 5019 | case Primitive::kPrimShort: |
| 5020 | return kStoreHalfword; |
| 5021 | case Primitive::kPrimInt: |
| 5022 | return kStoreWord; |
| 5023 | case Primitive::kPrimLong: |
| 5024 | return kStoreWordPair; |
| 5025 | case Primitive::kPrimFloat: |
| 5026 | return kStoreSWord; |
| 5027 | case Primitive::kPrimDouble: |
| 5028 | return kStoreDWord; |
| 5029 | default: |
| 5030 | LOG(FATAL) << "Unreachable type " << type; |
| 5031 | UNREACHABLE(); |
| 5032 | } |
| 5033 | } |
| 5034 | |
| 5035 | void CodeGeneratorARMVIXL::LoadFromShiftedRegOffset(Primitive::Type type, |
| 5036 | Location out_loc, |
| 5037 | vixl32::Register base, |
| 5038 | vixl32::Register reg_index, |
| 5039 | vixl32::Condition cond) { |
| 5040 | uint32_t shift_count = Primitive::ComponentSizeShift(type); |
| 5041 | MemOperand mem_address(base, reg_index, vixl32::LSL, shift_count); |
| 5042 | |
| 5043 | switch (type) { |
| 5044 | case Primitive::kPrimByte: |
| 5045 | __ Ldrsb(cond, RegisterFrom(out_loc), mem_address); |
| 5046 | break; |
| 5047 | case Primitive::kPrimBoolean: |
| 5048 | __ Ldrb(cond, RegisterFrom(out_loc), mem_address); |
| 5049 | break; |
| 5050 | case Primitive::kPrimShort: |
| 5051 | __ Ldrsh(cond, RegisterFrom(out_loc), mem_address); |
| 5052 | break; |
| 5053 | case Primitive::kPrimChar: |
| 5054 | __ Ldrh(cond, RegisterFrom(out_loc), mem_address); |
| 5055 | break; |
| 5056 | case Primitive::kPrimNot: |
| 5057 | case Primitive::kPrimInt: |
| 5058 | __ Ldr(cond, RegisterFrom(out_loc), mem_address); |
| 5059 | break; |
| 5060 | // T32 doesn't support LoadFromShiftedRegOffset mem address mode for these types. |
| 5061 | case Primitive::kPrimLong: |
| 5062 | case Primitive::kPrimFloat: |
| 5063 | case Primitive::kPrimDouble: |
| 5064 | default: |
| 5065 | LOG(FATAL) << "Unreachable type " << type; |
| 5066 | UNREACHABLE(); |
| 5067 | } |
| 5068 | } |
| 5069 | |
| 5070 | void CodeGeneratorARMVIXL::StoreToShiftedRegOffset(Primitive::Type type, |
| 5071 | Location loc, |
| 5072 | vixl32::Register base, |
| 5073 | vixl32::Register reg_index, |
| 5074 | vixl32::Condition cond) { |
| 5075 | uint32_t shift_count = Primitive::ComponentSizeShift(type); |
| 5076 | MemOperand mem_address(base, reg_index, vixl32::LSL, shift_count); |
| 5077 | |
| 5078 | switch (type) { |
| 5079 | case Primitive::kPrimByte: |
| 5080 | case Primitive::kPrimBoolean: |
| 5081 | __ Strb(cond, RegisterFrom(loc), mem_address); |
| 5082 | break; |
| 5083 | case Primitive::kPrimShort: |
| 5084 | case Primitive::kPrimChar: |
| 5085 | __ Strh(cond, RegisterFrom(loc), mem_address); |
| 5086 | break; |
| 5087 | case Primitive::kPrimNot: |
| 5088 | case Primitive::kPrimInt: |
| 5089 | __ Str(cond, RegisterFrom(loc), mem_address); |
| 5090 | break; |
| 5091 | // T32 doesn't support StoreToShiftedRegOffset mem address mode for these types. |
| 5092 | case Primitive::kPrimLong: |
| 5093 | case Primitive::kPrimFloat: |
| 5094 | case Primitive::kPrimDouble: |
| 5095 | default: |
| 5096 | LOG(FATAL) << "Unreachable type " << type; |
| 5097 | UNREACHABLE(); |
| 5098 | } |
| 5099 | } |
| 5100 | |
| 5101 | void LocationsBuilderARMVIXL::VisitArrayGet(HArrayGet* instruction) { |
| 5102 | bool object_array_get_with_read_barrier = |
| 5103 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
| 5104 | LocationSummary* locations = |
| 5105 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 5106 | object_array_get_with_read_barrier ? |
| 5107 | LocationSummary::kCallOnSlowPath : |
| 5108 | LocationSummary::kNoCall); |
| 5109 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 5110 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5111 | } |
| 5112 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5113 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 5114 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 5115 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 5116 | } else { |
| 5117 | // The output overlaps in the case of an object array get with |
| 5118 | // read barriers enabled: we do not want the move to overwrite the |
| 5119 | // array's location, as we need it to emit the read barrier. |
| 5120 | locations->SetOut( |
| 5121 | Location::RequiresRegister(), |
| 5122 | object_array_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
| 5123 | } |
| 5124 | // We need a temporary register for the read barrier marking slow |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 5125 | // path in CodeGeneratorARMVIXL::GenerateArrayLoadWithBakerReadBarrier. |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5126 | // Also need for String compression feature. |
| 5127 | if ((object_array_get_with_read_barrier && kUseBakerReadBarrier) |
| 5128 | || (mirror::kUseStringCompression && instruction->IsStringCharAt())) { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 5129 | locations->AddTemp(Location::RequiresRegister()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5130 | } |
| 5131 | } |
| 5132 | |
| 5133 | void InstructionCodeGeneratorARMVIXL::VisitArrayGet(HArrayGet* instruction) { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5134 | LocationSummary* locations = instruction->GetLocations(); |
| 5135 | Location obj_loc = locations->InAt(0); |
| 5136 | vixl32::Register obj = InputRegisterAt(instruction, 0); |
| 5137 | Location index = locations->InAt(1); |
| 5138 | Location out_loc = locations->Out(); |
| 5139 | uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction); |
| 5140 | Primitive::Type type = instruction->GetType(); |
| 5141 | const bool maybe_compressed_char_at = mirror::kUseStringCompression && |
| 5142 | instruction->IsStringCharAt(); |
| 5143 | HInstruction* array_instr = instruction->GetArray(); |
| 5144 | bool has_intermediate_address = array_instr->IsIntermediateAddress(); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5145 | |
| 5146 | switch (type) { |
| 5147 | case Primitive::kPrimBoolean: |
| 5148 | case Primitive::kPrimByte: |
| 5149 | case Primitive::kPrimShort: |
| 5150 | case Primitive::kPrimChar: |
| 5151 | case Primitive::kPrimInt: { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5152 | vixl32::Register length; |
| 5153 | if (maybe_compressed_char_at) { |
| 5154 | length = RegisterFrom(locations->GetTemp(0)); |
| 5155 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| 5156 | GetAssembler()->LoadFromOffset(kLoadWord, length, obj, count_offset); |
| 5157 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5158 | } |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5159 | if (index.IsConstant()) { |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 5160 | int32_t const_index = Int32ConstantFrom(index); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5161 | if (maybe_compressed_char_at) { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 5162 | vixl32::Label uncompressed_load, done; |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5163 | __ Lsrs(length, length, 1u); // LSRS has a 16-bit encoding, TST (immediate) does not. |
| 5164 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 5165 | "Expecting 0=compressed, 1=uncompressed"); |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 5166 | __ B(cs, &uncompressed_load, /* far_target */ false); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 5167 | GetAssembler()->LoadFromOffset(kLoadUnsignedByte, |
| 5168 | RegisterFrom(out_loc), |
| 5169 | obj, |
| 5170 | data_offset + const_index); |
| 5171 | __ B(&done); |
| 5172 | __ Bind(&uncompressed_load); |
| 5173 | GetAssembler()->LoadFromOffset(GetLoadOperandType(Primitive::kPrimChar), |
| 5174 | RegisterFrom(out_loc), |
| 5175 | obj, |
| 5176 | data_offset + (const_index << 1)); |
| 5177 | __ Bind(&done); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5178 | } else { |
| 5179 | uint32_t full_offset = data_offset + (const_index << Primitive::ComponentSizeShift(type)); |
| 5180 | |
| 5181 | LoadOperandType load_type = GetLoadOperandType(type); |
| 5182 | GetAssembler()->LoadFromOffset(load_type, RegisterFrom(out_loc), obj, full_offset); |
| 5183 | } |
| 5184 | } else { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 5185 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5186 | vixl32::Register temp = temps.Acquire(); |
| 5187 | |
| 5188 | if (has_intermediate_address) { |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 5189 | // We do not need to compute the intermediate address from the array: the |
| 5190 | // input instruction has done it already. See the comment in |
| 5191 | // `TryExtractArrayAccessAddress()`. |
| 5192 | if (kIsDebugBuild) { |
| 5193 | HIntermediateAddress* tmp = array_instr->AsIntermediateAddress(); |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 5194 | DCHECK_EQ(Uint64ConstantFrom(tmp->GetOffset()), data_offset); |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 5195 | } |
| 5196 | temp = obj; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5197 | } else { |
| 5198 | __ Add(temp, obj, data_offset); |
| 5199 | } |
| 5200 | if (maybe_compressed_char_at) { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 5201 | vixl32::Label uncompressed_load, done; |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5202 | __ Lsrs(length, length, 1u); // LSRS has a 16-bit encoding, TST (immediate) does not. |
| 5203 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 5204 | "Expecting 0=compressed, 1=uncompressed"); |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 5205 | __ B(cs, &uncompressed_load, /* far_target */ false); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 5206 | __ Ldrb(RegisterFrom(out_loc), MemOperand(temp, RegisterFrom(index), vixl32::LSL, 0)); |
| 5207 | __ B(&done); |
| 5208 | __ Bind(&uncompressed_load); |
| 5209 | __ Ldrh(RegisterFrom(out_loc), MemOperand(temp, RegisterFrom(index), vixl32::LSL, 1)); |
| 5210 | __ Bind(&done); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5211 | } else { |
| 5212 | codegen_->LoadFromShiftedRegOffset(type, out_loc, temp, RegisterFrom(index)); |
| 5213 | } |
| 5214 | } |
| 5215 | break; |
| 5216 | } |
| 5217 | |
| 5218 | case Primitive::kPrimNot: { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 5219 | // The read barrier instrumentation of object ArrayGet |
| 5220 | // instructions does not support the HIntermediateAddress |
| 5221 | // instruction. |
| 5222 | DCHECK(!(has_intermediate_address && kEmitCompilerReadBarrier)); |
| 5223 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5224 | static_assert( |
| 5225 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 5226 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 5227 | // /* HeapReference<Object> */ out = |
| 5228 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 5229 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 5230 | Location temp = locations->GetTemp(0); |
| 5231 | // Note that a potential implicit null check is handled in this |
| 5232 | // CodeGeneratorARMVIXL::GenerateArrayLoadWithBakerReadBarrier call. |
| 5233 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
| 5234 | instruction, out_loc, obj, data_offset, index, temp, /* needs_null_check */ true); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5235 | } else { |
| 5236 | vixl32::Register out = OutputRegister(instruction); |
| 5237 | if (index.IsConstant()) { |
| 5238 | size_t offset = |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 5239 | (Int32ConstantFrom(index) << TIMES_4) + data_offset; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5240 | GetAssembler()->LoadFromOffset(kLoadWord, out, obj, offset); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 5241 | // TODO(VIXL): Here and for other calls to `MaybeRecordImplicitNullCheck` in this method, |
| 5242 | // we should use a scope and the assembler to emit the load instruction to guarantee that |
| 5243 | // we record the pc at the correct position. But the `Assembler` does not automatically |
| 5244 | // handle unencodable offsets. Practically, everything is fine because the helper and |
| 5245 | // VIXL, at the time of writing, do generate the store instruction last. |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5246 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5247 | // If read barriers are enabled, emit read barriers other than |
| 5248 | // Baker's using a slow path (and also unpoison the loaded |
| 5249 | // reference, if heap poisoning is enabled). |
| 5250 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 5251 | } else { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 5252 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5253 | vixl32::Register temp = temps.Acquire(); |
| 5254 | |
| 5255 | if (has_intermediate_address) { |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 5256 | // We do not need to compute the intermediate address from the array: the |
| 5257 | // input instruction has done it already. See the comment in |
| 5258 | // `TryExtractArrayAccessAddress()`. |
| 5259 | if (kIsDebugBuild) { |
| 5260 | HIntermediateAddress* tmp = array_instr->AsIntermediateAddress(); |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 5261 | DCHECK_EQ(Uint64ConstantFrom(tmp->GetOffset()), data_offset); |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 5262 | } |
| 5263 | temp = obj; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5264 | } else { |
| 5265 | __ Add(temp, obj, data_offset); |
| 5266 | } |
| 5267 | codegen_->LoadFromShiftedRegOffset(type, out_loc, temp, RegisterFrom(index)); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 5268 | temps.Close(); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 5269 | // TODO(VIXL): Use a scope to ensure that we record the pc position immediately after the |
| 5270 | // load instruction. Practically, everything is fine because the helper and VIXL, at the |
| 5271 | // time of writing, do generate the store instruction last. |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5272 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5273 | // If read barriers are enabled, emit read barriers other than |
| 5274 | // Baker's using a slow path (and also unpoison the loaded |
| 5275 | // reference, if heap poisoning is enabled). |
| 5276 | codegen_->MaybeGenerateReadBarrierSlow( |
| 5277 | instruction, out_loc, out_loc, obj_loc, data_offset, index); |
| 5278 | } |
| 5279 | } |
| 5280 | break; |
| 5281 | } |
| 5282 | |
| 5283 | case Primitive::kPrimLong: { |
| 5284 | if (index.IsConstant()) { |
| 5285 | size_t offset = |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 5286 | (Int32ConstantFrom(index) << TIMES_8) + data_offset; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5287 | GetAssembler()->LoadFromOffset(kLoadWordPair, LowRegisterFrom(out_loc), obj, offset); |
| 5288 | } else { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 5289 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5290 | vixl32::Register temp = temps.Acquire(); |
| 5291 | __ Add(temp, obj, Operand(RegisterFrom(index), vixl32::LSL, TIMES_8)); |
| 5292 | GetAssembler()->LoadFromOffset(kLoadWordPair, LowRegisterFrom(out_loc), temp, data_offset); |
| 5293 | } |
| 5294 | break; |
| 5295 | } |
| 5296 | |
| 5297 | case Primitive::kPrimFloat: { |
| 5298 | vixl32::SRegister out = SRegisterFrom(out_loc); |
| 5299 | if (index.IsConstant()) { |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 5300 | size_t offset = (Int32ConstantFrom(index) << TIMES_4) + data_offset; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5301 | GetAssembler()->LoadSFromOffset(out, obj, offset); |
| 5302 | } else { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 5303 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5304 | vixl32::Register temp = temps.Acquire(); |
| 5305 | __ Add(temp, obj, Operand(RegisterFrom(index), vixl32::LSL, TIMES_4)); |
| 5306 | GetAssembler()->LoadSFromOffset(out, temp, data_offset); |
| 5307 | } |
| 5308 | break; |
| 5309 | } |
| 5310 | |
| 5311 | case Primitive::kPrimDouble: { |
| 5312 | if (index.IsConstant()) { |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 5313 | size_t offset = (Int32ConstantFrom(index) << TIMES_8) + data_offset; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5314 | GetAssembler()->LoadDFromOffset(DRegisterFrom(out_loc), obj, offset); |
| 5315 | } else { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 5316 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5317 | vixl32::Register temp = temps.Acquire(); |
| 5318 | __ Add(temp, obj, Operand(RegisterFrom(index), vixl32::LSL, TIMES_8)); |
| 5319 | GetAssembler()->LoadDFromOffset(DRegisterFrom(out_loc), temp, data_offset); |
| 5320 | } |
| 5321 | break; |
| 5322 | } |
| 5323 | |
| 5324 | case Primitive::kPrimVoid: |
| 5325 | LOG(FATAL) << "Unreachable type " << type; |
| 5326 | UNREACHABLE(); |
| 5327 | } |
| 5328 | |
| 5329 | if (type == Primitive::kPrimNot) { |
| 5330 | // Potential implicit null checks, in the case of reference |
| 5331 | // arrays, are handled in the previous switch statement. |
| 5332 | } else if (!maybe_compressed_char_at) { |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 5333 | // TODO(VIXL): Use a scope to ensure we record the pc info immediately after |
| 5334 | // the preceding load instruction. |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5335 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5336 | } |
| 5337 | } |
| 5338 | |
| 5339 | void LocationsBuilderARMVIXL::VisitArraySet(HArraySet* instruction) { |
| 5340 | Primitive::Type value_type = instruction->GetComponentType(); |
| 5341 | |
| 5342 | bool needs_write_barrier = |
| 5343 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
| 5344 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
| 5345 | |
| 5346 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 5347 | instruction, |
| 5348 | may_need_runtime_call_for_type_check ? |
| 5349 | LocationSummary::kCallOnSlowPath : |
| 5350 | LocationSummary::kNoCall); |
| 5351 | |
| 5352 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5353 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 5354 | if (Primitive::IsFloatingPointType(value_type)) { |
| 5355 | locations->SetInAt(2, Location::RequiresFpuRegister()); |
| 5356 | } else { |
| 5357 | locations->SetInAt(2, Location::RequiresRegister()); |
| 5358 | } |
| 5359 | if (needs_write_barrier) { |
| 5360 | // Temporary registers for the write barrier. |
| 5361 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
| 5362 | locations->AddTemp(Location::RequiresRegister()); |
| 5363 | } |
| 5364 | } |
| 5365 | |
| 5366 | void InstructionCodeGeneratorARMVIXL::VisitArraySet(HArraySet* instruction) { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5367 | LocationSummary* locations = instruction->GetLocations(); |
| 5368 | vixl32::Register array = InputRegisterAt(instruction, 0); |
| 5369 | Location index = locations->InAt(1); |
| 5370 | Primitive::Type value_type = instruction->GetComponentType(); |
| 5371 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
| 5372 | bool needs_write_barrier = |
| 5373 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
| 5374 | uint32_t data_offset = |
| 5375 | mirror::Array::DataOffset(Primitive::ComponentSize(value_type)).Uint32Value(); |
| 5376 | Location value_loc = locations->InAt(2); |
| 5377 | HInstruction* array_instr = instruction->GetArray(); |
| 5378 | bool has_intermediate_address = array_instr->IsIntermediateAddress(); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5379 | |
| 5380 | switch (value_type) { |
| 5381 | case Primitive::kPrimBoolean: |
| 5382 | case Primitive::kPrimByte: |
| 5383 | case Primitive::kPrimShort: |
| 5384 | case Primitive::kPrimChar: |
| 5385 | case Primitive::kPrimInt: { |
| 5386 | if (index.IsConstant()) { |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 5387 | int32_t const_index = Int32ConstantFrom(index); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5388 | uint32_t full_offset = |
| 5389 | data_offset + (const_index << Primitive::ComponentSizeShift(value_type)); |
| 5390 | StoreOperandType store_type = GetStoreOperandType(value_type); |
| 5391 | GetAssembler()->StoreToOffset(store_type, RegisterFrom(value_loc), array, full_offset); |
| 5392 | } else { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 5393 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5394 | vixl32::Register temp = temps.Acquire(); |
| 5395 | |
| 5396 | if (has_intermediate_address) { |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 5397 | // We do not need to compute the intermediate address from the array: the |
| 5398 | // input instruction has done it already. See the comment in |
| 5399 | // `TryExtractArrayAccessAddress()`. |
| 5400 | if (kIsDebugBuild) { |
| 5401 | HIntermediateAddress* tmp = array_instr->AsIntermediateAddress(); |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 5402 | DCHECK_EQ(Uint64ConstantFrom(tmp->GetOffset()), data_offset); |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 5403 | } |
| 5404 | temp = array; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5405 | } else { |
| 5406 | __ Add(temp, array, data_offset); |
| 5407 | } |
| 5408 | codegen_->StoreToShiftedRegOffset(value_type, value_loc, temp, RegisterFrom(index)); |
| 5409 | } |
| 5410 | break; |
| 5411 | } |
| 5412 | |
| 5413 | case Primitive::kPrimNot: { |
| 5414 | vixl32::Register value = RegisterFrom(value_loc); |
| 5415 | // TryExtractArrayAccessAddress optimization is never applied for non-primitive ArraySet. |
| 5416 | // See the comment in instruction_simplifier_shared.cc. |
| 5417 | DCHECK(!has_intermediate_address); |
| 5418 | |
| 5419 | if (instruction->InputAt(2)->IsNullConstant()) { |
| 5420 | // Just setting null. |
| 5421 | if (index.IsConstant()) { |
| 5422 | size_t offset = |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 5423 | (Int32ConstantFrom(index) << TIMES_4) + data_offset; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5424 | GetAssembler()->StoreToOffset(kStoreWord, value, array, offset); |
| 5425 | } else { |
| 5426 | DCHECK(index.IsRegister()) << index; |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 5427 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5428 | vixl32::Register temp = temps.Acquire(); |
| 5429 | __ Add(temp, array, data_offset); |
| 5430 | codegen_->StoreToShiftedRegOffset(value_type, value_loc, temp, RegisterFrom(index)); |
| 5431 | } |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 5432 | // TODO(VIXL): Use a scope to ensure we record the pc info immediately after the preceding |
| 5433 | // store instruction. |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5434 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5435 | DCHECK(!needs_write_barrier); |
| 5436 | DCHECK(!may_need_runtime_call_for_type_check); |
| 5437 | break; |
| 5438 | } |
| 5439 | |
| 5440 | DCHECK(needs_write_barrier); |
| 5441 | Location temp1_loc = locations->GetTemp(0); |
| 5442 | vixl32::Register temp1 = RegisterFrom(temp1_loc); |
| 5443 | Location temp2_loc = locations->GetTemp(1); |
| 5444 | vixl32::Register temp2 = RegisterFrom(temp2_loc); |
| 5445 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 5446 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5447 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 5448 | vixl32::Label done; |
| 5449 | SlowPathCodeARMVIXL* slow_path = nullptr; |
| 5450 | |
| 5451 | if (may_need_runtime_call_for_type_check) { |
| 5452 | slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathARMVIXL(instruction); |
| 5453 | codegen_->AddSlowPath(slow_path); |
| 5454 | if (instruction->GetValueCanBeNull()) { |
| 5455 | vixl32::Label non_zero; |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 5456 | __ CompareAndBranchIfNonZero(value, &non_zero); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5457 | if (index.IsConstant()) { |
| 5458 | size_t offset = |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 5459 | (Int32ConstantFrom(index) << TIMES_4) + data_offset; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5460 | GetAssembler()->StoreToOffset(kStoreWord, value, array, offset); |
| 5461 | } else { |
| 5462 | DCHECK(index.IsRegister()) << index; |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 5463 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5464 | vixl32::Register temp = temps.Acquire(); |
| 5465 | __ Add(temp, array, data_offset); |
| 5466 | codegen_->StoreToShiftedRegOffset(value_type, value_loc, temp, RegisterFrom(index)); |
| 5467 | } |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 5468 | // TODO(VIXL): Use a scope to ensure we record the pc info immediately after the preceding |
| 5469 | // store instruction. |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5470 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5471 | __ B(&done); |
| 5472 | __ Bind(&non_zero); |
| 5473 | } |
| 5474 | |
| 5475 | // Note that when read barriers are enabled, the type checks |
| 5476 | // are performed without read barriers. This is fine, even in |
| 5477 | // the case where a class object is in the from-space after |
| 5478 | // the flip, as a comparison involving such a type would not |
| 5479 | // produce a false positive; it may of course produce a false |
| 5480 | // negative, in which case we would take the ArraySet slow |
| 5481 | // path. |
| 5482 | |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 5483 | { |
| 5484 | // Ensure we record the pc position immediately after the `ldr` instruction. |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 5485 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 5486 | vixl32::kMaxInstructionSizeInBytes, |
| 5487 | CodeBufferCheckScope::kMaximumSize); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 5488 | // /* HeapReference<Class> */ temp1 = array->klass_ |
| 5489 | __ ldr(temp1, MemOperand(array, class_offset)); |
| 5490 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5491 | } |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5492 | GetAssembler()->MaybeUnpoisonHeapReference(temp1); |
| 5493 | |
| 5494 | // /* HeapReference<Class> */ temp1 = temp1->component_type_ |
| 5495 | GetAssembler()->LoadFromOffset(kLoadWord, temp1, temp1, component_offset); |
| 5496 | // /* HeapReference<Class> */ temp2 = value->klass_ |
| 5497 | GetAssembler()->LoadFromOffset(kLoadWord, temp2, value, class_offset); |
| 5498 | // If heap poisoning is enabled, no need to unpoison `temp1` |
| 5499 | // nor `temp2`, as we are comparing two poisoned references. |
| 5500 | __ Cmp(temp1, temp2); |
| 5501 | |
| 5502 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 5503 | vixl32::Label do_put; |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 5504 | __ B(eq, &do_put, /* far_target */ false); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5505 | // If heap poisoning is enabled, the `temp1` reference has |
| 5506 | // not been unpoisoned yet; unpoison it now. |
| 5507 | GetAssembler()->MaybeUnpoisonHeapReference(temp1); |
| 5508 | |
| 5509 | // /* HeapReference<Class> */ temp1 = temp1->super_class_ |
| 5510 | GetAssembler()->LoadFromOffset(kLoadWord, temp1, temp1, super_offset); |
| 5511 | // If heap poisoning is enabled, no need to unpoison |
| 5512 | // `temp1`, as we are comparing against null below. |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 5513 | __ CompareAndBranchIfNonZero(temp1, slow_path->GetEntryLabel()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5514 | __ Bind(&do_put); |
| 5515 | } else { |
| 5516 | __ B(ne, slow_path->GetEntryLabel()); |
| 5517 | } |
| 5518 | } |
| 5519 | |
| 5520 | vixl32::Register source = value; |
| 5521 | if (kPoisonHeapReferences) { |
| 5522 | // Note that in the case where `value` is a null reference, |
| 5523 | // we do not enter this block, as a null reference does not |
| 5524 | // need poisoning. |
| 5525 | DCHECK_EQ(value_type, Primitive::kPrimNot); |
| 5526 | __ Mov(temp1, value); |
| 5527 | GetAssembler()->PoisonHeapReference(temp1); |
| 5528 | source = temp1; |
| 5529 | } |
| 5530 | |
| 5531 | if (index.IsConstant()) { |
| 5532 | size_t offset = |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 5533 | (Int32ConstantFrom(index) << TIMES_4) + data_offset; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5534 | GetAssembler()->StoreToOffset(kStoreWord, source, array, offset); |
| 5535 | } else { |
| 5536 | DCHECK(index.IsRegister()) << index; |
| 5537 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 5538 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5539 | vixl32::Register temp = temps.Acquire(); |
| 5540 | __ Add(temp, array, data_offset); |
| 5541 | codegen_->StoreToShiftedRegOffset(value_type, |
| 5542 | LocationFrom(source), |
| 5543 | temp, |
| 5544 | RegisterFrom(index)); |
| 5545 | } |
| 5546 | |
| 5547 | if (!may_need_runtime_call_for_type_check) { |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 5548 | // TODO(VIXL): Ensure we record the pc position immediately after the preceding store |
| 5549 | // instruction. |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5550 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5551 | } |
| 5552 | |
| 5553 | codegen_->MarkGCCard(temp1, temp2, array, value, instruction->GetValueCanBeNull()); |
| 5554 | |
| 5555 | if (done.IsReferenced()) { |
| 5556 | __ Bind(&done); |
| 5557 | } |
| 5558 | |
| 5559 | if (slow_path != nullptr) { |
| 5560 | __ Bind(slow_path->GetExitLabel()); |
| 5561 | } |
| 5562 | |
| 5563 | break; |
| 5564 | } |
| 5565 | |
| 5566 | case Primitive::kPrimLong: { |
| 5567 | Location value = locations->InAt(2); |
| 5568 | if (index.IsConstant()) { |
| 5569 | size_t offset = |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 5570 | (Int32ConstantFrom(index) << TIMES_8) + data_offset; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5571 | GetAssembler()->StoreToOffset(kStoreWordPair, LowRegisterFrom(value), array, offset); |
| 5572 | } else { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 5573 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5574 | vixl32::Register temp = temps.Acquire(); |
| 5575 | __ Add(temp, array, Operand(RegisterFrom(index), vixl32::LSL, TIMES_8)); |
| 5576 | GetAssembler()->StoreToOffset(kStoreWordPair, LowRegisterFrom(value), temp, data_offset); |
| 5577 | } |
| 5578 | break; |
| 5579 | } |
| 5580 | |
| 5581 | case Primitive::kPrimFloat: { |
| 5582 | Location value = locations->InAt(2); |
| 5583 | DCHECK(value.IsFpuRegister()); |
| 5584 | if (index.IsConstant()) { |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 5585 | size_t offset = (Int32ConstantFrom(index) << TIMES_4) + data_offset; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5586 | GetAssembler()->StoreSToOffset(SRegisterFrom(value), array, offset); |
| 5587 | } else { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 5588 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5589 | vixl32::Register temp = temps.Acquire(); |
| 5590 | __ Add(temp, array, Operand(RegisterFrom(index), vixl32::LSL, TIMES_4)); |
| 5591 | GetAssembler()->StoreSToOffset(SRegisterFrom(value), temp, data_offset); |
| 5592 | } |
| 5593 | break; |
| 5594 | } |
| 5595 | |
| 5596 | case Primitive::kPrimDouble: { |
| 5597 | Location value = locations->InAt(2); |
| 5598 | DCHECK(value.IsFpuRegisterPair()); |
| 5599 | if (index.IsConstant()) { |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 5600 | size_t offset = (Int32ConstantFrom(index) << TIMES_8) + data_offset; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5601 | GetAssembler()->StoreDToOffset(DRegisterFrom(value), array, offset); |
| 5602 | } else { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 5603 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5604 | vixl32::Register temp = temps.Acquire(); |
| 5605 | __ Add(temp, array, Operand(RegisterFrom(index), vixl32::LSL, TIMES_8)); |
| 5606 | GetAssembler()->StoreDToOffset(DRegisterFrom(value), temp, data_offset); |
| 5607 | } |
| 5608 | break; |
| 5609 | } |
| 5610 | |
| 5611 | case Primitive::kPrimVoid: |
| 5612 | LOG(FATAL) << "Unreachable type " << value_type; |
| 5613 | UNREACHABLE(); |
| 5614 | } |
| 5615 | |
| 5616 | // Objects are handled in the switch. |
| 5617 | if (value_type != Primitive::kPrimNot) { |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 5618 | // TODO(VIXL): Ensure we record the pc position immediately after the preceding store |
| 5619 | // instruction. |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5620 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5621 | } |
| 5622 | } |
| 5623 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5624 | void LocationsBuilderARMVIXL::VisitArrayLength(HArrayLength* instruction) { |
| 5625 | LocationSummary* locations = |
| 5626 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 5627 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5628 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5629 | } |
| 5630 | |
| 5631 | void InstructionCodeGeneratorARMVIXL::VisitArrayLength(HArrayLength* instruction) { |
| 5632 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
| 5633 | vixl32::Register obj = InputRegisterAt(instruction, 0); |
| 5634 | vixl32::Register out = OutputRegister(instruction); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 5635 | { |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 5636 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 5637 | vixl32::kMaxInstructionSizeInBytes, |
| 5638 | CodeBufferCheckScope::kMaximumSize); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 5639 | __ ldr(out, MemOperand(obj, offset)); |
| 5640 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5641 | } |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 5642 | // Mask out compression flag from String's array length. |
| 5643 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5644 | __ Lsr(out, out, 1u); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 5645 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5646 | } |
| 5647 | |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 5648 | void LocationsBuilderARMVIXL::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 5649 | LocationSummary* locations = |
| 5650 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 5651 | |
| 5652 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5653 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->GetOffset())); |
| 5654 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5655 | } |
| 5656 | |
| 5657 | void InstructionCodeGeneratorARMVIXL::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
| 5658 | vixl32::Register out = OutputRegister(instruction); |
| 5659 | vixl32::Register first = InputRegisterAt(instruction, 0); |
| 5660 | Location second = instruction->GetLocations()->InAt(1); |
| 5661 | |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 5662 | if (second.IsRegister()) { |
| 5663 | __ Add(out, first, RegisterFrom(second)); |
| 5664 | } else { |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 5665 | __ Add(out, first, Int32ConstantFrom(second)); |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 5666 | } |
| 5667 | } |
| 5668 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5669 | void LocationsBuilderARMVIXL::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 5670 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 5671 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 5672 | caller_saves.Add(LocationFrom(calling_convention.GetRegisterAt(0))); |
| 5673 | caller_saves.Add(LocationFrom(calling_convention.GetRegisterAt(1))); |
| 5674 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
| 5675 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5676 | locations->SetInAt(1, Location::RequiresRegister()); |
| 5677 | } |
| 5678 | |
| 5679 | void InstructionCodeGeneratorARMVIXL::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 5680 | SlowPathCodeARMVIXL* slow_path = |
| 5681 | new (GetGraph()->GetArena()) BoundsCheckSlowPathARMVIXL(instruction); |
| 5682 | codegen_->AddSlowPath(slow_path); |
| 5683 | |
| 5684 | vixl32::Register index = InputRegisterAt(instruction, 0); |
| 5685 | vixl32::Register length = InputRegisterAt(instruction, 1); |
| 5686 | |
| 5687 | __ Cmp(index, length); |
| 5688 | __ B(hs, slow_path->GetEntryLabel()); |
| 5689 | } |
| 5690 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5691 | void CodeGeneratorARMVIXL::MarkGCCard(vixl32::Register temp, |
| 5692 | vixl32::Register card, |
| 5693 | vixl32::Register object, |
| 5694 | vixl32::Register value, |
| 5695 | bool can_be_null) { |
| 5696 | vixl32::Label is_null; |
| 5697 | if (can_be_null) { |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 5698 | __ CompareAndBranchIfZero(value, &is_null); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5699 | } |
| 5700 | GetAssembler()->LoadFromOffset( |
| 5701 | kLoadWord, card, tr, Thread::CardTableOffset<kArmPointerSize>().Int32Value()); |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 5702 | __ Lsr(temp, object, Operand::From(gc::accounting::CardTable::kCardShift)); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5703 | __ Strb(card, MemOperand(card, temp)); |
| 5704 | if (can_be_null) { |
| 5705 | __ Bind(&is_null); |
| 5706 | } |
| 5707 | } |
| 5708 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 5709 | void LocationsBuilderARMVIXL::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
| 5710 | LOG(FATAL) << "Unreachable"; |
| 5711 | } |
| 5712 | |
| 5713 | void InstructionCodeGeneratorARMVIXL::VisitParallelMove(HParallelMove* instruction) { |
| 5714 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 5715 | } |
| 5716 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5717 | void LocationsBuilderARMVIXL::VisitSuspendCheck(HSuspendCheck* instruction) { |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 5718 | LocationSummary* locations = |
| 5719 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
| 5720 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5721 | } |
| 5722 | |
| 5723 | void InstructionCodeGeneratorARMVIXL::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 5724 | HBasicBlock* block = instruction->GetBlock(); |
| 5725 | if (block->GetLoopInformation() != nullptr) { |
| 5726 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 5727 | // The back edge will generate the suspend check. |
| 5728 | return; |
| 5729 | } |
| 5730 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 5731 | // The goto will generate the suspend check. |
| 5732 | return; |
| 5733 | } |
| 5734 | GenerateSuspendCheck(instruction, nullptr); |
| 5735 | } |
| 5736 | |
| 5737 | void InstructionCodeGeneratorARMVIXL::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 5738 | HBasicBlock* successor) { |
| 5739 | SuspendCheckSlowPathARMVIXL* slow_path = |
| 5740 | down_cast<SuspendCheckSlowPathARMVIXL*>(instruction->GetSlowPath()); |
| 5741 | if (slow_path == nullptr) { |
| 5742 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathARMVIXL(instruction, successor); |
| 5743 | instruction->SetSlowPath(slow_path); |
| 5744 | codegen_->AddSlowPath(slow_path); |
| 5745 | if (successor != nullptr) { |
| 5746 | DCHECK(successor->IsLoopHeader()); |
| 5747 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 5748 | } |
| 5749 | } else { |
| 5750 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 5751 | } |
| 5752 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 5753 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5754 | vixl32::Register temp = temps.Acquire(); |
| 5755 | GetAssembler()->LoadFromOffset( |
| 5756 | kLoadUnsignedHalfword, temp, tr, Thread::ThreadFlagsOffset<kArmPointerSize>().Int32Value()); |
| 5757 | if (successor == nullptr) { |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 5758 | __ CompareAndBranchIfNonZero(temp, slow_path->GetEntryLabel()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5759 | __ Bind(slow_path->GetReturnLabel()); |
| 5760 | } else { |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 5761 | __ CompareAndBranchIfZero(temp, codegen_->GetLabelOf(successor)); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5762 | __ B(slow_path->GetEntryLabel()); |
| 5763 | } |
| 5764 | } |
| 5765 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 5766 | ArmVIXLAssembler* ParallelMoveResolverARMVIXL::GetAssembler() const { |
| 5767 | return codegen_->GetAssembler(); |
| 5768 | } |
| 5769 | |
| 5770 | void ParallelMoveResolverARMVIXL::EmitMove(size_t index) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5771 | UseScratchRegisterScope temps(GetAssembler()->GetVIXLAssembler()); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 5772 | MoveOperands* move = moves_[index]; |
| 5773 | Location source = move->GetSource(); |
| 5774 | Location destination = move->GetDestination(); |
| 5775 | |
| 5776 | if (source.IsRegister()) { |
| 5777 | if (destination.IsRegister()) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5778 | __ Mov(RegisterFrom(destination), RegisterFrom(source)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 5779 | } else if (destination.IsFpuRegister()) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5780 | __ Vmov(SRegisterFrom(destination), RegisterFrom(source)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 5781 | } else { |
| 5782 | DCHECK(destination.IsStackSlot()); |
| 5783 | GetAssembler()->StoreToOffset(kStoreWord, |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5784 | RegisterFrom(source), |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 5785 | sp, |
| 5786 | destination.GetStackIndex()); |
| 5787 | } |
| 5788 | } else if (source.IsStackSlot()) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5789 | if (destination.IsRegister()) { |
| 5790 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 5791 | RegisterFrom(destination), |
| 5792 | sp, |
| 5793 | source.GetStackIndex()); |
| 5794 | } else if (destination.IsFpuRegister()) { |
| 5795 | GetAssembler()->LoadSFromOffset(SRegisterFrom(destination), sp, source.GetStackIndex()); |
| 5796 | } else { |
| 5797 | DCHECK(destination.IsStackSlot()); |
| 5798 | vixl32::Register temp = temps.Acquire(); |
| 5799 | GetAssembler()->LoadFromOffset(kLoadWord, temp, sp, source.GetStackIndex()); |
| 5800 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, destination.GetStackIndex()); |
| 5801 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 5802 | } else if (source.IsFpuRegister()) { |
Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 5803 | if (destination.IsRegister()) { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5804 | __ Vmov(RegisterFrom(destination), SRegisterFrom(source)); |
Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 5805 | } else if (destination.IsFpuRegister()) { |
| 5806 | __ Vmov(SRegisterFrom(destination), SRegisterFrom(source)); |
| 5807 | } else { |
| 5808 | DCHECK(destination.IsStackSlot()); |
| 5809 | GetAssembler()->StoreSToOffset(SRegisterFrom(source), sp, destination.GetStackIndex()); |
| 5810 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 5811 | } else if (source.IsDoubleStackSlot()) { |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 5812 | if (destination.IsDoubleStackSlot()) { |
| 5813 | vixl32::DRegister temp = temps.AcquireD(); |
| 5814 | GetAssembler()->LoadDFromOffset(temp, sp, source.GetStackIndex()); |
| 5815 | GetAssembler()->StoreDToOffset(temp, sp, destination.GetStackIndex()); |
| 5816 | } else if (destination.IsRegisterPair()) { |
| 5817 | DCHECK(ExpectedPairLayout(destination)); |
| 5818 | GetAssembler()->LoadFromOffset( |
| 5819 | kLoadWordPair, LowRegisterFrom(destination), sp, source.GetStackIndex()); |
| 5820 | } else { |
Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 5821 | DCHECK(destination.IsFpuRegisterPair()) << destination; |
| 5822 | GetAssembler()->LoadDFromOffset(DRegisterFrom(destination), sp, source.GetStackIndex()); |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 5823 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 5824 | } else if (source.IsRegisterPair()) { |
| 5825 | if (destination.IsRegisterPair()) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5826 | __ Mov(LowRegisterFrom(destination), LowRegisterFrom(source)); |
| 5827 | __ Mov(HighRegisterFrom(destination), HighRegisterFrom(source)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 5828 | } else if (destination.IsFpuRegisterPair()) { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5829 | __ Vmov(DRegisterFrom(destination), LowRegisterFrom(source), HighRegisterFrom(source)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 5830 | } else { |
| 5831 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 5832 | DCHECK(ExpectedPairLayout(source)); |
| 5833 | GetAssembler()->StoreToOffset(kStoreWordPair, |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5834 | LowRegisterFrom(source), |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 5835 | sp, |
| 5836 | destination.GetStackIndex()); |
| 5837 | } |
| 5838 | } else if (source.IsFpuRegisterPair()) { |
Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 5839 | if (destination.IsRegisterPair()) { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5840 | __ Vmov(LowRegisterFrom(destination), HighRegisterFrom(destination), DRegisterFrom(source)); |
Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 5841 | } else if (destination.IsFpuRegisterPair()) { |
| 5842 | __ Vmov(DRegisterFrom(destination), DRegisterFrom(source)); |
| 5843 | } else { |
| 5844 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 5845 | GetAssembler()->StoreDToOffset(DRegisterFrom(source), sp, destination.GetStackIndex()); |
| 5846 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 5847 | } else { |
| 5848 | DCHECK(source.IsConstant()) << source; |
| 5849 | HConstant* constant = source.GetConstant(); |
| 5850 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
| 5851 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
| 5852 | if (destination.IsRegister()) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5853 | __ Mov(RegisterFrom(destination), value); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 5854 | } else { |
| 5855 | DCHECK(destination.IsStackSlot()); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 5856 | vixl32::Register temp = temps.Acquire(); |
| 5857 | __ Mov(temp, value); |
| 5858 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, destination.GetStackIndex()); |
| 5859 | } |
| 5860 | } else if (constant->IsLongConstant()) { |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 5861 | int64_t value = Int64ConstantFrom(source); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 5862 | if (destination.IsRegisterPair()) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5863 | __ Mov(LowRegisterFrom(destination), Low32Bits(value)); |
| 5864 | __ Mov(HighRegisterFrom(destination), High32Bits(value)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 5865 | } else { |
| 5866 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 5867 | vixl32::Register temp = temps.Acquire(); |
| 5868 | __ Mov(temp, Low32Bits(value)); |
| 5869 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, destination.GetStackIndex()); |
| 5870 | __ Mov(temp, High32Bits(value)); |
| 5871 | GetAssembler()->StoreToOffset(kStoreWord, |
| 5872 | temp, |
| 5873 | sp, |
| 5874 | destination.GetHighStackIndex(kArmWordSize)); |
| 5875 | } |
| 5876 | } else if (constant->IsDoubleConstant()) { |
| 5877 | double value = constant->AsDoubleConstant()->GetValue(); |
| 5878 | if (destination.IsFpuRegisterPair()) { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5879 | __ Vmov(DRegisterFrom(destination), value); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 5880 | } else { |
| 5881 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 5882 | uint64_t int_value = bit_cast<uint64_t, double>(value); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 5883 | vixl32::Register temp = temps.Acquire(); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5884 | __ Mov(temp, Low32Bits(int_value)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 5885 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, destination.GetStackIndex()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5886 | __ Mov(temp, High32Bits(int_value)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 5887 | GetAssembler()->StoreToOffset(kStoreWord, |
| 5888 | temp, |
| 5889 | sp, |
| 5890 | destination.GetHighStackIndex(kArmWordSize)); |
| 5891 | } |
| 5892 | } else { |
| 5893 | DCHECK(constant->IsFloatConstant()) << constant->DebugName(); |
| 5894 | float value = constant->AsFloatConstant()->GetValue(); |
| 5895 | if (destination.IsFpuRegister()) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5896 | __ Vmov(SRegisterFrom(destination), value); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 5897 | } else { |
| 5898 | DCHECK(destination.IsStackSlot()); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 5899 | vixl32::Register temp = temps.Acquire(); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5900 | __ Mov(temp, bit_cast<int32_t, float>(value)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 5901 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, destination.GetStackIndex()); |
| 5902 | } |
| 5903 | } |
| 5904 | } |
| 5905 | } |
| 5906 | |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 5907 | void ParallelMoveResolverARMVIXL::Exchange(vixl32::Register reg, int mem) { |
| 5908 | UseScratchRegisterScope temps(GetAssembler()->GetVIXLAssembler()); |
| 5909 | vixl32::Register temp = temps.Acquire(); |
| 5910 | __ Mov(temp, reg); |
| 5911 | GetAssembler()->LoadFromOffset(kLoadWord, reg, sp, mem); |
| 5912 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, mem); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 5913 | } |
| 5914 | |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 5915 | void ParallelMoveResolverARMVIXL::Exchange(int mem1, int mem2) { |
| 5916 | // TODO(VIXL32): Double check the performance of this implementation. |
| 5917 | UseScratchRegisterScope temps(GetAssembler()->GetVIXLAssembler()); |
Artem Serov | 4593f7d | 2016-12-29 16:21:49 +0000 | [diff] [blame] | 5918 | vixl32::SRegister temp_1 = temps.AcquireS(); |
| 5919 | vixl32::SRegister temp_2 = temps.AcquireS(); |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 5920 | |
Artem Serov | 4593f7d | 2016-12-29 16:21:49 +0000 | [diff] [blame] | 5921 | __ Vldr(temp_1, MemOperand(sp, mem1)); |
| 5922 | __ Vldr(temp_2, MemOperand(sp, mem2)); |
| 5923 | __ Vstr(temp_1, MemOperand(sp, mem2)); |
| 5924 | __ Vstr(temp_2, MemOperand(sp, mem1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 5925 | } |
| 5926 | |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 5927 | void ParallelMoveResolverARMVIXL::EmitSwap(size_t index) { |
| 5928 | MoveOperands* move = moves_[index]; |
| 5929 | Location source = move->GetSource(); |
| 5930 | Location destination = move->GetDestination(); |
| 5931 | UseScratchRegisterScope temps(GetAssembler()->GetVIXLAssembler()); |
| 5932 | |
| 5933 | if (source.IsRegister() && destination.IsRegister()) { |
| 5934 | vixl32::Register temp = temps.Acquire(); |
| 5935 | DCHECK(!RegisterFrom(source).Is(temp)); |
| 5936 | DCHECK(!RegisterFrom(destination).Is(temp)); |
| 5937 | __ Mov(temp, RegisterFrom(destination)); |
| 5938 | __ Mov(RegisterFrom(destination), RegisterFrom(source)); |
| 5939 | __ Mov(RegisterFrom(source), temp); |
| 5940 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
| 5941 | Exchange(RegisterFrom(source), destination.GetStackIndex()); |
| 5942 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
| 5943 | Exchange(RegisterFrom(destination), source.GetStackIndex()); |
| 5944 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 5945 | Exchange(source.GetStackIndex(), destination.GetStackIndex()); |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 5946 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 5947 | vixl32::SRegister temp = temps.AcquireS(); |
| 5948 | __ Vmov(temp, SRegisterFrom(source)); |
| 5949 | __ Vmov(SRegisterFrom(source), SRegisterFrom(destination)); |
| 5950 | __ Vmov(SRegisterFrom(destination), temp); |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 5951 | } else if (source.IsRegisterPair() && destination.IsRegisterPair()) { |
| 5952 | vixl32::DRegister temp = temps.AcquireD(); |
| 5953 | __ Vmov(temp, LowRegisterFrom(source), HighRegisterFrom(source)); |
| 5954 | __ Mov(LowRegisterFrom(source), LowRegisterFrom(destination)); |
| 5955 | __ Mov(HighRegisterFrom(source), HighRegisterFrom(destination)); |
| 5956 | __ Vmov(LowRegisterFrom(destination), HighRegisterFrom(destination), temp); |
| 5957 | } else if (source.IsRegisterPair() || destination.IsRegisterPair()) { |
| 5958 | vixl32::Register low_reg = LowRegisterFrom(source.IsRegisterPair() ? source : destination); |
| 5959 | int mem = source.IsRegisterPair() ? destination.GetStackIndex() : source.GetStackIndex(); |
| 5960 | DCHECK(ExpectedPairLayout(source.IsRegisterPair() ? source : destination)); |
| 5961 | vixl32::DRegister temp = temps.AcquireD(); |
| 5962 | __ Vmov(temp, low_reg, vixl32::Register(low_reg.GetCode() + 1)); |
| 5963 | GetAssembler()->LoadFromOffset(kLoadWordPair, low_reg, sp, mem); |
| 5964 | GetAssembler()->StoreDToOffset(temp, sp, mem); |
| 5965 | } else if (source.IsFpuRegisterPair() && destination.IsFpuRegisterPair()) { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 5966 | vixl32::DRegister first = DRegisterFrom(source); |
| 5967 | vixl32::DRegister second = DRegisterFrom(destination); |
| 5968 | vixl32::DRegister temp = temps.AcquireD(); |
| 5969 | __ Vmov(temp, first); |
| 5970 | __ Vmov(first, second); |
| 5971 | __ Vmov(second, temp); |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 5972 | } else if (source.IsFpuRegisterPair() || destination.IsFpuRegisterPair()) { |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 5973 | vixl32::DRegister reg = source.IsFpuRegisterPair() |
| 5974 | ? DRegisterFrom(source) |
| 5975 | : DRegisterFrom(destination); |
| 5976 | int mem = source.IsFpuRegisterPair() |
| 5977 | ? destination.GetStackIndex() |
| 5978 | : source.GetStackIndex(); |
| 5979 | vixl32::DRegister temp = temps.AcquireD(); |
| 5980 | __ Vmov(temp, reg); |
| 5981 | GetAssembler()->LoadDFromOffset(reg, sp, mem); |
| 5982 | GetAssembler()->StoreDToOffset(temp, sp, mem); |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 5983 | } else if (source.IsFpuRegister() || destination.IsFpuRegister()) { |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 5984 | vixl32::SRegister reg = source.IsFpuRegister() |
| 5985 | ? SRegisterFrom(source) |
| 5986 | : SRegisterFrom(destination); |
| 5987 | int mem = source.IsFpuRegister() |
| 5988 | ? destination.GetStackIndex() |
| 5989 | : source.GetStackIndex(); |
| 5990 | vixl32::Register temp = temps.Acquire(); |
| 5991 | __ Vmov(temp, reg); |
| 5992 | GetAssembler()->LoadSFromOffset(reg, sp, mem); |
| 5993 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, mem); |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 5994 | } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) { |
| 5995 | vixl32::DRegister temp1 = temps.AcquireD(); |
| 5996 | vixl32::DRegister temp2 = temps.AcquireD(); |
| 5997 | __ Vldr(temp1, MemOperand(sp, source.GetStackIndex())); |
| 5998 | __ Vldr(temp2, MemOperand(sp, destination.GetStackIndex())); |
| 5999 | __ Vstr(temp1, MemOperand(sp, destination.GetStackIndex())); |
| 6000 | __ Vstr(temp2, MemOperand(sp, source.GetStackIndex())); |
| 6001 | } else { |
| 6002 | LOG(FATAL) << "Unimplemented" << source << " <-> " << destination; |
| 6003 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6004 | } |
| 6005 | |
| 6006 | void ParallelMoveResolverARMVIXL::SpillScratch(int reg ATTRIBUTE_UNUSED) { |
| 6007 | TODO_VIXL32(FATAL); |
| 6008 | } |
| 6009 | |
| 6010 | void ParallelMoveResolverARMVIXL::RestoreScratch(int reg ATTRIBUTE_UNUSED) { |
| 6011 | TODO_VIXL32(FATAL); |
| 6012 | } |
| 6013 | |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 6014 | HLoadClass::LoadKind CodeGeneratorARMVIXL::GetSupportedLoadClassKind( |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 6015 | HLoadClass::LoadKind desired_class_load_kind) { |
| 6016 | switch (desired_class_load_kind) { |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 6017 | case HLoadClass::LoadKind::kInvalid: |
| 6018 | LOG(FATAL) << "UNREACHABLE"; |
| 6019 | UNREACHABLE(); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 6020 | case HLoadClass::LoadKind::kReferrersClass: |
| 6021 | break; |
| 6022 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 6023 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 6024 | break; |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 6025 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
| 6026 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 6027 | break; |
| 6028 | case HLoadClass::LoadKind::kBootImageAddress: |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 6029 | break; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6030 | case HLoadClass::LoadKind::kBssEntry: |
| 6031 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| 6032 | break; |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6033 | case HLoadClass::LoadKind::kJitTableAddress: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6034 | DCHECK(Runtime::Current()->UseJitCompilation()); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 6035 | break; |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 6036 | case HLoadClass::LoadKind::kDexCacheViaMethod: |
| 6037 | break; |
| 6038 | } |
| 6039 | return desired_class_load_kind; |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 6040 | } |
| 6041 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6042 | void LocationsBuilderARMVIXL::VisitLoadClass(HLoadClass* cls) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6043 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
| 6044 | if (load_kind == HLoadClass::LoadKind::kDexCacheViaMethod) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6045 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6046 | CodeGenerator::CreateLoadClassRuntimeCallLocationSummary( |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6047 | cls, |
| 6048 | LocationFrom(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6049 | LocationFrom(r0)); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6050 | DCHECK(calling_convention.GetRegisterAt(0).Is(r0)); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6051 | return; |
| 6052 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6053 | DCHECK(!cls->NeedsAccessCheck()); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6054 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 6055 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
| 6056 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6057 | ? LocationSummary::kCallOnSlowPath |
| 6058 | : LocationSummary::kNoCall; |
| 6059 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(cls, call_kind); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 6060 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6061 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 6062 | } |
| 6063 | |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6064 | if (load_kind == HLoadClass::LoadKind::kReferrersClass) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6065 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6066 | } |
| 6067 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6068 | if (load_kind == HLoadClass::LoadKind::kBssEntry) { |
| 6069 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 6070 | // Rely on the type resolution or initialization and marking to save everything we need. |
| 6071 | // Note that IP may be clobbered by saving/restoring the live register (only one thanks |
| 6072 | // to the custom calling convention) or by marking, so we request a different temp. |
| 6073 | locations->AddTemp(Location::RequiresRegister()); |
| 6074 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 6075 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 6076 | caller_saves.Add(LocationFrom(calling_convention.GetRegisterAt(0))); |
| 6077 | // TODO: Add GetReturnLocation() to the calling convention so that we can DCHECK() |
| 6078 | // that the the kPrimNot result register is the same as the first argument register. |
| 6079 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 6080 | } else { |
| 6081 | // For non-Baker read barrier we have a temp-clobbering call. |
| 6082 | } |
| 6083 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6084 | } |
| 6085 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6086 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 6087 | // move. |
| 6088 | void InstructionCodeGeneratorARMVIXL::VisitLoadClass(HLoadClass* cls) NO_THREAD_SAFETY_ANALYSIS { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6089 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
| 6090 | if (load_kind == HLoadClass::LoadKind::kDexCacheViaMethod) { |
| 6091 | codegen_->GenerateLoadClassRuntimeCall(cls); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6092 | return; |
| 6093 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6094 | DCHECK(!cls->NeedsAccessCheck()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6095 | |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6096 | LocationSummary* locations = cls->GetLocations(); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6097 | Location out_loc = locations->Out(); |
| 6098 | vixl32::Register out = OutputRegister(cls); |
| 6099 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 6100 | const ReadBarrierOption read_barrier_option = cls->IsInBootImage() |
| 6101 | ? kWithoutReadBarrier |
| 6102 | : kCompilerReadBarrierOption; |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6103 | bool generate_null_check = false; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6104 | switch (load_kind) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6105 | case HLoadClass::LoadKind::kReferrersClass: { |
| 6106 | DCHECK(!cls->CanCallRuntime()); |
| 6107 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 6108 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 6109 | vixl32::Register current_method = InputRegisterAt(cls, 0); |
| 6110 | GenerateGcRootFieldLoad(cls, |
| 6111 | out_loc, |
| 6112 | current_method, |
Roland Levillain | 00468f3 | 2016-10-27 18:02:48 +0100 | [diff] [blame] | 6113 | ArtMethod::DeclaringClassOffset().Int32Value(), |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 6114 | read_barrier_option); |
| 6115 | break; |
| 6116 | } |
| 6117 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6118 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 6119 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
| 6120 | __ Ldr(out, codegen_->DeduplicateBootImageTypeLiteral(cls->GetDexFile(), |
| 6121 | cls->GetTypeIndex())); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 6122 | break; |
| 6123 | } |
| 6124 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6125 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 6126 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
| 6127 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels = |
| 6128 | codegen_->NewPcRelativeTypePatch(cls->GetDexFile(), cls->GetTypeIndex()); |
| 6129 | codegen_->EmitMovwMovtPlaceholder(labels, out); |
| 6130 | break; |
| 6131 | } |
| 6132 | case HLoadClass::LoadKind::kBootImageAddress: { |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 6133 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6134 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 6135 | reinterpret_cast<uintptr_t>(cls->GetClass().Get())); |
| 6136 | DCHECK_NE(address, 0u); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 6137 | __ Ldr(out, codegen_->DeduplicateBootImageAddressLiteral(address)); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 6138 | break; |
| 6139 | } |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6140 | case HLoadClass::LoadKind::kBssEntry: { |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6141 | vixl32::Register temp = (!kUseReadBarrier || kUseBakerReadBarrier) |
| 6142 | ? RegisterFrom(locations->GetTemp(0)) |
| 6143 | : out; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6144 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels = |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 6145 | codegen_->NewTypeBssEntryPatch(cls->GetDexFile(), cls->GetTypeIndex()); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6146 | codegen_->EmitMovwMovtPlaceholder(labels, temp); |
| 6147 | GenerateGcRootFieldLoad(cls, out_loc, temp, /* offset */ 0, read_barrier_option); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6148 | generate_null_check = true; |
| 6149 | break; |
| 6150 | } |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6151 | case HLoadClass::LoadKind::kJitTableAddress: { |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 6152 | __ Ldr(out, codegen_->DeduplicateJitClassLiteral(cls->GetDexFile(), |
| 6153 | cls->GetTypeIndex(), |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6154 | cls->GetClass())); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 6155 | // /* GcRoot<mirror::Class> */ out = *out |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6156 | GenerateGcRootFieldLoad(cls, out_loc, out, /* offset */ 0, read_barrier_option); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 6157 | break; |
| 6158 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6159 | case HLoadClass::LoadKind::kDexCacheViaMethod: |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 6160 | case HLoadClass::LoadKind::kInvalid: |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6161 | LOG(FATAL) << "UNREACHABLE"; |
| 6162 | UNREACHABLE(); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6163 | } |
| 6164 | |
| 6165 | if (generate_null_check || cls->MustGenerateClinitCheck()) { |
| 6166 | DCHECK(cls->CanCallRuntime()); |
| 6167 | LoadClassSlowPathARMVIXL* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARMVIXL( |
| 6168 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 6169 | codegen_->AddSlowPath(slow_path); |
| 6170 | if (generate_null_check) { |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 6171 | __ CompareAndBranchIfZero(out, slow_path->GetEntryLabel()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6172 | } |
| 6173 | if (cls->MustGenerateClinitCheck()) { |
| 6174 | GenerateClassInitializationCheck(slow_path, out); |
| 6175 | } else { |
| 6176 | __ Bind(slow_path->GetExitLabel()); |
| 6177 | } |
| 6178 | } |
| 6179 | } |
| 6180 | |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 6181 | void LocationsBuilderARMVIXL::VisitClinitCheck(HClinitCheck* check) { |
| 6182 | LocationSummary* locations = |
| 6183 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 6184 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6185 | if (check->HasUses()) { |
| 6186 | locations->SetOut(Location::SameAsFirstInput()); |
| 6187 | } |
| 6188 | } |
| 6189 | |
| 6190 | void InstructionCodeGeneratorARMVIXL::VisitClinitCheck(HClinitCheck* check) { |
| 6191 | // We assume the class is not null. |
| 6192 | LoadClassSlowPathARMVIXL* slow_path = |
| 6193 | new (GetGraph()->GetArena()) LoadClassSlowPathARMVIXL(check->GetLoadClass(), |
| 6194 | check, |
| 6195 | check->GetDexPc(), |
| 6196 | /* do_clinit */ true); |
| 6197 | codegen_->AddSlowPath(slow_path); |
| 6198 | GenerateClassInitializationCheck(slow_path, InputRegisterAt(check, 0)); |
| 6199 | } |
| 6200 | |
| 6201 | void InstructionCodeGeneratorARMVIXL::GenerateClassInitializationCheck( |
| 6202 | LoadClassSlowPathARMVIXL* slow_path, vixl32::Register class_reg) { |
| 6203 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 6204 | vixl32::Register temp = temps.Acquire(); |
| 6205 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 6206 | temp, |
| 6207 | class_reg, |
| 6208 | mirror::Class::StatusOffset().Int32Value()); |
| 6209 | __ Cmp(temp, mirror::Class::kStatusInitialized); |
| 6210 | __ B(lt, slow_path->GetEntryLabel()); |
| 6211 | // Even if the initialized flag is set, we may be in a situation where caches are not synced |
| 6212 | // properly. Therefore, we do a memory fence. |
| 6213 | __ Dmb(ISH); |
| 6214 | __ Bind(slow_path->GetExitLabel()); |
| 6215 | } |
| 6216 | |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 6217 | HLoadString::LoadKind CodeGeneratorARMVIXL::GetSupportedLoadStringKind( |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 6218 | HLoadString::LoadKind desired_string_load_kind) { |
| 6219 | switch (desired_string_load_kind) { |
| 6220 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 6221 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 6222 | break; |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 6223 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
| 6224 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 6225 | break; |
| 6226 | case HLoadString::LoadKind::kBootImageAddress: |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 6227 | break; |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 6228 | case HLoadString::LoadKind::kBssEntry: |
| 6229 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| 6230 | break; |
| 6231 | case HLoadString::LoadKind::kJitTableAddress: |
| 6232 | DCHECK(Runtime::Current()->UseJitCompilation()); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 6233 | break; |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 6234 | case HLoadString::LoadKind::kDexCacheViaMethod: |
| 6235 | break; |
| 6236 | } |
| 6237 | return desired_string_load_kind; |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 6238 | } |
| 6239 | |
| 6240 | void LocationsBuilderARMVIXL::VisitLoadString(HLoadString* load) { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 6241 | LocationSummary::CallKind call_kind = CodeGenerator::GetLoadStringCallKind(load); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 6242 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 6243 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
| 6244 | if (load_kind == HLoadString::LoadKind::kDexCacheViaMethod) { |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 6245 | locations->SetOut(LocationFrom(r0)); |
| 6246 | } else { |
| 6247 | locations->SetOut(Location::RequiresRegister()); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 6248 | if (load_kind == HLoadString::LoadKind::kBssEntry) { |
| 6249 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6250 | // Rely on the pResolveString and marking to save everything we need, including temps. |
| 6251 | // Note that IP may be clobbered by saving/restoring the live register (only one thanks |
| 6252 | // 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] | 6253 | locations->AddTemp(Location::RequiresRegister()); |
| 6254 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 6255 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 6256 | caller_saves.Add(LocationFrom(calling_convention.GetRegisterAt(0))); |
| 6257 | // TODO: Add GetReturnLocation() to the calling convention so that we can DCHECK() |
| 6258 | // that the the kPrimNot result register is the same as the first argument register. |
| 6259 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 6260 | } else { |
| 6261 | // For non-Baker read barrier we have a temp-clobbering call. |
| 6262 | } |
| 6263 | } |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 6264 | } |
| 6265 | } |
| 6266 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6267 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 6268 | // move. |
| 6269 | void InstructionCodeGeneratorARMVIXL::VisitLoadString(HLoadString* load) NO_THREAD_SAFETY_ANALYSIS { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 6270 | LocationSummary* locations = load->GetLocations(); |
| 6271 | Location out_loc = locations->Out(); |
| 6272 | vixl32::Register out = OutputRegister(load); |
| 6273 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
| 6274 | |
| 6275 | switch (load_kind) { |
| 6276 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: { |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 6277 | __ Ldr(out, codegen_->DeduplicateBootImageStringLiteral(load->GetDexFile(), |
| 6278 | load->GetStringIndex())); |
| 6279 | return; // No dex cache slow path. |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 6280 | } |
| 6281 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
| 6282 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
| 6283 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels = |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6284 | codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex()); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 6285 | codegen_->EmitMovwMovtPlaceholder(labels, out); |
| 6286 | return; // No dex cache slow path. |
| 6287 | } |
| 6288 | case HLoadString::LoadKind::kBootImageAddress: { |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6289 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 6290 | reinterpret_cast<uintptr_t>(load->GetString().Get())); |
| 6291 | DCHECK_NE(address, 0u); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 6292 | __ Ldr(out, codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 6293 | return; // No dex cache slow path. |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 6294 | } |
| 6295 | case HLoadString::LoadKind::kBssEntry: { |
| 6296 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6297 | vixl32::Register temp = (!kUseReadBarrier || kUseBakerReadBarrier) |
| 6298 | ? RegisterFrom(locations->GetTemp(0)) |
| 6299 | : out; |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 6300 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels = |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6301 | codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex()); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 6302 | codegen_->EmitMovwMovtPlaceholder(labels, temp); |
| 6303 | GenerateGcRootFieldLoad(load, out_loc, temp, /* offset */ 0, kCompilerReadBarrierOption); |
| 6304 | LoadStringSlowPathARMVIXL* slow_path = |
| 6305 | new (GetGraph()->GetArena()) LoadStringSlowPathARMVIXL(load); |
| 6306 | codegen_->AddSlowPath(slow_path); |
| 6307 | __ CompareAndBranchIfZero(out, slow_path->GetEntryLabel()); |
| 6308 | __ Bind(slow_path->GetExitLabel()); |
| 6309 | return; |
| 6310 | } |
| 6311 | case HLoadString::LoadKind::kJitTableAddress: { |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 6312 | __ Ldr(out, codegen_->DeduplicateJitStringLiteral(load->GetDexFile(), |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6313 | load->GetStringIndex(), |
| 6314 | load->GetString())); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 6315 | // /* GcRoot<mirror::String> */ out = *out |
| 6316 | GenerateGcRootFieldLoad(load, out_loc, out, /* offset */ 0, kCompilerReadBarrierOption); |
| 6317 | return; |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 6318 | } |
| 6319 | default: |
| 6320 | break; |
| 6321 | } |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 6322 | |
| 6323 | // TODO: Re-add the compiler code to do string dex cache lookup again. |
| 6324 | DCHECK_EQ(load->GetLoadKind(), HLoadString::LoadKind::kDexCacheViaMethod); |
| 6325 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 6326 | __ Mov(calling_convention.GetRegisterAt(0), load->GetStringIndex().index_); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 6327 | codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc()); |
| 6328 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
| 6329 | } |
| 6330 | |
| 6331 | static int32_t GetExceptionTlsOffset() { |
| 6332 | return Thread::ExceptionOffset<kArmPointerSize>().Int32Value(); |
| 6333 | } |
| 6334 | |
| 6335 | void LocationsBuilderARMVIXL::VisitLoadException(HLoadException* load) { |
| 6336 | LocationSummary* locations = |
| 6337 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 6338 | locations->SetOut(Location::RequiresRegister()); |
| 6339 | } |
| 6340 | |
| 6341 | void InstructionCodeGeneratorARMVIXL::VisitLoadException(HLoadException* load) { |
| 6342 | vixl32::Register out = OutputRegister(load); |
| 6343 | GetAssembler()->LoadFromOffset(kLoadWord, out, tr, GetExceptionTlsOffset()); |
| 6344 | } |
| 6345 | |
| 6346 | |
| 6347 | void LocationsBuilderARMVIXL::VisitClearException(HClearException* clear) { |
| 6348 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 6349 | } |
| 6350 | |
| 6351 | void InstructionCodeGeneratorARMVIXL::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 6352 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 6353 | vixl32::Register temp = temps.Acquire(); |
| 6354 | __ Mov(temp, 0); |
| 6355 | GetAssembler()->StoreToOffset(kStoreWord, temp, tr, GetExceptionTlsOffset()); |
| 6356 | } |
| 6357 | |
| 6358 | void LocationsBuilderARMVIXL::VisitThrow(HThrow* instruction) { |
| 6359 | LocationSummary* locations = |
| 6360 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
| 6361 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 6362 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 6363 | } |
| 6364 | |
| 6365 | void InstructionCodeGeneratorARMVIXL::VisitThrow(HThrow* instruction) { |
| 6366 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
| 6367 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
| 6368 | } |
| 6369 | |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 6370 | // Temp is used for read barrier. |
| 6371 | static size_t NumberOfInstanceOfTemps(TypeCheckKind type_check_kind) { |
| 6372 | if (kEmitCompilerReadBarrier && |
| 6373 | (kUseBakerReadBarrier || |
| 6374 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 6375 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 6376 | type_check_kind == TypeCheckKind::kArrayObjectCheck)) { |
| 6377 | return 1; |
| 6378 | } |
| 6379 | return 0; |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6380 | } |
| 6381 | |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 6382 | // Interface case has 3 temps, one for holding the number of interfaces, one for the current |
| 6383 | // interface pointer, one for loading the current interface. |
| 6384 | // The other checks have one temp for loading the object's class. |
| 6385 | static size_t NumberOfCheckCastTemps(TypeCheckKind type_check_kind) { |
| 6386 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { |
| 6387 | return 3; |
| 6388 | } |
| 6389 | return 1 + NumberOfInstanceOfTemps(type_check_kind); |
| 6390 | } |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 6391 | |
| 6392 | void LocationsBuilderARMVIXL::VisitInstanceOf(HInstanceOf* instruction) { |
| 6393 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 6394 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 6395 | bool baker_read_barrier_slow_path = false; |
| 6396 | switch (type_check_kind) { |
| 6397 | case TypeCheckKind::kExactCheck: |
| 6398 | case TypeCheckKind::kAbstractClassCheck: |
| 6399 | case TypeCheckKind::kClassHierarchyCheck: |
| 6400 | case TypeCheckKind::kArrayObjectCheck: |
| 6401 | call_kind = |
| 6402 | kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
| 6403 | baker_read_barrier_slow_path = kUseBakerReadBarrier; |
| 6404 | break; |
| 6405 | case TypeCheckKind::kArrayCheck: |
| 6406 | case TypeCheckKind::kUnresolvedCheck: |
| 6407 | case TypeCheckKind::kInterfaceCheck: |
| 6408 | call_kind = LocationSummary::kCallOnSlowPath; |
| 6409 | break; |
| 6410 | } |
| 6411 | |
| 6412 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 6413 | if (baker_read_barrier_slow_path) { |
| 6414 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| 6415 | } |
| 6416 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6417 | locations->SetInAt(1, Location::RequiresRegister()); |
| 6418 | // The "out" register is used as a temporary, so it overlaps with the inputs. |
| 6419 | // Note that TypeCheckSlowPathARM uses this register too. |
| 6420 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 6421 | locations->AddRegisterTemps(NumberOfInstanceOfTemps(type_check_kind)); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 6422 | } |
| 6423 | |
| 6424 | void InstructionCodeGeneratorARMVIXL::VisitInstanceOf(HInstanceOf* instruction) { |
| 6425 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 6426 | LocationSummary* locations = instruction->GetLocations(); |
| 6427 | Location obj_loc = locations->InAt(0); |
| 6428 | vixl32::Register obj = InputRegisterAt(instruction, 0); |
| 6429 | vixl32::Register cls = InputRegisterAt(instruction, 1); |
| 6430 | Location out_loc = locations->Out(); |
| 6431 | vixl32::Register out = OutputRegister(instruction); |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 6432 | const size_t num_temps = NumberOfInstanceOfTemps(type_check_kind); |
| 6433 | DCHECK_LE(num_temps, 1u); |
| 6434 | Location maybe_temp_loc = (num_temps >= 1) ? locations->GetTemp(0) : Location::NoLocation(); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 6435 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 6436 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6437 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6438 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 6439 | vixl32::Label done, zero; |
| 6440 | SlowPathCodeARMVIXL* slow_path = nullptr; |
| 6441 | |
| 6442 | // Return 0 if `obj` is null. |
| 6443 | // avoid null check if we know obj is not null. |
| 6444 | if (instruction->MustDoNullCheck()) { |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 6445 | __ CompareAndBranchIfZero(obj, &zero, /* far_target */ false); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 6446 | } |
| 6447 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 6448 | switch (type_check_kind) { |
| 6449 | case TypeCheckKind::kExactCheck: { |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 6450 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6451 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6452 | out_loc, |
| 6453 | obj_loc, |
| 6454 | class_offset, |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 6455 | maybe_temp_loc, |
| 6456 | kCompilerReadBarrierOption); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 6457 | __ Cmp(out, cls); |
| 6458 | // Classes must be equal for the instanceof to succeed. |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 6459 | __ B(ne, &zero, /* far_target */ false); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 6460 | __ Mov(out, 1); |
| 6461 | __ B(&done); |
| 6462 | break; |
| 6463 | } |
| 6464 | |
| 6465 | case TypeCheckKind::kAbstractClassCheck: { |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 6466 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6467 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6468 | out_loc, |
| 6469 | obj_loc, |
| 6470 | class_offset, |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 6471 | maybe_temp_loc, |
| 6472 | kCompilerReadBarrierOption); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 6473 | // If the class is abstract, we eagerly fetch the super class of the |
| 6474 | // object to avoid doing a comparison we know will fail. |
| 6475 | vixl32::Label loop; |
| 6476 | __ Bind(&loop); |
| 6477 | // /* HeapReference<Class> */ out = out->super_class_ |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 6478 | GenerateReferenceLoadOneRegister(instruction, |
| 6479 | out_loc, |
| 6480 | super_offset, |
| 6481 | maybe_temp_loc, |
| 6482 | kCompilerReadBarrierOption); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 6483 | // If `out` is null, we use it for the result, and jump to `done`. |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 6484 | __ CompareAndBranchIfZero(out, &done, /* far_target */ false); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 6485 | __ Cmp(out, cls); |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 6486 | __ B(ne, &loop, /* far_target */ false); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 6487 | __ Mov(out, 1); |
| 6488 | if (zero.IsReferenced()) { |
| 6489 | __ B(&done); |
| 6490 | } |
| 6491 | break; |
| 6492 | } |
| 6493 | |
| 6494 | case TypeCheckKind::kClassHierarchyCheck: { |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 6495 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6496 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6497 | out_loc, |
| 6498 | obj_loc, |
| 6499 | class_offset, |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 6500 | maybe_temp_loc, |
| 6501 | kCompilerReadBarrierOption); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 6502 | // Walk over the class hierarchy to find a match. |
| 6503 | vixl32::Label loop, success; |
| 6504 | __ Bind(&loop); |
| 6505 | __ Cmp(out, cls); |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 6506 | __ B(eq, &success, /* far_target */ false); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 6507 | // /* HeapReference<Class> */ out = out->super_class_ |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 6508 | GenerateReferenceLoadOneRegister(instruction, |
| 6509 | out_loc, |
| 6510 | super_offset, |
| 6511 | maybe_temp_loc, |
| 6512 | kCompilerReadBarrierOption); |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 6513 | __ CompareAndBranchIfNonZero(out, &loop); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 6514 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6515 | __ B(&done); |
| 6516 | __ Bind(&success); |
| 6517 | __ Mov(out, 1); |
| 6518 | if (zero.IsReferenced()) { |
| 6519 | __ B(&done); |
| 6520 | } |
| 6521 | break; |
| 6522 | } |
| 6523 | |
| 6524 | case TypeCheckKind::kArrayObjectCheck: { |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 6525 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6526 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6527 | out_loc, |
| 6528 | obj_loc, |
| 6529 | class_offset, |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 6530 | maybe_temp_loc, |
| 6531 | kCompilerReadBarrierOption); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 6532 | // Do an exact check. |
| 6533 | vixl32::Label exact_check; |
| 6534 | __ Cmp(out, cls); |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 6535 | __ B(eq, &exact_check, /* far_target */ false); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 6536 | // Otherwise, we need to check that the object's class is a non-primitive array. |
| 6537 | // /* HeapReference<Class> */ out = out->component_type_ |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 6538 | GenerateReferenceLoadOneRegister(instruction, |
| 6539 | out_loc, |
| 6540 | component_offset, |
| 6541 | maybe_temp_loc, |
| 6542 | kCompilerReadBarrierOption); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 6543 | // If `out` is null, we use it for the result, and jump to `done`. |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 6544 | __ CompareAndBranchIfZero(out, &done, /* far_target */ false); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 6545 | GetAssembler()->LoadFromOffset(kLoadUnsignedHalfword, out, out, primitive_offset); |
| 6546 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 6547 | __ CompareAndBranchIfNonZero(out, &zero, /* far_target */ false); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 6548 | __ Bind(&exact_check); |
| 6549 | __ Mov(out, 1); |
| 6550 | __ B(&done); |
| 6551 | break; |
| 6552 | } |
| 6553 | |
| 6554 | case TypeCheckKind::kArrayCheck: { |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 6555 | // No read barrier since the slow path will retry upon failure. |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 6556 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6557 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6558 | out_loc, |
| 6559 | obj_loc, |
| 6560 | class_offset, |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 6561 | maybe_temp_loc, |
| 6562 | kWithoutReadBarrier); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 6563 | __ Cmp(out, cls); |
| 6564 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 6565 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARMVIXL(instruction, |
| 6566 | /* is_fatal */ false); |
| 6567 | codegen_->AddSlowPath(slow_path); |
| 6568 | __ B(ne, slow_path->GetEntryLabel()); |
| 6569 | __ Mov(out, 1); |
| 6570 | if (zero.IsReferenced()) { |
| 6571 | __ B(&done); |
| 6572 | } |
| 6573 | break; |
| 6574 | } |
| 6575 | |
| 6576 | case TypeCheckKind::kUnresolvedCheck: |
| 6577 | case TypeCheckKind::kInterfaceCheck: { |
| 6578 | // Note that we indeed only call on slow path, but we always go |
| 6579 | // into the slow path for the unresolved and interface check |
| 6580 | // cases. |
| 6581 | // |
| 6582 | // We cannot directly call the InstanceofNonTrivial runtime |
| 6583 | // entry point without resorting to a type checking slow path |
| 6584 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 6585 | // require to assign fixed registers for the inputs of this |
| 6586 | // HInstanceOf instruction (following the runtime calling |
| 6587 | // convention), which might be cluttered by the potential first |
| 6588 | // read barrier emission at the beginning of this method. |
| 6589 | // |
| 6590 | // TODO: Introduce a new runtime entry point taking the object |
| 6591 | // to test (instead of its class) as argument, and let it deal |
| 6592 | // with the read barrier issues. This will let us refactor this |
| 6593 | // case of the `switch` code as it was previously (with a direct |
| 6594 | // call to the runtime not using a type checking slow path). |
| 6595 | // This should also be beneficial for the other cases above. |
| 6596 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 6597 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARMVIXL(instruction, |
| 6598 | /* is_fatal */ false); |
| 6599 | codegen_->AddSlowPath(slow_path); |
| 6600 | __ B(slow_path->GetEntryLabel()); |
| 6601 | if (zero.IsReferenced()) { |
| 6602 | __ B(&done); |
| 6603 | } |
| 6604 | break; |
| 6605 | } |
| 6606 | } |
| 6607 | |
| 6608 | if (zero.IsReferenced()) { |
| 6609 | __ Bind(&zero); |
| 6610 | __ Mov(out, 0); |
| 6611 | } |
| 6612 | |
| 6613 | if (done.IsReferenced()) { |
| 6614 | __ Bind(&done); |
| 6615 | } |
| 6616 | |
| 6617 | if (slow_path != nullptr) { |
| 6618 | __ Bind(slow_path->GetExitLabel()); |
| 6619 | } |
| 6620 | } |
| 6621 | |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6622 | void LocationsBuilderARMVIXL::VisitCheckCast(HCheckCast* instruction) { |
| 6623 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 6624 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
| 6625 | |
| 6626 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 6627 | switch (type_check_kind) { |
| 6628 | case TypeCheckKind::kExactCheck: |
| 6629 | case TypeCheckKind::kAbstractClassCheck: |
| 6630 | case TypeCheckKind::kClassHierarchyCheck: |
| 6631 | case TypeCheckKind::kArrayObjectCheck: |
| 6632 | call_kind = (throws_into_catch || kEmitCompilerReadBarrier) ? |
| 6633 | LocationSummary::kCallOnSlowPath : |
| 6634 | LocationSummary::kNoCall; // In fact, call on a fatal (non-returning) slow path. |
| 6635 | break; |
| 6636 | case TypeCheckKind::kArrayCheck: |
| 6637 | case TypeCheckKind::kUnresolvedCheck: |
| 6638 | case TypeCheckKind::kInterfaceCheck: |
| 6639 | call_kind = LocationSummary::kCallOnSlowPath; |
| 6640 | break; |
| 6641 | } |
| 6642 | |
| 6643 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 6644 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6645 | locations->SetInAt(1, Location::RequiresRegister()); |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 6646 | locations->AddRegisterTemps(NumberOfCheckCastTemps(type_check_kind)); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6647 | } |
| 6648 | |
| 6649 | void InstructionCodeGeneratorARMVIXL::VisitCheckCast(HCheckCast* instruction) { |
| 6650 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 6651 | LocationSummary* locations = instruction->GetLocations(); |
| 6652 | Location obj_loc = locations->InAt(0); |
| 6653 | vixl32::Register obj = InputRegisterAt(instruction, 0); |
| 6654 | vixl32::Register cls = InputRegisterAt(instruction, 1); |
| 6655 | Location temp_loc = locations->GetTemp(0); |
| 6656 | vixl32::Register temp = RegisterFrom(temp_loc); |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 6657 | const size_t num_temps = NumberOfCheckCastTemps(type_check_kind); |
| 6658 | DCHECK_LE(num_temps, 3u); |
| 6659 | Location maybe_temp2_loc = (num_temps >= 2) ? locations->GetTemp(1) : Location::NoLocation(); |
| 6660 | Location maybe_temp3_loc = (num_temps >= 3) ? locations->GetTemp(2) : Location::NoLocation(); |
| 6661 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 6662 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6663 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6664 | const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 6665 | const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value(); |
| 6666 | const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value(); |
| 6667 | const uint32_t object_array_data_offset = |
| 6668 | mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value(); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6669 | |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 6670 | // Always false for read barriers since we may need to go to the entrypoint for non-fatal cases |
| 6671 | // from false negatives. The false negatives may come from avoiding read barriers below. Avoiding |
| 6672 | // read barriers is done for performance and code size reasons. |
| 6673 | bool is_type_check_slow_path_fatal = false; |
| 6674 | if (!kEmitCompilerReadBarrier) { |
| 6675 | is_type_check_slow_path_fatal = |
| 6676 | (type_check_kind == TypeCheckKind::kExactCheck || |
| 6677 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 6678 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 6679 | type_check_kind == TypeCheckKind::kArrayObjectCheck) && |
| 6680 | !instruction->CanThrowIntoCatchBlock(); |
| 6681 | } |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6682 | SlowPathCodeARMVIXL* type_check_slow_path = |
| 6683 | new (GetGraph()->GetArena()) TypeCheckSlowPathARMVIXL(instruction, |
| 6684 | is_type_check_slow_path_fatal); |
| 6685 | codegen_->AddSlowPath(type_check_slow_path); |
| 6686 | |
| 6687 | vixl32::Label done; |
| 6688 | // Avoid null check if we know obj is not null. |
| 6689 | if (instruction->MustDoNullCheck()) { |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 6690 | __ CompareAndBranchIfZero(obj, &done, /* far_target */ false); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6691 | } |
| 6692 | |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6693 | switch (type_check_kind) { |
| 6694 | case TypeCheckKind::kExactCheck: |
| 6695 | case TypeCheckKind::kArrayCheck: { |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 6696 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6697 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6698 | temp_loc, |
| 6699 | obj_loc, |
| 6700 | class_offset, |
| 6701 | maybe_temp2_loc, |
| 6702 | kWithoutReadBarrier); |
| 6703 | |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6704 | __ Cmp(temp, cls); |
| 6705 | // Jump to slow path for throwing the exception or doing a |
| 6706 | // more involved array check. |
| 6707 | __ B(ne, type_check_slow_path->GetEntryLabel()); |
| 6708 | break; |
| 6709 | } |
| 6710 | |
| 6711 | case TypeCheckKind::kAbstractClassCheck: { |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 6712 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6713 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6714 | temp_loc, |
| 6715 | obj_loc, |
| 6716 | class_offset, |
| 6717 | maybe_temp2_loc, |
| 6718 | kWithoutReadBarrier); |
| 6719 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 6720 | // If the class is abstract, we eagerly fetch the super class of the |
| 6721 | // object to avoid doing a comparison we know will fail. |
| 6722 | vixl32::Label loop; |
| 6723 | __ Bind(&loop); |
| 6724 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 6725 | GenerateReferenceLoadOneRegister(instruction, |
| 6726 | temp_loc, |
| 6727 | super_offset, |
| 6728 | maybe_temp2_loc, |
| 6729 | kWithoutReadBarrier); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 6730 | |
| 6731 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 6732 | // exception. |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 6733 | __ CompareAndBranchIfZero(temp, type_check_slow_path->GetEntryLabel()); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 6734 | |
| 6735 | // Otherwise, compare the classes. |
| 6736 | __ Cmp(temp, cls); |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 6737 | __ B(ne, &loop, /* far_target */ false); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6738 | break; |
| 6739 | } |
| 6740 | |
| 6741 | case TypeCheckKind::kClassHierarchyCheck: { |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 6742 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6743 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6744 | temp_loc, |
| 6745 | obj_loc, |
| 6746 | class_offset, |
| 6747 | maybe_temp2_loc, |
| 6748 | kWithoutReadBarrier); |
| 6749 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 6750 | // Walk over the class hierarchy to find a match. |
| 6751 | vixl32::Label loop; |
| 6752 | __ Bind(&loop); |
| 6753 | __ Cmp(temp, cls); |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 6754 | __ B(eq, &done, /* far_target */ false); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 6755 | |
| 6756 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 6757 | GenerateReferenceLoadOneRegister(instruction, |
| 6758 | temp_loc, |
| 6759 | super_offset, |
| 6760 | maybe_temp2_loc, |
| 6761 | kWithoutReadBarrier); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 6762 | |
| 6763 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 6764 | // exception. |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 6765 | __ CompareAndBranchIfZero(temp, type_check_slow_path->GetEntryLabel()); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 6766 | // Otherwise, jump to the beginning of the loop. |
| 6767 | __ B(&loop); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6768 | break; |
| 6769 | } |
| 6770 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 6771 | case TypeCheckKind::kArrayObjectCheck: { |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 6772 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6773 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6774 | temp_loc, |
| 6775 | obj_loc, |
| 6776 | class_offset, |
| 6777 | maybe_temp2_loc, |
| 6778 | kWithoutReadBarrier); |
| 6779 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 6780 | // Do an exact check. |
| 6781 | __ Cmp(temp, cls); |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 6782 | __ B(eq, &done, /* far_target */ false); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 6783 | |
| 6784 | // Otherwise, we need to check that the object's class is a non-primitive array. |
| 6785 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 6786 | GenerateReferenceLoadOneRegister(instruction, |
| 6787 | temp_loc, |
| 6788 | component_offset, |
| 6789 | maybe_temp2_loc, |
| 6790 | kWithoutReadBarrier); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 6791 | // 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] | 6792 | __ CompareAndBranchIfZero(temp, type_check_slow_path->GetEntryLabel()); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 6793 | // Otherwise,the object is indeed an array, jump to label `check_non_primitive_component_type` |
| 6794 | // to further check that this component type is not a primitive type. |
| 6795 | GetAssembler()->LoadFromOffset(kLoadUnsignedHalfword, temp, temp, primitive_offset); |
| 6796 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for art::Primitive::kPrimNot"); |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 6797 | __ CompareAndBranchIfNonZero(temp, type_check_slow_path->GetEntryLabel()); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6798 | break; |
| 6799 | } |
| 6800 | |
| 6801 | case TypeCheckKind::kUnresolvedCheck: |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 6802 | // 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] | 6803 | // We cannot directly call the CheckCast runtime entry point |
| 6804 | // without resorting to a type checking slow path here (i.e. by |
| 6805 | // calling InvokeRuntime directly), as it would require to |
| 6806 | // assign fixed registers for the inputs of this HInstanceOf |
| 6807 | // instruction (following the runtime calling convention), which |
| 6808 | // might be cluttered by the potential first read barrier |
| 6809 | // emission at the beginning of this method. |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 6810 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 6811 | __ B(type_check_slow_path->GetEntryLabel()); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6812 | break; |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 6813 | |
| 6814 | case TypeCheckKind::kInterfaceCheck: { |
| 6815 | // Avoid read barriers to improve performance of the fast path. We can not get false |
| 6816 | // positives by doing this. |
| 6817 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6818 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6819 | temp_loc, |
| 6820 | obj_loc, |
| 6821 | class_offset, |
| 6822 | maybe_temp2_loc, |
| 6823 | kWithoutReadBarrier); |
| 6824 | |
| 6825 | // /* HeapReference<Class> */ temp = temp->iftable_ |
| 6826 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6827 | temp_loc, |
| 6828 | temp_loc, |
| 6829 | iftable_offset, |
| 6830 | maybe_temp2_loc, |
| 6831 | kWithoutReadBarrier); |
| 6832 | // Iftable is never null. |
| 6833 | __ Ldr(RegisterFrom(maybe_temp2_loc), MemOperand(temp, array_length_offset)); |
| 6834 | // Loop through the iftable and check if any class matches. |
| 6835 | vixl32::Label start_loop; |
| 6836 | __ Bind(&start_loop); |
| 6837 | __ CompareAndBranchIfZero(RegisterFrom(maybe_temp2_loc), |
| 6838 | type_check_slow_path->GetEntryLabel()); |
| 6839 | __ Ldr(RegisterFrom(maybe_temp3_loc), MemOperand(temp, object_array_data_offset)); |
| 6840 | GetAssembler()->MaybeUnpoisonHeapReference(RegisterFrom(maybe_temp3_loc)); |
| 6841 | // Go to next interface. |
| 6842 | __ Add(temp, temp, Operand::From(2 * kHeapReferenceSize)); |
| 6843 | __ Sub(RegisterFrom(maybe_temp2_loc), RegisterFrom(maybe_temp2_loc), 2); |
| 6844 | // Compare the classes and continue the loop if they do not match. |
| 6845 | __ Cmp(cls, RegisterFrom(maybe_temp3_loc)); |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 6846 | __ B(ne, &start_loop, /* far_target */ false); |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 6847 | break; |
| 6848 | } |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6849 | } |
| 6850 | __ Bind(&done); |
| 6851 | |
| 6852 | __ Bind(type_check_slow_path->GetExitLabel()); |
| 6853 | } |
| 6854 | |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 6855 | void LocationsBuilderARMVIXL::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 6856 | LocationSummary* locations = |
| 6857 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
| 6858 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 6859 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 6860 | } |
| 6861 | |
| 6862 | void InstructionCodeGeneratorARMVIXL::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 6863 | codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject : kQuickUnlockObject, |
| 6864 | instruction, |
| 6865 | instruction->GetDexPc()); |
| 6866 | if (instruction->IsEnter()) { |
| 6867 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 6868 | } else { |
| 6869 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 6870 | } |
| 6871 | } |
| 6872 | |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 6873 | void LocationsBuilderARMVIXL::VisitAnd(HAnd* instruction) { |
| 6874 | HandleBitwiseOperation(instruction, AND); |
| 6875 | } |
| 6876 | |
| 6877 | void LocationsBuilderARMVIXL::VisitOr(HOr* instruction) { |
| 6878 | HandleBitwiseOperation(instruction, ORR); |
| 6879 | } |
| 6880 | |
| 6881 | void LocationsBuilderARMVIXL::VisitXor(HXor* instruction) { |
| 6882 | HandleBitwiseOperation(instruction, EOR); |
| 6883 | } |
| 6884 | |
| 6885 | void LocationsBuilderARMVIXL::HandleBitwiseOperation(HBinaryOperation* instruction, Opcode opcode) { |
| 6886 | LocationSummary* locations = |
| 6887 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 6888 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 6889 | || instruction->GetResultType() == Primitive::kPrimLong); |
| 6890 | // Note: GVN reorders commutative operations to have the constant on the right hand side. |
| 6891 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6892 | locations->SetInAt(1, ArmEncodableConstantOrRegister(instruction->InputAt(1), opcode)); |
| 6893 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6894 | } |
| 6895 | |
| 6896 | void InstructionCodeGeneratorARMVIXL::VisitAnd(HAnd* instruction) { |
| 6897 | HandleBitwiseOperation(instruction); |
| 6898 | } |
| 6899 | |
| 6900 | void InstructionCodeGeneratorARMVIXL::VisitOr(HOr* instruction) { |
| 6901 | HandleBitwiseOperation(instruction); |
| 6902 | } |
| 6903 | |
| 6904 | void InstructionCodeGeneratorARMVIXL::VisitXor(HXor* instruction) { |
| 6905 | HandleBitwiseOperation(instruction); |
| 6906 | } |
| 6907 | |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6908 | void LocationsBuilderARMVIXL::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instruction) { |
| 6909 | LocationSummary* locations = |
| 6910 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 6911 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 6912 | || instruction->GetResultType() == Primitive::kPrimLong); |
| 6913 | |
| 6914 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6915 | locations->SetInAt(1, Location::RequiresRegister()); |
| 6916 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6917 | } |
| 6918 | |
| 6919 | void InstructionCodeGeneratorARMVIXL::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instruction) { |
| 6920 | LocationSummary* locations = instruction->GetLocations(); |
| 6921 | Location first = locations->InAt(0); |
| 6922 | Location second = locations->InAt(1); |
| 6923 | Location out = locations->Out(); |
| 6924 | |
| 6925 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 6926 | vixl32::Register first_reg = RegisterFrom(first); |
| 6927 | vixl32::Register second_reg = RegisterFrom(second); |
| 6928 | vixl32::Register out_reg = RegisterFrom(out); |
| 6929 | |
| 6930 | switch (instruction->GetOpKind()) { |
| 6931 | case HInstruction::kAnd: |
| 6932 | __ Bic(out_reg, first_reg, second_reg); |
| 6933 | break; |
| 6934 | case HInstruction::kOr: |
| 6935 | __ Orn(out_reg, first_reg, second_reg); |
| 6936 | break; |
| 6937 | // There is no EON on arm. |
| 6938 | case HInstruction::kXor: |
| 6939 | default: |
| 6940 | LOG(FATAL) << "Unexpected instruction " << instruction->DebugName(); |
| 6941 | UNREACHABLE(); |
| 6942 | } |
| 6943 | return; |
| 6944 | |
| 6945 | } else { |
| 6946 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 6947 | vixl32::Register first_low = LowRegisterFrom(first); |
| 6948 | vixl32::Register first_high = HighRegisterFrom(first); |
| 6949 | vixl32::Register second_low = LowRegisterFrom(second); |
| 6950 | vixl32::Register second_high = HighRegisterFrom(second); |
| 6951 | vixl32::Register out_low = LowRegisterFrom(out); |
| 6952 | vixl32::Register out_high = HighRegisterFrom(out); |
| 6953 | |
| 6954 | switch (instruction->GetOpKind()) { |
| 6955 | case HInstruction::kAnd: |
| 6956 | __ Bic(out_low, first_low, second_low); |
| 6957 | __ Bic(out_high, first_high, second_high); |
| 6958 | break; |
| 6959 | case HInstruction::kOr: |
| 6960 | __ Orn(out_low, first_low, second_low); |
| 6961 | __ Orn(out_high, first_high, second_high); |
| 6962 | break; |
| 6963 | // There is no EON on arm. |
| 6964 | case HInstruction::kXor: |
| 6965 | default: |
| 6966 | LOG(FATAL) << "Unexpected instruction " << instruction->DebugName(); |
| 6967 | UNREACHABLE(); |
| 6968 | } |
| 6969 | } |
| 6970 | } |
| 6971 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 6972 | void LocationsBuilderARMVIXL::VisitDataProcWithShifterOp( |
| 6973 | HDataProcWithShifterOp* instruction) { |
| 6974 | DCHECK(instruction->GetType() == Primitive::kPrimInt || |
| 6975 | instruction->GetType() == Primitive::kPrimLong); |
| 6976 | LocationSummary* locations = |
| 6977 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 6978 | const bool overlap = instruction->GetType() == Primitive::kPrimLong && |
| 6979 | HDataProcWithShifterOp::IsExtensionOp(instruction->GetOpKind()); |
| 6980 | |
| 6981 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6982 | locations->SetInAt(1, Location::RequiresRegister()); |
| 6983 | locations->SetOut(Location::RequiresRegister(), |
| 6984 | overlap ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
| 6985 | } |
| 6986 | |
| 6987 | void InstructionCodeGeneratorARMVIXL::VisitDataProcWithShifterOp( |
| 6988 | HDataProcWithShifterOp* instruction) { |
| 6989 | const LocationSummary* const locations = instruction->GetLocations(); |
| 6990 | const HInstruction::InstructionKind kind = instruction->GetInstrKind(); |
| 6991 | const HDataProcWithShifterOp::OpKind op_kind = instruction->GetOpKind(); |
| 6992 | |
| 6993 | if (instruction->GetType() == Primitive::kPrimInt) { |
| 6994 | DCHECK(!HDataProcWithShifterOp::IsExtensionOp(op_kind)); |
| 6995 | |
| 6996 | const vixl32::Register second = instruction->InputAt(1)->GetType() == Primitive::kPrimLong |
| 6997 | ? LowRegisterFrom(locations->InAt(1)) |
| 6998 | : InputRegisterAt(instruction, 1); |
| 6999 | |
| 7000 | GenerateDataProcInstruction(kind, |
| 7001 | OutputRegister(instruction), |
| 7002 | InputRegisterAt(instruction, 0), |
| 7003 | Operand(second, |
| 7004 | ShiftFromOpKind(op_kind), |
| 7005 | instruction->GetShiftAmount()), |
| 7006 | codegen_); |
| 7007 | } else { |
| 7008 | DCHECK_EQ(instruction->GetType(), Primitive::kPrimLong); |
| 7009 | |
| 7010 | if (HDataProcWithShifterOp::IsExtensionOp(op_kind)) { |
| 7011 | const vixl32::Register second = InputRegisterAt(instruction, 1); |
| 7012 | |
| 7013 | DCHECK(!LowRegisterFrom(locations->Out()).Is(second)); |
| 7014 | GenerateDataProc(kind, |
| 7015 | locations->Out(), |
| 7016 | locations->InAt(0), |
| 7017 | second, |
| 7018 | Operand(second, ShiftType::ASR, 31), |
| 7019 | codegen_); |
| 7020 | } else { |
| 7021 | GenerateLongDataProc(instruction, codegen_); |
| 7022 | } |
| 7023 | } |
| 7024 | } |
| 7025 | |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 7026 | // TODO(VIXL): Remove optimizations in the helper when they are implemented in vixl. |
| 7027 | void InstructionCodeGeneratorARMVIXL::GenerateAndConst(vixl32::Register out, |
| 7028 | vixl32::Register first, |
| 7029 | uint32_t value) { |
| 7030 | // Optimize special cases for individual halfs of `and-long` (`and` is simplified earlier). |
| 7031 | if (value == 0xffffffffu) { |
| 7032 | if (!out.Is(first)) { |
| 7033 | __ Mov(out, first); |
| 7034 | } |
| 7035 | return; |
| 7036 | } |
| 7037 | if (value == 0u) { |
| 7038 | __ Mov(out, 0); |
| 7039 | return; |
| 7040 | } |
| 7041 | if (GetAssembler()->ShifterOperandCanHold(AND, value)) { |
| 7042 | __ And(out, first, value); |
| 7043 | } else { |
| 7044 | DCHECK(GetAssembler()->ShifterOperandCanHold(BIC, ~value)); |
| 7045 | __ Bic(out, first, ~value); |
| 7046 | } |
| 7047 | } |
| 7048 | |
| 7049 | // TODO(VIXL): Remove optimizations in the helper when they are implemented in vixl. |
| 7050 | void InstructionCodeGeneratorARMVIXL::GenerateOrrConst(vixl32::Register out, |
| 7051 | vixl32::Register first, |
| 7052 | uint32_t value) { |
| 7053 | // Optimize special cases for individual halfs of `or-long` (`or` is simplified earlier). |
| 7054 | if (value == 0u) { |
| 7055 | if (!out.Is(first)) { |
| 7056 | __ Mov(out, first); |
| 7057 | } |
| 7058 | return; |
| 7059 | } |
| 7060 | if (value == 0xffffffffu) { |
| 7061 | __ Mvn(out, 0); |
| 7062 | return; |
| 7063 | } |
| 7064 | if (GetAssembler()->ShifterOperandCanHold(ORR, value)) { |
| 7065 | __ Orr(out, first, value); |
| 7066 | } else { |
| 7067 | DCHECK(GetAssembler()->ShifterOperandCanHold(ORN, ~value)); |
| 7068 | __ Orn(out, first, ~value); |
| 7069 | } |
| 7070 | } |
| 7071 | |
| 7072 | // TODO(VIXL): Remove optimizations in the helper when they are implemented in vixl. |
| 7073 | void InstructionCodeGeneratorARMVIXL::GenerateEorConst(vixl32::Register out, |
| 7074 | vixl32::Register first, |
| 7075 | uint32_t value) { |
| 7076 | // Optimize special case for individual halfs of `xor-long` (`xor` is simplified earlier). |
| 7077 | if (value == 0u) { |
| 7078 | if (!out.Is(first)) { |
| 7079 | __ Mov(out, first); |
| 7080 | } |
| 7081 | return; |
| 7082 | } |
| 7083 | __ Eor(out, first, value); |
| 7084 | } |
| 7085 | |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 7086 | void InstructionCodeGeneratorARMVIXL::GenerateAddLongConst(Location out, |
| 7087 | Location first, |
| 7088 | uint64_t value) { |
| 7089 | vixl32::Register out_low = LowRegisterFrom(out); |
| 7090 | vixl32::Register out_high = HighRegisterFrom(out); |
| 7091 | vixl32::Register first_low = LowRegisterFrom(first); |
| 7092 | vixl32::Register first_high = HighRegisterFrom(first); |
| 7093 | uint32_t value_low = Low32Bits(value); |
| 7094 | uint32_t value_high = High32Bits(value); |
| 7095 | if (value_low == 0u) { |
| 7096 | if (!out_low.Is(first_low)) { |
| 7097 | __ Mov(out_low, first_low); |
| 7098 | } |
| 7099 | __ Add(out_high, first_high, value_high); |
| 7100 | return; |
| 7101 | } |
| 7102 | __ Adds(out_low, first_low, value_low); |
Scott Wakeling | bffdc70 | 2016-12-07 17:46:03 +0000 | [diff] [blame] | 7103 | if (GetAssembler()->ShifterOperandCanHold(ADC, value_high, kCcDontCare)) { |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 7104 | __ Adc(out_high, first_high, value_high); |
Scott Wakeling | bffdc70 | 2016-12-07 17:46:03 +0000 | [diff] [blame] | 7105 | } else if (GetAssembler()->ShifterOperandCanHold(SBC, ~value_high, kCcDontCare)) { |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 7106 | __ Sbc(out_high, first_high, ~value_high); |
| 7107 | } else { |
| 7108 | LOG(FATAL) << "Unexpected constant " << value_high; |
| 7109 | UNREACHABLE(); |
| 7110 | } |
| 7111 | } |
| 7112 | |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 7113 | void InstructionCodeGeneratorARMVIXL::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 7114 | LocationSummary* locations = instruction->GetLocations(); |
| 7115 | Location first = locations->InAt(0); |
| 7116 | Location second = locations->InAt(1); |
| 7117 | Location out = locations->Out(); |
| 7118 | |
| 7119 | if (second.IsConstant()) { |
| 7120 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant())); |
| 7121 | uint32_t value_low = Low32Bits(value); |
| 7122 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 7123 | vixl32::Register first_reg = InputRegisterAt(instruction, 0); |
| 7124 | vixl32::Register out_reg = OutputRegister(instruction); |
| 7125 | if (instruction->IsAnd()) { |
| 7126 | GenerateAndConst(out_reg, first_reg, value_low); |
| 7127 | } else if (instruction->IsOr()) { |
| 7128 | GenerateOrrConst(out_reg, first_reg, value_low); |
| 7129 | } else { |
| 7130 | DCHECK(instruction->IsXor()); |
| 7131 | GenerateEorConst(out_reg, first_reg, value_low); |
| 7132 | } |
| 7133 | } else { |
| 7134 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 7135 | uint32_t value_high = High32Bits(value); |
| 7136 | vixl32::Register first_low = LowRegisterFrom(first); |
| 7137 | vixl32::Register first_high = HighRegisterFrom(first); |
| 7138 | vixl32::Register out_low = LowRegisterFrom(out); |
| 7139 | vixl32::Register out_high = HighRegisterFrom(out); |
| 7140 | if (instruction->IsAnd()) { |
| 7141 | GenerateAndConst(out_low, first_low, value_low); |
| 7142 | GenerateAndConst(out_high, first_high, value_high); |
| 7143 | } else if (instruction->IsOr()) { |
| 7144 | GenerateOrrConst(out_low, first_low, value_low); |
| 7145 | GenerateOrrConst(out_high, first_high, value_high); |
| 7146 | } else { |
| 7147 | DCHECK(instruction->IsXor()); |
| 7148 | GenerateEorConst(out_low, first_low, value_low); |
| 7149 | GenerateEorConst(out_high, first_high, value_high); |
| 7150 | } |
| 7151 | } |
| 7152 | return; |
| 7153 | } |
| 7154 | |
| 7155 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 7156 | vixl32::Register first_reg = InputRegisterAt(instruction, 0); |
| 7157 | vixl32::Register second_reg = InputRegisterAt(instruction, 1); |
| 7158 | vixl32::Register out_reg = OutputRegister(instruction); |
| 7159 | if (instruction->IsAnd()) { |
| 7160 | __ And(out_reg, first_reg, second_reg); |
| 7161 | } else if (instruction->IsOr()) { |
| 7162 | __ Orr(out_reg, first_reg, second_reg); |
| 7163 | } else { |
| 7164 | DCHECK(instruction->IsXor()); |
| 7165 | __ Eor(out_reg, first_reg, second_reg); |
| 7166 | } |
| 7167 | } else { |
| 7168 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 7169 | vixl32::Register first_low = LowRegisterFrom(first); |
| 7170 | vixl32::Register first_high = HighRegisterFrom(first); |
| 7171 | vixl32::Register second_low = LowRegisterFrom(second); |
| 7172 | vixl32::Register second_high = HighRegisterFrom(second); |
| 7173 | vixl32::Register out_low = LowRegisterFrom(out); |
| 7174 | vixl32::Register out_high = HighRegisterFrom(out); |
| 7175 | if (instruction->IsAnd()) { |
| 7176 | __ And(out_low, first_low, second_low); |
| 7177 | __ And(out_high, first_high, second_high); |
| 7178 | } else if (instruction->IsOr()) { |
| 7179 | __ Orr(out_low, first_low, second_low); |
| 7180 | __ Orr(out_high, first_high, second_high); |
| 7181 | } else { |
| 7182 | DCHECK(instruction->IsXor()); |
| 7183 | __ Eor(out_low, first_low, second_low); |
| 7184 | __ Eor(out_high, first_high, second_high); |
| 7185 | } |
| 7186 | } |
| 7187 | } |
| 7188 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7189 | void InstructionCodeGeneratorARMVIXL::GenerateReferenceLoadOneRegister( |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 7190 | HInstruction* instruction, |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7191 | Location out, |
| 7192 | uint32_t offset, |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 7193 | Location maybe_temp, |
| 7194 | ReadBarrierOption read_barrier_option) { |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7195 | vixl32::Register out_reg = RegisterFrom(out); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 7196 | if (read_barrier_option == kWithReadBarrier) { |
| 7197 | CHECK(kEmitCompilerReadBarrier); |
| 7198 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
| 7199 | if (kUseBakerReadBarrier) { |
| 7200 | // Load with fast path based Baker's read barrier. |
| 7201 | // /* HeapReference<Object> */ out = *(out + offset) |
| 7202 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 7203 | instruction, out, out_reg, offset, maybe_temp, /* needs_null_check */ false); |
| 7204 | } else { |
| 7205 | // Load with slow path based read barrier. |
| 7206 | // Save the value of `out` into `maybe_temp` before overwriting it |
| 7207 | // in the following move operation, as we will need it for the |
| 7208 | // read barrier below. |
| 7209 | __ Mov(RegisterFrom(maybe_temp), out_reg); |
| 7210 | // /* HeapReference<Object> */ out = *(out + offset) |
| 7211 | GetAssembler()->LoadFromOffset(kLoadWord, out_reg, out_reg, offset); |
| 7212 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
| 7213 | } |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7214 | } else { |
| 7215 | // Plain load with no read barrier. |
| 7216 | // /* HeapReference<Object> */ out = *(out + offset) |
| 7217 | GetAssembler()->LoadFromOffset(kLoadWord, out_reg, out_reg, offset); |
| 7218 | GetAssembler()->MaybeUnpoisonHeapReference(out_reg); |
| 7219 | } |
| 7220 | } |
| 7221 | |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7222 | void InstructionCodeGeneratorARMVIXL::GenerateReferenceLoadTwoRegisters( |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 7223 | HInstruction* instruction, |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7224 | Location out, |
| 7225 | Location obj, |
| 7226 | uint32_t offset, |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 7227 | Location maybe_temp, |
| 7228 | ReadBarrierOption read_barrier_option) { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7229 | vixl32::Register out_reg = RegisterFrom(out); |
| 7230 | vixl32::Register obj_reg = RegisterFrom(obj); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 7231 | if (read_barrier_option == kWithReadBarrier) { |
| 7232 | CHECK(kEmitCompilerReadBarrier); |
| 7233 | if (kUseBakerReadBarrier) { |
| 7234 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
| 7235 | // Load with fast path based Baker's read barrier. |
| 7236 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 7237 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 7238 | instruction, out, obj_reg, offset, maybe_temp, /* needs_null_check */ false); |
| 7239 | } else { |
| 7240 | // Load with slow path based read barrier. |
| 7241 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 7242 | GetAssembler()->LoadFromOffset(kLoadWord, out_reg, obj_reg, offset); |
| 7243 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 7244 | } |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7245 | } else { |
| 7246 | // Plain load with no read barrier. |
| 7247 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 7248 | GetAssembler()->LoadFromOffset(kLoadWord, out_reg, obj_reg, offset); |
| 7249 | GetAssembler()->MaybeUnpoisonHeapReference(out_reg); |
| 7250 | } |
| 7251 | } |
| 7252 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7253 | void InstructionCodeGeneratorARMVIXL::GenerateGcRootFieldLoad( |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 7254 | HInstruction* instruction, |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7255 | Location root, |
| 7256 | vixl32::Register obj, |
| 7257 | uint32_t offset, |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7258 | ReadBarrierOption read_barrier_option) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7259 | vixl32::Register root_reg = RegisterFrom(root); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7260 | if (read_barrier_option == kWithReadBarrier) { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 7261 | DCHECK(kEmitCompilerReadBarrier); |
| 7262 | if (kUseBakerReadBarrier) { |
| 7263 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
Roland Levillain | 35345a5 | 2017-02-27 14:32:08 +0000 | [diff] [blame] | 7264 | // Baker's read barrier are used: |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 7265 | // |
Roland Levillain | 35345a5 | 2017-02-27 14:32:08 +0000 | [diff] [blame] | 7266 | // root = obj.field; |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 7267 | // temp = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
Roland Levillain | 35345a5 | 2017-02-27 14:32:08 +0000 | [diff] [blame] | 7268 | // if (temp != null) { |
| 7269 | // root = temp(root) |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 7270 | // } |
| 7271 | |
| 7272 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 7273 | GetAssembler()->LoadFromOffset(kLoadWord, root_reg, obj, offset); |
| 7274 | static_assert( |
| 7275 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 7276 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 7277 | "have different sizes."); |
| 7278 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 7279 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 7280 | "have different sizes."); |
| 7281 | |
Roland Levillain | 35345a5 | 2017-02-27 14:32:08 +0000 | [diff] [blame] | 7282 | // Slow path marking the GC root `root`. |
| 7283 | Location temp = LocationFrom(lr); |
| 7284 | SlowPathCodeARMVIXL* slow_path = |
| 7285 | new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathARMVIXL( |
| 7286 | instruction, |
| 7287 | root, |
| 7288 | /*entrypoint*/ temp); |
| 7289 | codegen_->AddSlowPath(slow_path); |
| 7290 | |
| 7291 | // temp = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 7292 | const int32_t entry_point_offset = |
| 7293 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArmPointerSize>(root.reg()); |
| 7294 | // Loading the entrypoint does not require a load acquire since it is only changed when |
| 7295 | // threads are suspended or running a checkpoint. |
| 7296 | GetAssembler()->LoadFromOffset(kLoadWord, RegisterFrom(temp), tr, entry_point_offset); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 7297 | // The entrypoint is null when the GC is not marking, this prevents one load compared to |
| 7298 | // checking GetIsGcMarking. |
| 7299 | __ CompareAndBranchIfNonZero(RegisterFrom(temp), slow_path->GetEntryLabel()); |
| 7300 | __ Bind(slow_path->GetExitLabel()); |
| 7301 | } else { |
| 7302 | // GC root loaded through a slow path for read barriers other |
| 7303 | // than Baker's. |
| 7304 | // /* GcRoot<mirror::Object>* */ root = obj + offset |
| 7305 | __ Add(root_reg, obj, offset); |
| 7306 | // /* mirror::Object* */ root = root->Read() |
| 7307 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 7308 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7309 | } else { |
| 7310 | // Plain GC root load with no read barrier. |
| 7311 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 7312 | GetAssembler()->LoadFromOffset(kLoadWord, root_reg, obj, offset); |
| 7313 | // Note that GC roots are not affected by heap poisoning, thus we |
| 7314 | // do not have to unpoison `root_reg` here. |
| 7315 | } |
| 7316 | } |
| 7317 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 7318 | void CodeGeneratorARMVIXL::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7319 | Location ref, |
| 7320 | vixl32::Register obj, |
| 7321 | uint32_t offset, |
| 7322 | Location temp, |
| 7323 | bool needs_null_check) { |
| 7324 | DCHECK(kEmitCompilerReadBarrier); |
| 7325 | DCHECK(kUseBakerReadBarrier); |
| 7326 | |
| 7327 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 7328 | Location no_index = Location::NoLocation(); |
| 7329 | ScaleFactor no_scale_factor = TIMES_1; |
| 7330 | GenerateReferenceLoadWithBakerReadBarrier( |
| 7331 | 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] | 7332 | } |
| 7333 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 7334 | void CodeGeneratorARMVIXL::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7335 | Location ref, |
| 7336 | vixl32::Register obj, |
| 7337 | uint32_t data_offset, |
| 7338 | Location index, |
| 7339 | Location temp, |
| 7340 | bool needs_null_check) { |
| 7341 | DCHECK(kEmitCompilerReadBarrier); |
| 7342 | DCHECK(kUseBakerReadBarrier); |
| 7343 | |
| 7344 | static_assert( |
| 7345 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 7346 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 7347 | // /* HeapReference<Object> */ ref = |
| 7348 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 7349 | ScaleFactor scale_factor = TIMES_4; |
| 7350 | GenerateReferenceLoadWithBakerReadBarrier( |
| 7351 | instruction, ref, obj, data_offset, index, scale_factor, temp, needs_null_check); |
Roland Levillain | 6070e88 | 2016-11-03 17:51:58 +0000 | [diff] [blame] | 7352 | } |
| 7353 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 7354 | void CodeGeneratorARMVIXL::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7355 | Location ref, |
| 7356 | vixl32::Register obj, |
| 7357 | uint32_t offset, |
| 7358 | Location index, |
| 7359 | ScaleFactor scale_factor, |
| 7360 | Location temp, |
| 7361 | bool needs_null_check, |
| 7362 | bool always_update_field, |
| 7363 | vixl32::Register* temp2) { |
| 7364 | DCHECK(kEmitCompilerReadBarrier); |
| 7365 | DCHECK(kUseBakerReadBarrier); |
| 7366 | |
Roland Levillain | 35345a5 | 2017-02-27 14:32:08 +0000 | [diff] [blame] | 7367 | // In slow path based read barriers, the read barrier call is |
| 7368 | // inserted after the original load. However, in fast path based |
| 7369 | // Baker's read barriers, we need to perform the load of |
| 7370 | // mirror::Object::monitor_ *before* the original reference load. |
| 7371 | // This load-load ordering is required by the read barrier. |
| 7372 | // The fast path/slow path (for Baker's algorithm) should look like: |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 7373 | // |
Roland Levillain | 35345a5 | 2017-02-27 14:32:08 +0000 | [diff] [blame] | 7374 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 7375 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 7376 | // HeapReference<Object> ref = *src; // Original reference load. |
| 7377 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 7378 | // if (is_gray) { |
| 7379 | // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path. |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 7380 | // } |
Roland Levillain | 35345a5 | 2017-02-27 14:32:08 +0000 | [diff] [blame] | 7381 | // |
| 7382 | // Note: the original implementation in ReadBarrier::Barrier is |
| 7383 | // slightly more complex as it performs additional checks that we do |
| 7384 | // not do here for performance reasons. |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 7385 | |
Roland Levillain | 35345a5 | 2017-02-27 14:32:08 +0000 | [diff] [blame] | 7386 | vixl32::Register ref_reg = RegisterFrom(ref); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 7387 | vixl32::Register temp_reg = RegisterFrom(temp); |
Roland Levillain | 35345a5 | 2017-02-27 14:32:08 +0000 | [diff] [blame] | 7388 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 7389 | |
Roland Levillain | 35345a5 | 2017-02-27 14:32:08 +0000 | [diff] [blame] | 7390 | // /* int32_t */ monitor = obj->monitor_ |
| 7391 | GetAssembler()->LoadFromOffset(kLoadWord, temp_reg, obj, monitor_offset); |
| 7392 | if (needs_null_check) { |
| 7393 | MaybeRecordImplicitNullCheck(instruction); |
| 7394 | } |
| 7395 | // /* LockWord */ lock_word = LockWord(monitor) |
| 7396 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 7397 | "art::LockWord and int32_t have different sizes."); |
| 7398 | |
| 7399 | // Introduce a dependency on the lock_word including the rb_state, |
| 7400 | // which shall prevent load-load reordering without using |
| 7401 | // a memory barrier (which would be more expensive). |
| 7402 | // `obj` is unchanged by this operation, but its value now depends |
| 7403 | // on `temp_reg`. |
| 7404 | __ Add(obj, obj, Operand(temp_reg, ShiftType::LSR, 32)); |
| 7405 | |
| 7406 | // The actual reference load. |
| 7407 | if (index.IsValid()) { |
| 7408 | // Load types involving an "index": ArrayGet, |
| 7409 | // UnsafeGetObject/UnsafeGetObjectVolatile and UnsafeCASObject |
| 7410 | // intrinsics. |
| 7411 | // /* HeapReference<Object> */ ref = *(obj + offset + (index << scale_factor)) |
| 7412 | if (index.IsConstant()) { |
| 7413 | size_t computed_offset = |
| 7414 | (Int32ConstantFrom(index) << scale_factor) + offset; |
| 7415 | GetAssembler()->LoadFromOffset(kLoadWord, ref_reg, obj, computed_offset); |
| 7416 | } else { |
| 7417 | // Handle the special case of the |
| 7418 | // UnsafeGetObject/UnsafeGetObjectVolatile and UnsafeCASObject |
| 7419 | // intrinsics, which use a register pair as index ("long |
| 7420 | // offset"), of which only the low part contains data. |
| 7421 | vixl32::Register index_reg = index.IsRegisterPair() |
| 7422 | ? LowRegisterFrom(index) |
| 7423 | : RegisterFrom(index); |
| 7424 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 7425 | const vixl32::Register temp3 = temps.Acquire(); |
| 7426 | __ Add(temp3, obj, Operand(index_reg, ShiftType::LSL, scale_factor)); |
| 7427 | GetAssembler()->LoadFromOffset(kLoadWord, ref_reg, temp3, offset); |
| 7428 | } |
| 7429 | } else { |
| 7430 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 7431 | GetAssembler()->LoadFromOffset(kLoadWord, ref_reg, obj, offset); |
| 7432 | } |
| 7433 | |
| 7434 | // Object* ref = ref_addr->AsMirrorPtr() |
| 7435 | GetAssembler()->MaybeUnpoisonHeapReference(ref_reg); |
| 7436 | |
| 7437 | // Slow path marking the object `ref` when it is gray. |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 7438 | SlowPathCodeARMVIXL* slow_path; |
| 7439 | if (always_update_field) { |
| 7440 | DCHECK(temp2 != nullptr); |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 7441 | // ReadBarrierMarkAndUpdateFieldSlowPathARMVIXL only supports address |
| 7442 | // of the form `obj + field_offset`, where `obj` is a register and |
| 7443 | // `field_offset` is a register pair (of which only the lower half |
| 7444 | // is used). Thus `offset` and `scale_factor` above are expected |
| 7445 | // to be null in this code path. |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 7446 | DCHECK_EQ(offset, 0u); |
| 7447 | DCHECK_EQ(scale_factor, ScaleFactor::TIMES_1); |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 7448 | slow_path = new (GetGraph()->GetArena()) ReadBarrierMarkAndUpdateFieldSlowPathARMVIXL( |
Roland Levillain | 35345a5 | 2017-02-27 14:32:08 +0000 | [diff] [blame] | 7449 | instruction, ref, obj, /* field_offset */ index, temp_reg, *temp2); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 7450 | } else { |
Roland Levillain | 35345a5 | 2017-02-27 14:32:08 +0000 | [diff] [blame] | 7451 | slow_path = new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathARMVIXL(instruction, ref); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 7452 | } |
| 7453 | AddSlowPath(slow_path); |
| 7454 | |
Roland Levillain | 35345a5 | 2017-02-27 14:32:08 +0000 | [diff] [blame] | 7455 | // if (rb_state == ReadBarrier::GrayState()) |
| 7456 | // ref = ReadBarrier::Mark(ref); |
| 7457 | // Given the numeric representation, it's enough to check the low bit of the |
| 7458 | // rb_state. We do that by shifting the bit out of the lock word with LSRS |
| 7459 | // which can be a 16-bit instruction unlike the TST immediate. |
| 7460 | static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0"); |
| 7461 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
| 7462 | __ Lsrs(temp_reg, temp_reg, LockWord::kReadBarrierStateShift + 1); |
| 7463 | __ B(cs, slow_path->GetEntryLabel()); // Carry flag is the last bit shifted out by LSRS. |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 7464 | __ Bind(slow_path->GetExitLabel()); |
Roland Levillain | 844e653 | 2016-11-03 16:09:47 +0000 | [diff] [blame] | 7465 | } |
| 7466 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 7467 | void CodeGeneratorARMVIXL::GenerateReadBarrierSlow(HInstruction* instruction, |
| 7468 | Location out, |
| 7469 | Location ref, |
| 7470 | Location obj, |
| 7471 | uint32_t offset, |
| 7472 | Location index) { |
| 7473 | DCHECK(kEmitCompilerReadBarrier); |
| 7474 | |
| 7475 | // Insert a slow path based read barrier *after* the reference load. |
| 7476 | // |
| 7477 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 7478 | // reference will be carried out by the runtime within the slow |
| 7479 | // path. |
| 7480 | // |
| 7481 | // Note that `ref` currently does not get unpoisoned (when heap |
| 7482 | // poisoning is enabled), which is alright as the `ref` argument is |
| 7483 | // not used by the artReadBarrierSlow entry point. |
| 7484 | // |
| 7485 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
| 7486 | SlowPathCodeARMVIXL* slow_path = new (GetGraph()->GetArena()) |
| 7487 | ReadBarrierForHeapReferenceSlowPathARMVIXL(instruction, out, ref, obj, offset, index); |
| 7488 | AddSlowPath(slow_path); |
| 7489 | |
| 7490 | __ B(slow_path->GetEntryLabel()); |
| 7491 | __ Bind(slow_path->GetExitLabel()); |
| 7492 | } |
| 7493 | |
| 7494 | void CodeGeneratorARMVIXL::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7495 | Location out, |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 7496 | Location ref, |
| 7497 | Location obj, |
| 7498 | uint32_t offset, |
| 7499 | Location index) { |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7500 | if (kEmitCompilerReadBarrier) { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 7501 | // Baker's read barriers shall be handled by the fast path |
| 7502 | // (CodeGeneratorARM::GenerateReferenceLoadWithBakerReadBarrier). |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7503 | DCHECK(!kUseBakerReadBarrier); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 7504 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 7505 | // by the runtime within the slow path. |
| 7506 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7507 | } else if (kPoisonHeapReferences) { |
| 7508 | GetAssembler()->UnpoisonHeapReference(RegisterFrom(out)); |
| 7509 | } |
| 7510 | } |
| 7511 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 7512 | void CodeGeneratorARMVIXL::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 7513 | Location out, |
| 7514 | Location root) { |
| 7515 | DCHECK(kEmitCompilerReadBarrier); |
| 7516 | |
| 7517 | // Insert a slow path based read barrier *after* the GC root load. |
| 7518 | // |
| 7519 | // Note that GC roots are not affected by heap poisoning, so we do |
| 7520 | // not need to do anything special for this here. |
| 7521 | SlowPathCodeARMVIXL* slow_path = |
| 7522 | new (GetGraph()->GetArena()) ReadBarrierForRootSlowPathARMVIXL(instruction, out, root); |
| 7523 | AddSlowPath(slow_path); |
| 7524 | |
| 7525 | __ B(slow_path->GetEntryLabel()); |
| 7526 | __ Bind(slow_path->GetExitLabel()); |
| 7527 | } |
| 7528 | |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7529 | // Check if the desired_dispatch_info is supported. If it is, return it, |
| 7530 | // otherwise return a fall-back info that should be used instead. |
| 7531 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorARMVIXL::GetSupportedInvokeStaticOrDirectDispatch( |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7532 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
Nicolas Geoffray | c1a42cf | 2016-12-18 15:52:36 +0000 | [diff] [blame] | 7533 | HInvokeStaticOrDirect* invoke ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | e807ff7 | 2017-01-23 09:03:12 +0000 | [diff] [blame] | 7534 | return desired_dispatch_info; |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7535 | } |
| 7536 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7537 | vixl32::Register CodeGeneratorARMVIXL::GetInvokeStaticOrDirectExtraParameter( |
| 7538 | HInvokeStaticOrDirect* invoke, vixl32::Register temp) { |
| 7539 | DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
| 7540 | Location location = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
| 7541 | if (!invoke->GetLocations()->Intrinsified()) { |
| 7542 | return RegisterFrom(location); |
| 7543 | } |
| 7544 | // For intrinsics we allow any location, so it may be on the stack. |
| 7545 | if (!location.IsRegister()) { |
| 7546 | GetAssembler()->LoadFromOffset(kLoadWord, temp, sp, location.GetStackIndex()); |
| 7547 | return temp; |
| 7548 | } |
| 7549 | // For register locations, check if the register was saved. If so, get it from the stack. |
| 7550 | // Note: There is a chance that the register was saved but not overwritten, so we could |
| 7551 | // save one load. However, since this is just an intrinsic slow path we prefer this |
| 7552 | // simple and more robust approach rather that trying to determine if that's the case. |
| 7553 | SlowPathCode* slow_path = GetCurrentSlowPath(); |
Scott Wakeling | d5cd497 | 2017-02-03 11:38:35 +0000 | [diff] [blame] | 7554 | if (slow_path != nullptr && slow_path->IsCoreRegisterSaved(RegisterFrom(location).GetCode())) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7555 | int stack_offset = slow_path->GetStackOffsetOfCoreRegister(RegisterFrom(location).GetCode()); |
| 7556 | GetAssembler()->LoadFromOffset(kLoadWord, temp, sp, stack_offset); |
| 7557 | return temp; |
| 7558 | } |
| 7559 | return RegisterFrom(location); |
| 7560 | } |
| 7561 | |
TatWai Chong | d8c052a | 2016-11-02 16:12:48 +0800 | [diff] [blame] | 7562 | Location CodeGeneratorARMVIXL::GenerateCalleeMethodStaticOrDirectCall( |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7563 | HInvokeStaticOrDirect* invoke, Location temp) { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7564 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7565 | switch (invoke->GetMethodLoadKind()) { |
| 7566 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: { |
| 7567 | uint32_t offset = |
| 7568 | GetThreadOffset<kArmPointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
| 7569 | // temp = thread->string_init_entrypoint |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7570 | GetAssembler()->LoadFromOffset(kLoadWord, RegisterFrom(temp), tr, offset); |
| 7571 | break; |
| 7572 | } |
| 7573 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
| 7574 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
| 7575 | break; |
| 7576 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 7577 | __ Mov(RegisterFrom(temp), Operand::From(invoke->GetMethodAddress())); |
| 7578 | break; |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7579 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: { |
| 7580 | HArmDexCacheArraysBase* base = |
| 7581 | invoke->InputAt(invoke->GetSpecialInputIndex())->AsArmDexCacheArraysBase(); |
| 7582 | vixl32::Register base_reg = GetInvokeStaticOrDirectExtraParameter(invoke, RegisterFrom(temp)); |
| 7583 | int32_t offset = invoke->GetDexCacheArrayOffset() - base->GetElementOffset(); |
| 7584 | GetAssembler()->LoadFromOffset(kLoadWord, RegisterFrom(temp), base_reg, offset); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7585 | break; |
| 7586 | } |
| 7587 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: { |
| 7588 | Location current_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
| 7589 | vixl32::Register method_reg; |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7590 | vixl32::Register reg = RegisterFrom(temp); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7591 | if (current_method.IsRegister()) { |
| 7592 | method_reg = RegisterFrom(current_method); |
| 7593 | } else { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7594 | DCHECK(invoke->GetLocations()->Intrinsified()); |
| 7595 | DCHECK(!current_method.IsValid()); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7596 | method_reg = reg; |
| 7597 | GetAssembler()->LoadFromOffset(kLoadWord, reg, sp, kCurrentMethodStackOffset); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7598 | } |
| 7599 | // /* ArtMethod*[] */ temp = temp.ptr_sized_fields_->dex_cache_resolved_methods_; |
| 7600 | GetAssembler()->LoadFromOffset( |
| 7601 | kLoadWord, |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7602 | reg, |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7603 | method_reg, |
| 7604 | ArtMethod::DexCacheResolvedMethodsOffset(kArmPointerSize).Int32Value()); |
| 7605 | // temp = temp[index_in_cache]; |
| 7606 | // Note: Don't use invoke->GetTargetMethod() as it may point to a different dex file. |
| 7607 | uint32_t index_in_cache = invoke->GetDexMethodIndex(); |
| 7608 | GetAssembler()->LoadFromOffset( |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7609 | kLoadWord, reg, reg, CodeGenerator::GetCachePointerOffset(index_in_cache)); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7610 | break; |
| 7611 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7612 | } |
TatWai Chong | d8c052a | 2016-11-02 16:12:48 +0800 | [diff] [blame] | 7613 | return callee_method; |
| 7614 | } |
| 7615 | |
| 7616 | void CodeGeneratorARMVIXL::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, |
| 7617 | Location temp) { |
| 7618 | Location callee_method = GenerateCalleeMethodStaticOrDirectCall(invoke, temp); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7619 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7620 | switch (invoke->GetCodePtrLocation()) { |
| 7621 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 7622 | __ Bl(GetFrameEntryLabel()); |
| 7623 | break; |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7624 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 7625 | // LR = callee_method->entry_point_from_quick_compiled_code_ |
| 7626 | GetAssembler()->LoadFromOffset( |
| 7627 | kLoadWord, |
| 7628 | lr, |
| 7629 | RegisterFrom(callee_method), |
| 7630 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize).Int32Value()); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 7631 | { |
| 7632 | // 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] | 7633 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 7634 | vixl32::k16BitT32InstructionSizeInBytes, |
| 7635 | CodeBufferCheckScope::kExactSize); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 7636 | // LR() |
| 7637 | __ blx(lr); |
| 7638 | } |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7639 | break; |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7640 | } |
| 7641 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7642 | DCHECK(!IsLeafMethod()); |
| 7643 | } |
| 7644 | |
| 7645 | void CodeGeneratorARMVIXL::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_location) { |
| 7646 | vixl32::Register temp = RegisterFrom(temp_location); |
| 7647 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 7648 | invoke->GetVTableIndex(), kArmPointerSize).Uint32Value(); |
| 7649 | |
| 7650 | // Use the calling convention instead of the location of the receiver, as |
| 7651 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 7652 | // slow path, the arguments have been moved to the right place, so here we are |
| 7653 | // guaranteed that the receiver is the first register of the calling convention. |
| 7654 | InvokeDexCallingConventionARMVIXL calling_convention; |
| 7655 | vixl32::Register receiver = calling_convention.GetRegisterAt(0); |
| 7656 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 7657 | { |
| 7658 | // Make sure the pc is recorded immediately after the `ldr` instruction. |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 7659 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 7660 | vixl32::kMaxInstructionSizeInBytes, |
| 7661 | CodeBufferCheckScope::kMaximumSize); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 7662 | // /* HeapReference<Class> */ temp = receiver->klass_ |
| 7663 | __ ldr(temp, MemOperand(receiver, class_offset)); |
| 7664 | MaybeRecordImplicitNullCheck(invoke); |
| 7665 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7666 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 7667 | // emit a read barrier for the previous class reference load. |
| 7668 | // However this is not required in practice, as this is an |
| 7669 | // intermediate/temporary reference and because the current |
| 7670 | // concurrent copying collector keeps the from-space memory |
| 7671 | // intact/accessible until the end of the marking phase (the |
| 7672 | // concurrent copying collector may not in the future). |
| 7673 | GetAssembler()->MaybeUnpoisonHeapReference(temp); |
| 7674 | |
| 7675 | // temp = temp->GetMethodAt(method_offset); |
| 7676 | uint32_t entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
| 7677 | kArmPointerSize).Int32Value(); |
| 7678 | GetAssembler()->LoadFromOffset(kLoadWord, temp, temp, method_offset); |
| 7679 | // LR = temp->GetEntryPoint(); |
| 7680 | GetAssembler()->LoadFromOffset(kLoadWord, lr, temp, entry_point); |
| 7681 | // LR(); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 7682 | // This `blx` *must* be the *last* instruction generated by this stub, so that calls to |
| 7683 | // `RecordPcInfo()` immediately following record the correct pc. Use a scope to help guarantee |
| 7684 | // that. |
| 7685 | // 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] | 7686 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 7687 | vixl32::k16BitT32InstructionSizeInBytes, |
| 7688 | CodeBufferCheckScope::kExactSize); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 7689 | __ blx(lr); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7690 | } |
| 7691 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7692 | CodeGeneratorARMVIXL::PcRelativePatchInfo* CodeGeneratorARMVIXL::NewPcRelativeStringPatch( |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7693 | const DexFile& dex_file, dex::StringIndex string_index) { |
| 7694 | return NewPcRelativePatch(dex_file, string_index.index_, &pc_relative_string_patches_); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7695 | } |
| 7696 | |
| 7697 | CodeGeneratorARMVIXL::PcRelativePatchInfo* CodeGeneratorARMVIXL::NewPcRelativeTypePatch( |
| 7698 | const DexFile& dex_file, dex::TypeIndex type_index) { |
| 7699 | return NewPcRelativePatch(dex_file, type_index.index_, &pc_relative_type_patches_); |
| 7700 | } |
| 7701 | |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 7702 | CodeGeneratorARMVIXL::PcRelativePatchInfo* CodeGeneratorARMVIXL::NewTypeBssEntryPatch( |
| 7703 | const DexFile& dex_file, dex::TypeIndex type_index) { |
| 7704 | return NewPcRelativePatch(dex_file, type_index.index_, &type_bss_entry_patches_); |
| 7705 | } |
| 7706 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7707 | CodeGeneratorARMVIXL::PcRelativePatchInfo* CodeGeneratorARMVIXL::NewPcRelativeDexCacheArrayPatch( |
| 7708 | const DexFile& dex_file, uint32_t element_offset) { |
| 7709 | return NewPcRelativePatch(dex_file, element_offset, &pc_relative_dex_cache_patches_); |
| 7710 | } |
| 7711 | |
| 7712 | CodeGeneratorARMVIXL::PcRelativePatchInfo* CodeGeneratorARMVIXL::NewPcRelativePatch( |
| 7713 | const DexFile& dex_file, uint32_t offset_or_index, ArenaDeque<PcRelativePatchInfo>* patches) { |
| 7714 | patches->emplace_back(dex_file, offset_or_index); |
| 7715 | return &patches->back(); |
| 7716 | } |
| 7717 | |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 7718 | VIXLUInt32Literal* CodeGeneratorARMVIXL::DeduplicateBootImageStringLiteral( |
| 7719 | const DexFile& dex_file, |
| 7720 | dex::StringIndex string_index) { |
| 7721 | return boot_image_string_patches_.GetOrCreate( |
| 7722 | StringReference(&dex_file, string_index), |
| 7723 | [this]() { |
| 7724 | return GetAssembler()->CreateLiteralDestroyedWithPool<uint32_t>(/* placeholder */ 0u); |
| 7725 | }); |
| 7726 | } |
| 7727 | |
| 7728 | VIXLUInt32Literal* CodeGeneratorARMVIXL::DeduplicateBootImageTypeLiteral( |
| 7729 | const DexFile& dex_file, |
| 7730 | dex::TypeIndex type_index) { |
| 7731 | return boot_image_type_patches_.GetOrCreate( |
| 7732 | TypeReference(&dex_file, type_index), |
| 7733 | [this]() { |
| 7734 | return GetAssembler()->CreateLiteralDestroyedWithPool<uint32_t>(/* placeholder */ 0u); |
| 7735 | }); |
| 7736 | } |
| 7737 | |
| 7738 | VIXLUInt32Literal* CodeGeneratorARMVIXL::DeduplicateBootImageAddressLiteral(uint32_t address) { |
Richard Uhler | c52f303 | 2017-03-02 13:45:45 +0000 | [diff] [blame^] | 7739 | return DeduplicateUint32Literal(dchecked_integral_cast<uint32_t>(address), &uint32_literals_); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 7740 | } |
| 7741 | |
| 7742 | VIXLUInt32Literal* CodeGeneratorARMVIXL::DeduplicateDexCacheAddressLiteral(uint32_t address) { |
| 7743 | return DeduplicateUint32Literal(address, &uint32_literals_); |
| 7744 | } |
| 7745 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 7746 | VIXLUInt32Literal* CodeGeneratorARMVIXL::DeduplicateJitStringLiteral( |
| 7747 | const DexFile& dex_file, |
| 7748 | dex::StringIndex string_index, |
| 7749 | Handle<mirror::String> handle) { |
| 7750 | jit_string_roots_.Overwrite(StringReference(&dex_file, string_index), |
| 7751 | reinterpret_cast64<uint64_t>(handle.GetReference())); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 7752 | return jit_string_patches_.GetOrCreate( |
| 7753 | StringReference(&dex_file, string_index), |
| 7754 | [this]() { |
| 7755 | return GetAssembler()->CreateLiteralDestroyedWithPool<uint32_t>(/* placeholder */ 0u); |
| 7756 | }); |
| 7757 | } |
| 7758 | |
| 7759 | VIXLUInt32Literal* CodeGeneratorARMVIXL::DeduplicateJitClassLiteral(const DexFile& dex_file, |
| 7760 | dex::TypeIndex type_index, |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 7761 | Handle<mirror::Class> handle) { |
| 7762 | jit_class_roots_.Overwrite(TypeReference(&dex_file, type_index), |
| 7763 | reinterpret_cast64<uint64_t>(handle.GetReference())); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 7764 | return jit_class_patches_.GetOrCreate( |
| 7765 | TypeReference(&dex_file, type_index), |
| 7766 | [this]() { |
| 7767 | return GetAssembler()->CreateLiteralDestroyedWithPool<uint32_t>(/* placeholder */ 0u); |
| 7768 | }); |
| 7769 | } |
| 7770 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7771 | template <LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
| 7772 | inline void CodeGeneratorARMVIXL::EmitPcRelativeLinkerPatches( |
| 7773 | const ArenaDeque<PcRelativePatchInfo>& infos, |
| 7774 | ArenaVector<LinkerPatch>* linker_patches) { |
| 7775 | for (const PcRelativePatchInfo& info : infos) { |
| 7776 | const DexFile& dex_file = info.target_dex_file; |
| 7777 | size_t offset_or_index = info.offset_or_index; |
| 7778 | DCHECK(info.add_pc_label.IsBound()); |
| 7779 | uint32_t add_pc_offset = dchecked_integral_cast<uint32_t>(info.add_pc_label.GetLocation()); |
| 7780 | // Add MOVW patch. |
| 7781 | DCHECK(info.movw_label.IsBound()); |
| 7782 | uint32_t movw_offset = dchecked_integral_cast<uint32_t>(info.movw_label.GetLocation()); |
| 7783 | linker_patches->push_back(Factory(movw_offset, &dex_file, add_pc_offset, offset_or_index)); |
| 7784 | // Add MOVT patch. |
| 7785 | DCHECK(info.movt_label.IsBound()); |
| 7786 | uint32_t movt_offset = dchecked_integral_cast<uint32_t>(info.movt_label.GetLocation()); |
| 7787 | linker_patches->push_back(Factory(movt_offset, &dex_file, add_pc_offset, offset_or_index)); |
| 7788 | } |
| 7789 | } |
| 7790 | |
| 7791 | void CodeGeneratorARMVIXL::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) { |
| 7792 | DCHECK(linker_patches->empty()); |
| 7793 | size_t size = |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7794 | /* MOVW+MOVT for each entry */ 2u * pc_relative_dex_cache_patches_.size() + |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 7795 | boot_image_string_patches_.size() + |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7796 | /* MOVW+MOVT for each entry */ 2u * pc_relative_string_patches_.size() + |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 7797 | boot_image_type_patches_.size() + |
| 7798 | /* MOVW+MOVT for each entry */ 2u * pc_relative_type_patches_.size() + |
Richard Uhler | c52f303 | 2017-03-02 13:45:45 +0000 | [diff] [blame^] | 7799 | /* MOVW+MOVT for each entry */ 2u * type_bss_entry_patches_.size(); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7800 | linker_patches->reserve(size); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7801 | EmitPcRelativeLinkerPatches<LinkerPatch::DexCacheArrayPatch>(pc_relative_dex_cache_patches_, |
| 7802 | linker_patches); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 7803 | for (const auto& entry : boot_image_string_patches_) { |
| 7804 | const StringReference& target_string = entry.first; |
| 7805 | VIXLUInt32Literal* literal = entry.second; |
| 7806 | DCHECK(literal->IsBound()); |
| 7807 | uint32_t literal_offset = literal->GetLocation(); |
| 7808 | linker_patches->push_back(LinkerPatch::StringPatch(literal_offset, |
| 7809 | target_string.dex_file, |
| 7810 | target_string.string_index.index_)); |
| 7811 | } |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7812 | if (!GetCompilerOptions().IsBootImage()) { |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 7813 | DCHECK(pc_relative_type_patches_.empty()); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7814 | EmitPcRelativeLinkerPatches<LinkerPatch::StringBssEntryPatch>(pc_relative_string_patches_, |
| 7815 | linker_patches); |
| 7816 | } else { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7817 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeTypePatch>(pc_relative_type_patches_, |
| 7818 | linker_patches); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7819 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeStringPatch>(pc_relative_string_patches_, |
| 7820 | linker_patches); |
| 7821 | } |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 7822 | EmitPcRelativeLinkerPatches<LinkerPatch::TypeBssEntryPatch>(type_bss_entry_patches_, |
| 7823 | linker_patches); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 7824 | for (const auto& entry : boot_image_type_patches_) { |
| 7825 | const TypeReference& target_type = entry.first; |
| 7826 | VIXLUInt32Literal* literal = entry.second; |
| 7827 | DCHECK(literal->IsBound()); |
| 7828 | uint32_t literal_offset = literal->GetLocation(); |
| 7829 | linker_patches->push_back(LinkerPatch::TypePatch(literal_offset, |
| 7830 | target_type.dex_file, |
| 7831 | target_type.type_index.index_)); |
| 7832 | } |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 7833 | DCHECK_EQ(size, linker_patches->size()); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 7834 | } |
| 7835 | |
| 7836 | VIXLUInt32Literal* CodeGeneratorARMVIXL::DeduplicateUint32Literal( |
| 7837 | uint32_t value, |
| 7838 | Uint32ToLiteralMap* map) { |
| 7839 | return map->GetOrCreate( |
| 7840 | value, |
| 7841 | [this, value]() { |
| 7842 | return GetAssembler()->CreateLiteralDestroyedWithPool<uint32_t>(/* placeholder */ value); |
| 7843 | }); |
| 7844 | } |
| 7845 | |
| 7846 | VIXLUInt32Literal* CodeGeneratorARMVIXL::DeduplicateMethodLiteral( |
| 7847 | MethodReference target_method, |
| 7848 | MethodToLiteralMap* map) { |
| 7849 | return map->GetOrCreate( |
| 7850 | target_method, |
| 7851 | [this]() { |
| 7852 | return GetAssembler()->CreateLiteralDestroyedWithPool<uint32_t>(/* placeholder */ 0u); |
| 7853 | }); |
| 7854 | } |
| 7855 | |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 7856 | void LocationsBuilderARMVIXL::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
| 7857 | LocationSummary* locations = |
| 7858 | new (GetGraph()->GetArena()) LocationSummary(instr, LocationSummary::kNoCall); |
| 7859 | locations->SetInAt(HMultiplyAccumulate::kInputAccumulatorIndex, |
| 7860 | Location::RequiresRegister()); |
| 7861 | locations->SetInAt(HMultiplyAccumulate::kInputMulLeftIndex, Location::RequiresRegister()); |
| 7862 | locations->SetInAt(HMultiplyAccumulate::kInputMulRightIndex, Location::RequiresRegister()); |
| 7863 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 7864 | } |
| 7865 | |
| 7866 | void InstructionCodeGeneratorARMVIXL::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
| 7867 | vixl32::Register res = OutputRegister(instr); |
| 7868 | vixl32::Register accumulator = |
| 7869 | InputRegisterAt(instr, HMultiplyAccumulate::kInputAccumulatorIndex); |
| 7870 | vixl32::Register mul_left = |
| 7871 | InputRegisterAt(instr, HMultiplyAccumulate::kInputMulLeftIndex); |
| 7872 | vixl32::Register mul_right = |
| 7873 | InputRegisterAt(instr, HMultiplyAccumulate::kInputMulRightIndex); |
| 7874 | |
| 7875 | if (instr->GetOpKind() == HInstruction::kAdd) { |
| 7876 | __ Mla(res, mul_left, mul_right, accumulator); |
| 7877 | } else { |
| 7878 | __ Mls(res, mul_left, mul_right, accumulator); |
| 7879 | } |
| 7880 | } |
| 7881 | |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 7882 | void LocationsBuilderARMVIXL::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
| 7883 | // Nothing to do, this should be removed during prepare for register allocator. |
| 7884 | LOG(FATAL) << "Unreachable"; |
| 7885 | } |
| 7886 | |
| 7887 | void InstructionCodeGeneratorARMVIXL::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
| 7888 | // Nothing to do, this should be removed during prepare for register allocator. |
| 7889 | LOG(FATAL) << "Unreachable"; |
| 7890 | } |
| 7891 | |
| 7892 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 7893 | void LocationsBuilderARMVIXL::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 7894 | LocationSummary* locations = |
| 7895 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 7896 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7897 | if (switch_instr->GetNumEntries() > kPackedSwitchCompareJumpThreshold && |
| 7898 | codegen_->GetAssembler()->GetVIXLAssembler()->IsUsingT32()) { |
| 7899 | locations->AddTemp(Location::RequiresRegister()); // We need a temp for the table base. |
| 7900 | if (switch_instr->GetStartValue() != 0) { |
| 7901 | locations->AddTemp(Location::RequiresRegister()); // We need a temp for the bias. |
| 7902 | } |
| 7903 | } |
| 7904 | } |
| 7905 | |
| 7906 | // TODO(VIXL): Investigate and reach the parity with old arm codegen. |
| 7907 | void InstructionCodeGeneratorARMVIXL::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 7908 | int32_t lower_bound = switch_instr->GetStartValue(); |
| 7909 | uint32_t num_entries = switch_instr->GetNumEntries(); |
| 7910 | LocationSummary* locations = switch_instr->GetLocations(); |
| 7911 | vixl32::Register value_reg = InputRegisterAt(switch_instr, 0); |
| 7912 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 7913 | |
| 7914 | if (num_entries <= kPackedSwitchCompareJumpThreshold || |
| 7915 | !codegen_->GetAssembler()->GetVIXLAssembler()->IsUsingT32()) { |
| 7916 | // Create a series of compare/jumps. |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 7917 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 7918 | vixl32::Register temp_reg = temps.Acquire(); |
| 7919 | // Note: It is fine for the below AddConstantSetFlags() using IP register to temporarily store |
| 7920 | // the immediate, because IP is used as the destination register. For the other |
| 7921 | // AddConstantSetFlags() and GenerateCompareWithImmediate(), the immediate values are constant, |
| 7922 | // and they can be encoded in the instruction without making use of IP register. |
| 7923 | __ Adds(temp_reg, value_reg, -lower_bound); |
| 7924 | |
| 7925 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
| 7926 | // Jump to successors[0] if value == lower_bound. |
| 7927 | __ B(eq, codegen_->GetLabelOf(successors[0])); |
| 7928 | int32_t last_index = 0; |
| 7929 | for (; num_entries - last_index > 2; last_index += 2) { |
| 7930 | __ Adds(temp_reg, temp_reg, -2); |
| 7931 | // Jump to successors[last_index + 1] if value < case_value[last_index + 2]. |
| 7932 | __ B(lo, codegen_->GetLabelOf(successors[last_index + 1])); |
| 7933 | // Jump to successors[last_index + 2] if value == case_value[last_index + 2]. |
| 7934 | __ B(eq, codegen_->GetLabelOf(successors[last_index + 2])); |
| 7935 | } |
| 7936 | if (num_entries - last_index == 2) { |
| 7937 | // The last missing case_value. |
| 7938 | __ Cmp(temp_reg, 1); |
| 7939 | __ B(eq, codegen_->GetLabelOf(successors[last_index + 1])); |
| 7940 | } |
| 7941 | |
| 7942 | // And the default for any other value. |
| 7943 | if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) { |
| 7944 | __ B(codegen_->GetLabelOf(default_block)); |
| 7945 | } |
| 7946 | } else { |
| 7947 | // Create a table lookup. |
| 7948 | vixl32::Register table_base = RegisterFrom(locations->GetTemp(0)); |
| 7949 | |
| 7950 | JumpTableARMVIXL* jump_table = codegen_->CreateJumpTable(switch_instr); |
| 7951 | |
| 7952 | // Remove the bias. |
| 7953 | vixl32::Register key_reg; |
| 7954 | if (lower_bound != 0) { |
| 7955 | key_reg = RegisterFrom(locations->GetTemp(1)); |
| 7956 | __ Sub(key_reg, value_reg, lower_bound); |
| 7957 | } else { |
| 7958 | key_reg = value_reg; |
| 7959 | } |
| 7960 | |
| 7961 | // Check whether the value is in the table, jump to default block if not. |
| 7962 | __ Cmp(key_reg, num_entries - 1); |
| 7963 | __ B(hi, codegen_->GetLabelOf(default_block)); |
| 7964 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 7965 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 7966 | vixl32::Register jump_offset = temps.Acquire(); |
| 7967 | |
| 7968 | // Load jump offset from the table. |
Scott Wakeling | 86e9d26 | 2017-01-18 15:59:24 +0000 | [diff] [blame] | 7969 | { |
| 7970 | const size_t jump_size = switch_instr->GetNumEntries() * sizeof(int32_t); |
| 7971 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 7972 | (vixl32::kMaxInstructionSizeInBytes * 4) + jump_size, |
| 7973 | CodeBufferCheckScope::kMaximumSize); |
| 7974 | __ adr(table_base, jump_table->GetTableStartLabel()); |
| 7975 | __ ldr(jump_offset, MemOperand(table_base, key_reg, vixl32::LSL, 2)); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 7976 | |
Scott Wakeling | 86e9d26 | 2017-01-18 15:59:24 +0000 | [diff] [blame] | 7977 | // Jump to target block by branching to table_base(pc related) + offset. |
| 7978 | vixl32::Register target_address = table_base; |
| 7979 | __ add(target_address, table_base, jump_offset); |
| 7980 | __ bx(target_address); |
Artem Serov | 09a940d | 2016-11-11 16:15:11 +0000 | [diff] [blame] | 7981 | |
Scott Wakeling | 86e9d26 | 2017-01-18 15:59:24 +0000 | [diff] [blame] | 7982 | jump_table->EmitTable(codegen_); |
| 7983 | } |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 7984 | } |
| 7985 | } |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7986 | void LocationsBuilderARMVIXL::VisitArmDexCacheArraysBase(HArmDexCacheArraysBase* base) { |
| 7987 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(base); |
| 7988 | locations->SetOut(Location::RequiresRegister()); |
| 7989 | } |
| 7990 | |
| 7991 | void InstructionCodeGeneratorARMVIXL::VisitArmDexCacheArraysBase(HArmDexCacheArraysBase* base) { |
| 7992 | vixl32::Register base_reg = OutputRegister(base); |
| 7993 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels = |
| 7994 | codegen_->NewPcRelativeDexCacheArrayPatch(base->GetDexFile(), base->GetElementOffset()); |
| 7995 | codegen_->EmitMovwMovtPlaceholder(labels, base_reg); |
| 7996 | } |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 7997 | |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7998 | // Copy the result of a call into the given target. |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7999 | void CodeGeneratorARMVIXL::MoveFromReturnRegister(Location trg, Primitive::Type type) { |
| 8000 | if (!trg.IsValid()) { |
| 8001 | DCHECK_EQ(type, Primitive::kPrimVoid); |
| 8002 | return; |
| 8003 | } |
| 8004 | |
| 8005 | DCHECK_NE(type, Primitive::kPrimVoid); |
| 8006 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8007 | Location return_loc = InvokeDexCallingConventionVisitorARMVIXL().GetReturnLocation(type); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8008 | if (return_loc.Equals(trg)) { |
| 8009 | return; |
| 8010 | } |
| 8011 | |
| 8012 | // TODO: Consider pairs in the parallel move resolver, then this could be nicely merged |
| 8013 | // with the last branch. |
| 8014 | if (type == Primitive::kPrimLong) { |
| 8015 | TODO_VIXL32(FATAL); |
| 8016 | } else if (type == Primitive::kPrimDouble) { |
| 8017 | TODO_VIXL32(FATAL); |
| 8018 | } else { |
| 8019 | // Let the parallel move resolver take care of all of this. |
| 8020 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 8021 | parallel_move.AddMove(return_loc, trg, type, nullptr); |
| 8022 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 8023 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 8024 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8025 | |
xueliang.zhong | 8d2c459 | 2016-11-23 17:05:25 +0000 | [diff] [blame] | 8026 | void LocationsBuilderARMVIXL::VisitClassTableGet(HClassTableGet* instruction) { |
| 8027 | LocationSummary* locations = |
| 8028 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 8029 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8030 | locations->SetOut(Location::RequiresRegister()); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 8031 | } |
| 8032 | |
xueliang.zhong | 8d2c459 | 2016-11-23 17:05:25 +0000 | [diff] [blame] | 8033 | void InstructionCodeGeneratorARMVIXL::VisitClassTableGet(HClassTableGet* instruction) { |
| 8034 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
| 8035 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 8036 | instruction->GetIndex(), kArmPointerSize).SizeValue(); |
| 8037 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 8038 | OutputRegister(instruction), |
| 8039 | InputRegisterAt(instruction, 0), |
| 8040 | method_offset); |
| 8041 | } else { |
| 8042 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
| 8043 | instruction->GetIndex(), kArmPointerSize)); |
| 8044 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 8045 | OutputRegister(instruction), |
| 8046 | InputRegisterAt(instruction, 0), |
| 8047 | mirror::Class::ImtPtrOffset(kArmPointerSize).Uint32Value()); |
| 8048 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 8049 | OutputRegister(instruction), |
| 8050 | OutputRegister(instruction), |
| 8051 | method_offset); |
| 8052 | } |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 8053 | } |
| 8054 | |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 8055 | static void PatchJitRootUse(uint8_t* code, |
| 8056 | const uint8_t* roots_data, |
| 8057 | VIXLUInt32Literal* literal, |
| 8058 | uint64_t index_in_table) { |
| 8059 | DCHECK(literal->IsBound()); |
| 8060 | uint32_t literal_offset = literal->GetLocation(); |
| 8061 | uintptr_t address = |
| 8062 | reinterpret_cast<uintptr_t>(roots_data) + index_in_table * sizeof(GcRoot<mirror::Object>); |
| 8063 | uint8_t* data = code + literal_offset; |
| 8064 | reinterpret_cast<uint32_t*>(data)[0] = dchecked_integral_cast<uint32_t>(address); |
| 8065 | } |
| 8066 | |
| 8067 | void CodeGeneratorARMVIXL::EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) { |
| 8068 | for (const auto& entry : jit_string_patches_) { |
| 8069 | const auto& it = jit_string_roots_.find(entry.first); |
| 8070 | DCHECK(it != jit_string_roots_.end()); |
| 8071 | PatchJitRootUse(code, roots_data, entry.second, it->second); |
| 8072 | } |
| 8073 | for (const auto& entry : jit_class_patches_) { |
| 8074 | const auto& it = jit_class_roots_.find(entry.first); |
| 8075 | DCHECK(it != jit_class_roots_.end()); |
| 8076 | PatchJitRootUse(code, roots_data, entry.second, it->second); |
| 8077 | } |
| 8078 | } |
| 8079 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8080 | void CodeGeneratorARMVIXL::EmitMovwMovtPlaceholder( |
| 8081 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels, |
| 8082 | vixl32::Register out) { |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 8083 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 8084 | 3 * vixl32::kMaxInstructionSizeInBytes, |
| 8085 | CodeBufferCheckScope::kMaximumSize); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8086 | // TODO(VIXL): Think about using mov instead of movw. |
| 8087 | __ bind(&labels->movw_label); |
| 8088 | __ movw(out, /* placeholder */ 0u); |
| 8089 | __ bind(&labels->movt_label); |
| 8090 | __ movt(out, /* placeholder */ 0u); |
| 8091 | __ bind(&labels->add_pc_label); |
| 8092 | __ add(out, out, pc); |
| 8093 | } |
| 8094 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8095 | #undef __ |
| 8096 | #undef QUICK_ENTRY_POINT |
| 8097 | #undef TODO_VIXL32 |
| 8098 | |
| 8099 | } // namespace arm |
| 8100 | } // namespace art |