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; |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 49 | using helpers::InputVRegisterAt; |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 50 | using helpers::Int32ConstantFrom; |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 51 | using helpers::LocationFrom; |
| 52 | using helpers::LowRegisterFrom; |
| 53 | using helpers::LowSRegisterFrom; |
| 54 | using helpers::OutputRegister; |
| 55 | using helpers::OutputSRegister; |
| 56 | using helpers::OutputVRegister; |
| 57 | using helpers::RegisterFrom; |
| 58 | using helpers::SRegisterFrom; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 59 | |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 60 | using vixl::ExactAssemblyScope; |
| 61 | using vixl::CodeBufferCheckScope; |
| 62 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 63 | using RegisterList = vixl32::RegisterList; |
| 64 | |
| 65 | static bool ExpectedPairLayout(Location location) { |
| 66 | // We expected this for both core and fpu register pairs. |
| 67 | return ((location.low() & 1) == 0) && (location.low() + 1 == location.high()); |
| 68 | } |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 69 | // Use a local definition to prevent copying mistakes. |
| 70 | static constexpr size_t kArmWordSize = static_cast<size_t>(kArmPointerSize); |
| 71 | static constexpr size_t kArmBitsPerWord = kArmWordSize * kBitsPerByte; |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 72 | static constexpr int kCurrentMethodStackOffset = 0; |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 73 | static constexpr uint32_t kPackedSwitchCompareJumpThreshold = 7; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 74 | |
| 75 | #ifdef __ |
| 76 | #error "ARM Codegen VIXL macro-assembler macro already defined." |
| 77 | #endif |
| 78 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 79 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 80 | #define __ down_cast<CodeGeneratorARMVIXL*>(codegen)->GetVIXLAssembler()-> // NOLINT |
| 81 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kArmPointerSize, x).Int32Value() |
| 82 | |
| 83 | // Marker that code is yet to be, and must, be implemented. |
| 84 | #define TODO_VIXL32(level) LOG(level) << __PRETTY_FUNCTION__ << " unimplemented " |
| 85 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 86 | // SaveLiveRegisters and RestoreLiveRegisters from SlowPathCodeARM operate on sets of S registers, |
| 87 | // for each live D registers they treat two corresponding S registers as live ones. |
| 88 | // |
| 89 | // Two following functions (SaveContiguousSRegisterList, RestoreContiguousSRegisterList) build |
| 90 | // from a list of contiguous S registers a list of contiguous D registers (processing first/last |
| 91 | // S registers corner cases) and save/restore this new list treating them as D registers. |
| 92 | // - decreasing code size |
| 93 | // - avoiding hazards on Cortex-A57, when a pair of S registers for an actual live D register is |
| 94 | // restored and then used in regular non SlowPath code as D register. |
| 95 | // |
| 96 | // For the following example (v means the S register is live): |
| 97 | // D names: | D0 | D1 | D2 | D4 | ... |
| 98 | // S names: | S0 | S1 | S2 | S3 | S4 | S5 | S6 | S7 | ... |
| 99 | // Live? | | v | v | v | v | v | v | | ... |
| 100 | // |
| 101 | // S1 and S6 will be saved/restored independently; D registers list (D1, D2) will be processed |
| 102 | // as D registers. |
| 103 | // |
| 104 | // TODO(VIXL): All this code should be unnecessary once the VIXL AArch32 backend provides helpers |
| 105 | // for lists of floating-point registers. |
| 106 | static size_t SaveContiguousSRegisterList(size_t first, |
| 107 | size_t last, |
| 108 | CodeGenerator* codegen, |
| 109 | size_t stack_offset) { |
| 110 | static_assert(kSRegSizeInBytes == kArmWordSize, "Broken assumption on reg/word sizes."); |
| 111 | static_assert(kDRegSizeInBytes == 2 * kArmWordSize, "Broken assumption on reg/word sizes."); |
| 112 | DCHECK_LE(first, last); |
| 113 | if ((first == last) && (first == 0)) { |
| 114 | __ Vstr(vixl32::SRegister(first), MemOperand(sp, stack_offset)); |
| 115 | return stack_offset + kSRegSizeInBytes; |
| 116 | } |
| 117 | if (first % 2 == 1) { |
| 118 | __ Vstr(vixl32::SRegister(first++), MemOperand(sp, stack_offset)); |
| 119 | stack_offset += kSRegSizeInBytes; |
| 120 | } |
| 121 | |
| 122 | bool save_last = false; |
| 123 | if (last % 2 == 0) { |
| 124 | save_last = true; |
| 125 | --last; |
| 126 | } |
| 127 | |
| 128 | if (first < last) { |
| 129 | vixl32::DRegister d_reg = vixl32::DRegister(first / 2); |
| 130 | DCHECK_EQ((last - first + 1) % 2, 0u); |
| 131 | size_t number_of_d_regs = (last - first + 1) / 2; |
| 132 | |
| 133 | if (number_of_d_regs == 1) { |
| 134 | __ Vstr(d_reg, MemOperand(sp, stack_offset)); |
| 135 | } else if (number_of_d_regs > 1) { |
| 136 | UseScratchRegisterScope temps(down_cast<CodeGeneratorARMVIXL*>(codegen)->GetVIXLAssembler()); |
| 137 | vixl32::Register base = sp; |
| 138 | if (stack_offset != 0) { |
| 139 | base = temps.Acquire(); |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 140 | __ Add(base, sp, Operand::From(stack_offset)); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 141 | } |
| 142 | __ Vstm(F64, base, NO_WRITE_BACK, DRegisterList(d_reg, number_of_d_regs)); |
| 143 | } |
| 144 | stack_offset += number_of_d_regs * kDRegSizeInBytes; |
| 145 | } |
| 146 | |
| 147 | if (save_last) { |
| 148 | __ Vstr(vixl32::SRegister(last + 1), MemOperand(sp, stack_offset)); |
| 149 | stack_offset += kSRegSizeInBytes; |
| 150 | } |
| 151 | |
| 152 | return stack_offset; |
| 153 | } |
| 154 | |
| 155 | static size_t RestoreContiguousSRegisterList(size_t first, |
| 156 | size_t last, |
| 157 | CodeGenerator* codegen, |
| 158 | size_t stack_offset) { |
| 159 | static_assert(kSRegSizeInBytes == kArmWordSize, "Broken assumption on reg/word sizes."); |
| 160 | static_assert(kDRegSizeInBytes == 2 * kArmWordSize, "Broken assumption on reg/word sizes."); |
| 161 | DCHECK_LE(first, last); |
| 162 | if ((first == last) && (first == 0)) { |
| 163 | __ Vldr(vixl32::SRegister(first), MemOperand(sp, stack_offset)); |
| 164 | return stack_offset + kSRegSizeInBytes; |
| 165 | } |
| 166 | if (first % 2 == 1) { |
| 167 | __ Vldr(vixl32::SRegister(first++), MemOperand(sp, stack_offset)); |
| 168 | stack_offset += kSRegSizeInBytes; |
| 169 | } |
| 170 | |
| 171 | bool restore_last = false; |
| 172 | if (last % 2 == 0) { |
| 173 | restore_last = true; |
| 174 | --last; |
| 175 | } |
| 176 | |
| 177 | if (first < last) { |
| 178 | vixl32::DRegister d_reg = vixl32::DRegister(first / 2); |
| 179 | DCHECK_EQ((last - first + 1) % 2, 0u); |
| 180 | size_t number_of_d_regs = (last - first + 1) / 2; |
| 181 | if (number_of_d_regs == 1) { |
| 182 | __ Vldr(d_reg, MemOperand(sp, stack_offset)); |
| 183 | } else if (number_of_d_regs > 1) { |
| 184 | UseScratchRegisterScope temps(down_cast<CodeGeneratorARMVIXL*>(codegen)->GetVIXLAssembler()); |
| 185 | vixl32::Register base = sp; |
| 186 | if (stack_offset != 0) { |
| 187 | base = temps.Acquire(); |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 188 | __ Add(base, sp, Operand::From(stack_offset)); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 189 | } |
| 190 | __ Vldm(F64, base, NO_WRITE_BACK, DRegisterList(d_reg, number_of_d_regs)); |
| 191 | } |
| 192 | stack_offset += number_of_d_regs * kDRegSizeInBytes; |
| 193 | } |
| 194 | |
| 195 | if (restore_last) { |
| 196 | __ Vldr(vixl32::SRegister(last + 1), MemOperand(sp, stack_offset)); |
| 197 | stack_offset += kSRegSizeInBytes; |
| 198 | } |
| 199 | |
| 200 | return stack_offset; |
| 201 | } |
| 202 | |
| 203 | void SlowPathCodeARMVIXL::SaveLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) { |
| 204 | size_t stack_offset = codegen->GetFirstRegisterSlotInSlowPath(); |
| 205 | size_t orig_offset = stack_offset; |
| 206 | |
| 207 | const uint32_t core_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ true); |
| 208 | for (uint32_t i : LowToHighBits(core_spills)) { |
| 209 | // If the register holds an object, update the stack mask. |
| 210 | if (locations->RegisterContainsObject(i)) { |
| 211 | locations->SetStackBit(stack_offset / kVRegSize); |
| 212 | } |
| 213 | DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 214 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 215 | saved_core_stack_offsets_[i] = stack_offset; |
| 216 | stack_offset += kArmWordSize; |
| 217 | } |
| 218 | |
| 219 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 220 | arm_codegen->GetAssembler()->StoreRegisterList(core_spills, orig_offset); |
| 221 | |
| 222 | uint32_t fp_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ false); |
| 223 | orig_offset = stack_offset; |
| 224 | for (uint32_t i : LowToHighBits(fp_spills)) { |
| 225 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 226 | saved_fpu_stack_offsets_[i] = stack_offset; |
| 227 | stack_offset += kArmWordSize; |
| 228 | } |
| 229 | |
| 230 | stack_offset = orig_offset; |
| 231 | while (fp_spills != 0u) { |
| 232 | uint32_t begin = CTZ(fp_spills); |
| 233 | uint32_t tmp = fp_spills + (1u << begin); |
| 234 | fp_spills &= tmp; // Clear the contiguous range of 1s. |
| 235 | uint32_t end = (tmp == 0u) ? 32u : CTZ(tmp); // CTZ(0) is undefined. |
| 236 | stack_offset = SaveContiguousSRegisterList(begin, end - 1, codegen, stack_offset); |
| 237 | } |
| 238 | DCHECK_LE(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 239 | } |
| 240 | |
| 241 | void SlowPathCodeARMVIXL::RestoreLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) { |
| 242 | size_t stack_offset = codegen->GetFirstRegisterSlotInSlowPath(); |
| 243 | size_t orig_offset = stack_offset; |
| 244 | |
| 245 | const uint32_t core_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ true); |
| 246 | for (uint32_t i : LowToHighBits(core_spills)) { |
| 247 | DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 248 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 249 | stack_offset += kArmWordSize; |
| 250 | } |
| 251 | |
| 252 | // TODO(VIXL): Check the coherency of stack_offset after this with a test. |
| 253 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 254 | arm_codegen->GetAssembler()->LoadRegisterList(core_spills, orig_offset); |
| 255 | |
| 256 | uint32_t fp_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ false); |
| 257 | while (fp_spills != 0u) { |
| 258 | uint32_t begin = CTZ(fp_spills); |
| 259 | uint32_t tmp = fp_spills + (1u << begin); |
| 260 | fp_spills &= tmp; // Clear the contiguous range of 1s. |
| 261 | uint32_t end = (tmp == 0u) ? 32u : CTZ(tmp); // CTZ(0) is undefined. |
| 262 | stack_offset = RestoreContiguousSRegisterList(begin, end - 1, codegen, stack_offset); |
| 263 | } |
| 264 | DCHECK_LE(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 265 | } |
| 266 | |
| 267 | class NullCheckSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 268 | public: |
| 269 | explicit NullCheckSlowPathARMVIXL(HNullCheck* instruction) : SlowPathCodeARMVIXL(instruction) {} |
| 270 | |
| 271 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 272 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 273 | __ Bind(GetEntryLabel()); |
| 274 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 275 | // Live registers will be restored in the catch block if caught. |
| 276 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 277 | } |
| 278 | arm_codegen->InvokeRuntime(kQuickThrowNullPointer, |
| 279 | instruction_, |
| 280 | instruction_->GetDexPc(), |
| 281 | this); |
| 282 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); |
| 283 | } |
| 284 | |
| 285 | bool IsFatal() const OVERRIDE { return true; } |
| 286 | |
| 287 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathARMVIXL"; } |
| 288 | |
| 289 | private: |
| 290 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathARMVIXL); |
| 291 | }; |
| 292 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 293 | class DivZeroCheckSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 294 | public: |
| 295 | explicit DivZeroCheckSlowPathARMVIXL(HDivZeroCheck* instruction) |
| 296 | : SlowPathCodeARMVIXL(instruction) {} |
| 297 | |
| 298 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 299 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 300 | __ Bind(GetEntryLabel()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 301 | arm_codegen->InvokeRuntime(kQuickThrowDivZero, instruction_, instruction_->GetDexPc(), this); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 302 | CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); |
| 303 | } |
| 304 | |
| 305 | bool IsFatal() const OVERRIDE { return true; } |
| 306 | |
| 307 | const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathARMVIXL"; } |
| 308 | |
| 309 | private: |
| 310 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathARMVIXL); |
| 311 | }; |
| 312 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 313 | class SuspendCheckSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 314 | public: |
| 315 | SuspendCheckSlowPathARMVIXL(HSuspendCheck* instruction, HBasicBlock* successor) |
| 316 | : SlowPathCodeARMVIXL(instruction), successor_(successor) {} |
| 317 | |
| 318 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 319 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 320 | __ Bind(GetEntryLabel()); |
| 321 | arm_codegen->InvokeRuntime(kQuickTestSuspend, instruction_, instruction_->GetDexPc(), this); |
| 322 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
| 323 | if (successor_ == nullptr) { |
| 324 | __ B(GetReturnLabel()); |
| 325 | } else { |
| 326 | __ B(arm_codegen->GetLabelOf(successor_)); |
| 327 | } |
| 328 | } |
| 329 | |
| 330 | vixl32::Label* GetReturnLabel() { |
| 331 | DCHECK(successor_ == nullptr); |
| 332 | return &return_label_; |
| 333 | } |
| 334 | |
| 335 | HBasicBlock* GetSuccessor() const { |
| 336 | return successor_; |
| 337 | } |
| 338 | |
| 339 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathARMVIXL"; } |
| 340 | |
| 341 | private: |
| 342 | // If not null, the block to branch to after the suspend check. |
| 343 | HBasicBlock* const successor_; |
| 344 | |
| 345 | // If `successor_` is null, the label to branch to after the suspend check. |
| 346 | vixl32::Label return_label_; |
| 347 | |
| 348 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathARMVIXL); |
| 349 | }; |
| 350 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 351 | class BoundsCheckSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 352 | public: |
| 353 | explicit BoundsCheckSlowPathARMVIXL(HBoundsCheck* instruction) |
| 354 | : SlowPathCodeARMVIXL(instruction) {} |
| 355 | |
| 356 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 357 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 358 | LocationSummary* locations = instruction_->GetLocations(); |
| 359 | |
| 360 | __ Bind(GetEntryLabel()); |
| 361 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 362 | // Live registers will be restored in the catch block if caught. |
| 363 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 364 | } |
| 365 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 366 | // move resolver. |
| 367 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 368 | codegen->EmitParallelMoves( |
| 369 | locations->InAt(0), |
| 370 | LocationFrom(calling_convention.GetRegisterAt(0)), |
| 371 | Primitive::kPrimInt, |
| 372 | locations->InAt(1), |
| 373 | LocationFrom(calling_convention.GetRegisterAt(1)), |
| 374 | Primitive::kPrimInt); |
| 375 | QuickEntrypointEnum entrypoint = instruction_->AsBoundsCheck()->IsStringCharAt() |
| 376 | ? kQuickThrowStringBounds |
| 377 | : kQuickThrowArrayBounds; |
| 378 | arm_codegen->InvokeRuntime(entrypoint, instruction_, instruction_->GetDexPc(), this); |
| 379 | CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>(); |
| 380 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
| 381 | } |
| 382 | |
| 383 | bool IsFatal() const OVERRIDE { return true; } |
| 384 | |
| 385 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathARMVIXL"; } |
| 386 | |
| 387 | private: |
| 388 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathARMVIXL); |
| 389 | }; |
| 390 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 391 | class LoadClassSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 392 | public: |
| 393 | LoadClassSlowPathARMVIXL(HLoadClass* cls, HInstruction* at, uint32_t dex_pc, bool do_clinit) |
| 394 | : SlowPathCodeARMVIXL(at), cls_(cls), at_(at), dex_pc_(dex_pc), do_clinit_(do_clinit) { |
| 395 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 396 | } |
| 397 | |
| 398 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 399 | LocationSummary* locations = at_->GetLocations(); |
| 400 | |
| 401 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 402 | __ Bind(GetEntryLabel()); |
| 403 | SaveLiveRegisters(codegen, locations); |
| 404 | |
| 405 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 406 | __ Mov(calling_convention.GetRegisterAt(0), cls_->GetTypeIndex().index_); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 407 | QuickEntrypointEnum entrypoint = do_clinit_ ? kQuickInitializeStaticStorage |
| 408 | : kQuickInitializeType; |
| 409 | arm_codegen->InvokeRuntime(entrypoint, at_, dex_pc_, this); |
| 410 | if (do_clinit_) { |
| 411 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>(); |
| 412 | } else { |
| 413 | CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>(); |
| 414 | } |
| 415 | |
| 416 | // Move the class to the desired location. |
| 417 | Location out = locations->Out(); |
| 418 | if (out.IsValid()) { |
| 419 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
| 420 | arm_codegen->Move32(locations->Out(), LocationFrom(r0)); |
| 421 | } |
| 422 | RestoreLiveRegisters(codegen, locations); |
| 423 | __ B(GetExitLabel()); |
| 424 | } |
| 425 | |
| 426 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathARMVIXL"; } |
| 427 | |
| 428 | private: |
| 429 | // The class this slow path will load. |
| 430 | HLoadClass* const cls_; |
| 431 | |
| 432 | // The instruction where this slow path is happening. |
| 433 | // (Might be the load class or an initialization check). |
| 434 | HInstruction* const at_; |
| 435 | |
| 436 | // The dex PC of `at_`. |
| 437 | const uint32_t dex_pc_; |
| 438 | |
| 439 | // Whether to initialize the class. |
| 440 | const bool do_clinit_; |
| 441 | |
| 442 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathARMVIXL); |
| 443 | }; |
| 444 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 445 | class LoadStringSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 446 | public: |
| 447 | explicit LoadStringSlowPathARMVIXL(HLoadString* instruction) |
| 448 | : SlowPathCodeARMVIXL(instruction) {} |
| 449 | |
| 450 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 451 | LocationSummary* locations = instruction_->GetLocations(); |
| 452 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 453 | HLoadString* load = instruction_->AsLoadString(); |
| 454 | const uint32_t string_index = load->GetStringIndex().index_; |
| 455 | vixl32::Register out = OutputRegister(load); |
| 456 | vixl32::Register temp = RegisterFrom(locations->GetTemp(0)); |
| 457 | constexpr bool call_saves_everything_except_r0 = (!kUseReadBarrier || kUseBakerReadBarrier); |
| 458 | |
| 459 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 460 | __ Bind(GetEntryLabel()); |
| 461 | SaveLiveRegisters(codegen, locations); |
| 462 | |
| 463 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 464 | // In the unlucky case that the `temp` is R0, we preserve the address in `out` across |
| 465 | // the kSaveEverything call (or use `out` for the address after non-kSaveEverything call). |
| 466 | bool temp_is_r0 = (temp.Is(calling_convention.GetRegisterAt(0))); |
| 467 | vixl32::Register entry_address = temp_is_r0 ? out : temp; |
| 468 | DCHECK(!entry_address.Is(calling_convention.GetRegisterAt(0))); |
| 469 | if (call_saves_everything_except_r0 && temp_is_r0) { |
| 470 | __ Mov(entry_address, temp); |
| 471 | } |
| 472 | |
| 473 | __ Mov(calling_convention.GetRegisterAt(0), string_index); |
| 474 | arm_codegen->InvokeRuntime(kQuickResolveString, instruction_, instruction_->GetDexPc(), this); |
| 475 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
| 476 | |
| 477 | // Store the resolved String to the .bss entry. |
| 478 | if (call_saves_everything_except_r0) { |
| 479 | // The string entry address was preserved in `entry_address` thanks to kSaveEverything. |
| 480 | __ Str(r0, MemOperand(entry_address)); |
| 481 | } else { |
| 482 | // For non-Baker read barrier, we need to re-calculate the address of the string entry. |
| 483 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels = |
| 484 | arm_codegen->NewPcRelativeStringPatch(load->GetDexFile(), string_index); |
| 485 | arm_codegen->EmitMovwMovtPlaceholder(labels, out); |
| 486 | __ Str(r0, MemOperand(entry_address)); |
| 487 | } |
| 488 | |
| 489 | arm_codegen->Move32(locations->Out(), LocationFrom(r0)); |
| 490 | RestoreLiveRegisters(codegen, locations); |
| 491 | |
| 492 | __ B(GetExitLabel()); |
| 493 | } |
| 494 | |
| 495 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathARMVIXL"; } |
| 496 | |
| 497 | private: |
| 498 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathARMVIXL); |
| 499 | }; |
| 500 | |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 501 | class TypeCheckSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 502 | public: |
| 503 | TypeCheckSlowPathARMVIXL(HInstruction* instruction, bool is_fatal) |
| 504 | : SlowPathCodeARMVIXL(instruction), is_fatal_(is_fatal) {} |
| 505 | |
| 506 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 507 | LocationSummary* locations = instruction_->GetLocations(); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 508 | DCHECK(instruction_->IsCheckCast() |
| 509 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 510 | |
| 511 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 512 | __ Bind(GetEntryLabel()); |
| 513 | |
| 514 | if (!is_fatal_) { |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 515 | SaveLiveRegisters(codegen, locations); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 516 | } |
| 517 | |
| 518 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 519 | // move resolver. |
| 520 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 521 | |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 522 | codegen->EmitParallelMoves(locations->InAt(0), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 523 | LocationFrom(calling_convention.GetRegisterAt(0)), |
| 524 | Primitive::kPrimNot, |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 525 | locations->InAt(1), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 526 | LocationFrom(calling_convention.GetRegisterAt(1)), |
| 527 | Primitive::kPrimNot); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 528 | if (instruction_->IsInstanceOf()) { |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 529 | arm_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, |
| 530 | instruction_, |
| 531 | instruction_->GetDexPc(), |
| 532 | this); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 533 | CheckEntrypointTypes<kQuickInstanceofNonTrivial, size_t, mirror::Object*, mirror::Class*>(); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 534 | arm_codegen->Move32(locations->Out(), LocationFrom(r0)); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 535 | } else { |
| 536 | DCHECK(instruction_->IsCheckCast()); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 537 | arm_codegen->InvokeRuntime(kQuickCheckInstanceOf, |
| 538 | instruction_, |
| 539 | instruction_->GetDexPc(), |
| 540 | this); |
| 541 | CheckEntrypointTypes<kQuickCheckInstanceOf, void, mirror::Object*, mirror::Class*>(); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 542 | } |
| 543 | |
| 544 | if (!is_fatal_) { |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 545 | RestoreLiveRegisters(codegen, locations); |
| 546 | __ B(GetExitLabel()); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 547 | } |
| 548 | } |
| 549 | |
| 550 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathARMVIXL"; } |
| 551 | |
| 552 | bool IsFatal() const OVERRIDE { return is_fatal_; } |
| 553 | |
| 554 | private: |
| 555 | const bool is_fatal_; |
| 556 | |
| 557 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathARMVIXL); |
| 558 | }; |
| 559 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 560 | class DeoptimizationSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 561 | public: |
| 562 | explicit DeoptimizationSlowPathARMVIXL(HDeoptimize* instruction) |
| 563 | : SlowPathCodeARMVIXL(instruction) {} |
| 564 | |
| 565 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 566 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 567 | __ Bind(GetEntryLabel()); |
| 568 | arm_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this); |
| 569 | CheckEntrypointTypes<kQuickDeoptimize, void, void>(); |
| 570 | } |
| 571 | |
| 572 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathARMVIXL"; } |
| 573 | |
| 574 | private: |
| 575 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathARMVIXL); |
| 576 | }; |
| 577 | |
| 578 | class ArraySetSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 579 | public: |
| 580 | explicit ArraySetSlowPathARMVIXL(HInstruction* instruction) : SlowPathCodeARMVIXL(instruction) {} |
| 581 | |
| 582 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 583 | LocationSummary* locations = instruction_->GetLocations(); |
| 584 | __ Bind(GetEntryLabel()); |
| 585 | SaveLiveRegisters(codegen, locations); |
| 586 | |
| 587 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 588 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 589 | parallel_move.AddMove( |
| 590 | locations->InAt(0), |
| 591 | LocationFrom(calling_convention.GetRegisterAt(0)), |
| 592 | Primitive::kPrimNot, |
| 593 | nullptr); |
| 594 | parallel_move.AddMove( |
| 595 | locations->InAt(1), |
| 596 | LocationFrom(calling_convention.GetRegisterAt(1)), |
| 597 | Primitive::kPrimInt, |
| 598 | nullptr); |
| 599 | parallel_move.AddMove( |
| 600 | locations->InAt(2), |
| 601 | LocationFrom(calling_convention.GetRegisterAt(2)), |
| 602 | Primitive::kPrimNot, |
| 603 | nullptr); |
| 604 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 605 | |
| 606 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 607 | arm_codegen->InvokeRuntime(kQuickAputObject, instruction_, instruction_->GetDexPc(), this); |
| 608 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
| 609 | RestoreLiveRegisters(codegen, locations); |
| 610 | __ B(GetExitLabel()); |
| 611 | } |
| 612 | |
| 613 | const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathARMVIXL"; } |
| 614 | |
| 615 | private: |
| 616 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathARMVIXL); |
| 617 | }; |
| 618 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 619 | // Slow path marking an object reference `ref` during a read |
| 620 | // barrier. The field `obj.field` in the object `obj` holding this |
| 621 | // reference does not get updated by this slow path after marking (see |
| 622 | // ReadBarrierMarkAndUpdateFieldSlowPathARM below for that). |
| 623 | // |
| 624 | // This means that after the execution of this slow path, `ref` will |
| 625 | // always be up-to-date, but `obj.field` may not; i.e., after the |
| 626 | // flip, `ref` will be a to-space reference, but `obj.field` will |
| 627 | // probably still be a from-space reference (unless it gets updated by |
| 628 | // another thread, or if another thread installed another object |
| 629 | // reference (different from `ref`) in `obj.field`). |
| 630 | class ReadBarrierMarkSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 631 | public: |
| 632 | ReadBarrierMarkSlowPathARMVIXL(HInstruction* instruction, |
| 633 | Location ref, |
| 634 | Location entrypoint = Location::NoLocation()) |
| 635 | : SlowPathCodeARMVIXL(instruction), ref_(ref), entrypoint_(entrypoint) { |
| 636 | DCHECK(kEmitCompilerReadBarrier); |
| 637 | } |
| 638 | |
| 639 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathARMVIXL"; } |
| 640 | |
| 641 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 642 | LocationSummary* locations = instruction_->GetLocations(); |
| 643 | vixl32::Register ref_reg = RegisterFrom(ref_); |
| 644 | DCHECK(locations->CanCall()); |
| 645 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg.GetCode())) << ref_reg; |
| 646 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 647 | instruction_->IsStaticFieldGet() || |
| 648 | instruction_->IsArrayGet() || |
| 649 | instruction_->IsArraySet() || |
| 650 | instruction_->IsLoadClass() || |
| 651 | instruction_->IsLoadString() || |
| 652 | instruction_->IsInstanceOf() || |
| 653 | instruction_->IsCheckCast() || |
| 654 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()) || |
| 655 | (instruction_->IsInvokeStaticOrDirect() && instruction_->GetLocations()->Intrinsified())) |
| 656 | << "Unexpected instruction in read barrier marking slow path: " |
| 657 | << instruction_->DebugName(); |
| 658 | // The read barrier instrumentation of object ArrayGet |
| 659 | // instructions does not support the HIntermediateAddress |
| 660 | // instruction. |
| 661 | DCHECK(!(instruction_->IsArrayGet() && |
| 662 | instruction_->AsArrayGet()->GetArray()->IsIntermediateAddress())); |
| 663 | |
| 664 | __ Bind(GetEntryLabel()); |
| 665 | // No need to save live registers; it's taken care of by the |
| 666 | // entrypoint. Also, there is no need to update the stack mask, |
| 667 | // as this runtime call will not trigger a garbage collection. |
| 668 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 669 | DCHECK(!ref_reg.Is(sp)); |
| 670 | DCHECK(!ref_reg.Is(lr)); |
| 671 | DCHECK(!ref_reg.Is(pc)); |
| 672 | // IP is used internally by the ReadBarrierMarkRegX entry point |
| 673 | // as a temporary, it cannot be the entry point's input/output. |
| 674 | DCHECK(!ref_reg.Is(ip)); |
| 675 | DCHECK(ref_reg.IsRegister()) << ref_reg; |
| 676 | // "Compact" slow path, saving two moves. |
| 677 | // |
| 678 | // Instead of using the standard runtime calling convention (input |
| 679 | // and output in R0): |
| 680 | // |
| 681 | // R0 <- ref |
| 682 | // R0 <- ReadBarrierMark(R0) |
| 683 | // ref <- R0 |
| 684 | // |
| 685 | // we just use rX (the register containing `ref`) as input and output |
| 686 | // of a dedicated entrypoint: |
| 687 | // |
| 688 | // rX <- ReadBarrierMarkRegX(rX) |
| 689 | // |
| 690 | if (entrypoint_.IsValid()) { |
| 691 | arm_codegen->ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction_, this); |
| 692 | __ Blx(RegisterFrom(entrypoint_)); |
| 693 | } else { |
| 694 | int32_t entry_point_offset = |
| 695 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArmPointerSize>(ref_reg.GetCode()); |
| 696 | // This runtime call does not require a stack map. |
| 697 | arm_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
| 698 | } |
| 699 | __ B(GetExitLabel()); |
| 700 | } |
| 701 | |
| 702 | private: |
| 703 | // The location (register) of the marked object reference. |
| 704 | const Location ref_; |
| 705 | |
| 706 | // The location of the entrypoint if already loaded. |
| 707 | const Location entrypoint_; |
| 708 | |
| 709 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathARMVIXL); |
| 710 | }; |
| 711 | |
| 712 | // Slow path marking an object reference `ref` during a read barrier, |
| 713 | // and if needed, atomically updating the field `obj.field` in the |
| 714 | // object `obj` holding this reference after marking (contrary to |
| 715 | // ReadBarrierMarkSlowPathARM above, which never tries to update |
| 716 | // `obj.field`). |
| 717 | // |
| 718 | // This means that after the execution of this slow path, both `ref` |
| 719 | // and `obj.field` will be up-to-date; i.e., after the flip, both will |
| 720 | // hold the same to-space reference (unless another thread installed |
| 721 | // another object reference (different from `ref`) in `obj.field`). |
| 722 | class ReadBarrierMarkAndUpdateFieldSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 723 | public: |
| 724 | ReadBarrierMarkAndUpdateFieldSlowPathARMVIXL(HInstruction* instruction, |
| 725 | Location ref, |
| 726 | vixl32::Register obj, |
| 727 | Location field_offset, |
| 728 | vixl32::Register temp1, |
| 729 | vixl32::Register temp2) |
| 730 | : SlowPathCodeARMVIXL(instruction), |
| 731 | ref_(ref), |
| 732 | obj_(obj), |
| 733 | field_offset_(field_offset), |
| 734 | temp1_(temp1), |
| 735 | temp2_(temp2) { |
| 736 | DCHECK(kEmitCompilerReadBarrier); |
| 737 | } |
| 738 | |
| 739 | const char* GetDescription() const OVERRIDE { |
| 740 | return "ReadBarrierMarkAndUpdateFieldSlowPathARMVIXL"; |
| 741 | } |
| 742 | |
| 743 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 744 | LocationSummary* locations = instruction_->GetLocations(); |
| 745 | vixl32::Register ref_reg = RegisterFrom(ref_); |
| 746 | DCHECK(locations->CanCall()); |
| 747 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg.GetCode())) << ref_reg; |
| 748 | // This slow path is only used by the UnsafeCASObject intrinsic. |
| 749 | DCHECK((instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
| 750 | << "Unexpected instruction in read barrier marking and field updating slow path: " |
| 751 | << instruction_->DebugName(); |
| 752 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 753 | DCHECK_EQ(instruction_->AsInvoke()->GetIntrinsic(), Intrinsics::kUnsafeCASObject); |
| 754 | DCHECK(field_offset_.IsRegisterPair()) << field_offset_; |
| 755 | |
| 756 | __ Bind(GetEntryLabel()); |
| 757 | |
| 758 | // Save the old reference. |
| 759 | // Note that we cannot use IP to save the old reference, as IP is |
| 760 | // used internally by the ReadBarrierMarkRegX entry point, and we |
| 761 | // need the old reference after the call to that entry point. |
| 762 | DCHECK(!temp1_.Is(ip)); |
| 763 | __ Mov(temp1_, ref_reg); |
| 764 | |
| 765 | // No need to save live registers; it's taken care of by the |
| 766 | // entrypoint. Also, there is no need to update the stack mask, |
| 767 | // as this runtime call will not trigger a garbage collection. |
| 768 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 769 | DCHECK(!ref_reg.Is(sp)); |
| 770 | DCHECK(!ref_reg.Is(lr)); |
| 771 | DCHECK(!ref_reg.Is(pc)); |
| 772 | // IP is used internally by the ReadBarrierMarkRegX entry point |
| 773 | // as a temporary, it cannot be the entry point's input/output. |
| 774 | DCHECK(!ref_reg.Is(ip)); |
| 775 | DCHECK(ref_reg.IsRegister()) << ref_reg; |
| 776 | // "Compact" slow path, saving two moves. |
| 777 | // |
| 778 | // Instead of using the standard runtime calling convention (input |
| 779 | // and output in R0): |
| 780 | // |
| 781 | // R0 <- ref |
| 782 | // R0 <- ReadBarrierMark(R0) |
| 783 | // ref <- R0 |
| 784 | // |
| 785 | // we just use rX (the register containing `ref`) as input and output |
| 786 | // of a dedicated entrypoint: |
| 787 | // |
| 788 | // rX <- ReadBarrierMarkRegX(rX) |
| 789 | // |
| 790 | int32_t entry_point_offset = |
| 791 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArmPointerSize>(ref_reg.GetCode()); |
| 792 | // This runtime call does not require a stack map. |
| 793 | arm_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
| 794 | |
| 795 | // If the new reference is different from the old reference, |
| 796 | // update the field in the holder (`*(obj_ + field_offset_)`). |
| 797 | // |
| 798 | // Note that this field could also hold a different object, if |
| 799 | // another thread had concurrently changed it. In that case, the |
| 800 | // LDREX/SUBS/ITNE sequence of instructions in the compare-and-set |
| 801 | // (CAS) operation below would abort the CAS, leaving the field |
| 802 | // as-is. |
| 803 | vixl32::Label done; |
| 804 | __ Cmp(temp1_, ref_reg); |
| 805 | __ B(eq, &done); |
| 806 | |
| 807 | // Update the the holder's field atomically. This may fail if |
| 808 | // mutator updates before us, but it's OK. This is achieved |
| 809 | // using a strong compare-and-set (CAS) operation with relaxed |
| 810 | // memory synchronization ordering, where the expected value is |
| 811 | // the old reference and the desired value is the new reference. |
| 812 | |
| 813 | UseScratchRegisterScope temps(arm_codegen->GetVIXLAssembler()); |
| 814 | // Convenience aliases. |
| 815 | vixl32::Register base = obj_; |
| 816 | // The UnsafeCASObject intrinsic uses a register pair as field |
| 817 | // offset ("long offset"), of which only the low part contains |
| 818 | // data. |
| 819 | vixl32::Register offset = LowRegisterFrom(field_offset_); |
| 820 | vixl32::Register expected = temp1_; |
| 821 | vixl32::Register value = ref_reg; |
| 822 | vixl32::Register tmp_ptr = temps.Acquire(); // Pointer to actual memory. |
| 823 | vixl32::Register tmp = temp2_; // Value in memory. |
| 824 | |
| 825 | __ Add(tmp_ptr, base, offset); |
| 826 | |
| 827 | if (kPoisonHeapReferences) { |
| 828 | arm_codegen->GetAssembler()->PoisonHeapReference(expected); |
| 829 | if (value.Is(expected)) { |
| 830 | // Do not poison `value`, as it is the same register as |
| 831 | // `expected`, which has just been poisoned. |
| 832 | } else { |
| 833 | arm_codegen->GetAssembler()->PoisonHeapReference(value); |
| 834 | } |
| 835 | } |
| 836 | |
| 837 | // do { |
| 838 | // tmp = [r_ptr] - expected; |
| 839 | // } while (tmp == 0 && failure([r_ptr] <- r_new_value)); |
| 840 | |
| 841 | vixl32::Label loop_head, exit_loop; |
| 842 | __ Bind(&loop_head); |
| 843 | |
| 844 | __ Ldrex(tmp, MemOperand(tmp_ptr)); |
| 845 | |
| 846 | __ Subs(tmp, tmp, expected); |
| 847 | |
| 848 | { |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 849 | ExactAssemblyScope aas(arm_codegen->GetVIXLAssembler(), |
| 850 | 2 * kMaxInstructionSizeInBytes, |
| 851 | CodeBufferCheckScope::kMaximumSize); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 852 | |
| 853 | __ it(ne); |
| 854 | __ clrex(ne); |
| 855 | } |
| 856 | |
| 857 | __ B(ne, &exit_loop); |
| 858 | |
| 859 | __ Strex(tmp, value, MemOperand(tmp_ptr)); |
| 860 | __ Cmp(tmp, 1); |
| 861 | __ B(eq, &loop_head); |
| 862 | |
| 863 | __ Bind(&exit_loop); |
| 864 | |
| 865 | if (kPoisonHeapReferences) { |
| 866 | arm_codegen->GetAssembler()->UnpoisonHeapReference(expected); |
| 867 | if (value.Is(expected)) { |
| 868 | // Do not unpoison `value`, as it is the same register as |
| 869 | // `expected`, which has just been unpoisoned. |
| 870 | } else { |
| 871 | arm_codegen->GetAssembler()->UnpoisonHeapReference(value); |
| 872 | } |
| 873 | } |
| 874 | |
| 875 | __ Bind(&done); |
| 876 | __ B(GetExitLabel()); |
| 877 | } |
| 878 | |
| 879 | private: |
| 880 | // The location (register) of the marked object reference. |
| 881 | const Location ref_; |
| 882 | // The register containing the object holding the marked object reference field. |
| 883 | const vixl32::Register obj_; |
| 884 | // The location of the offset of the marked reference field within `obj_`. |
| 885 | Location field_offset_; |
| 886 | |
| 887 | const vixl32::Register temp1_; |
| 888 | const vixl32::Register temp2_; |
| 889 | |
| 890 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkAndUpdateFieldSlowPathARMVIXL); |
| 891 | }; |
| 892 | |
| 893 | // Slow path generating a read barrier for a heap reference. |
| 894 | class ReadBarrierForHeapReferenceSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 895 | public: |
| 896 | ReadBarrierForHeapReferenceSlowPathARMVIXL(HInstruction* instruction, |
| 897 | Location out, |
| 898 | Location ref, |
| 899 | Location obj, |
| 900 | uint32_t offset, |
| 901 | Location index) |
| 902 | : SlowPathCodeARMVIXL(instruction), |
| 903 | out_(out), |
| 904 | ref_(ref), |
| 905 | obj_(obj), |
| 906 | offset_(offset), |
| 907 | index_(index) { |
| 908 | DCHECK(kEmitCompilerReadBarrier); |
| 909 | // If `obj` is equal to `out` or `ref`, it means the initial object |
| 910 | // has been overwritten by (or after) the heap object reference load |
| 911 | // to be instrumented, e.g.: |
| 912 | // |
| 913 | // __ LoadFromOffset(kLoadWord, out, out, offset); |
| 914 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
| 915 | // |
| 916 | // In that case, we have lost the information about the original |
| 917 | // object, and the emitted read barrier cannot work properly. |
| 918 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 919 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 920 | } |
| 921 | |
| 922 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 923 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 924 | LocationSummary* locations = instruction_->GetLocations(); |
| 925 | vixl32::Register reg_out = RegisterFrom(out_); |
| 926 | DCHECK(locations->CanCall()); |
| 927 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out.GetCode())); |
| 928 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 929 | instruction_->IsStaticFieldGet() || |
| 930 | instruction_->IsArrayGet() || |
| 931 | instruction_->IsInstanceOf() || |
| 932 | instruction_->IsCheckCast() || |
| 933 | (instruction_->IsInvokeVirtual()) && instruction_->GetLocations()->Intrinsified()) |
| 934 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 935 | << instruction_->DebugName(); |
| 936 | // The read barrier instrumentation of object ArrayGet |
| 937 | // instructions does not support the HIntermediateAddress |
| 938 | // instruction. |
| 939 | DCHECK(!(instruction_->IsArrayGet() && |
| 940 | instruction_->AsArrayGet()->GetArray()->IsIntermediateAddress())); |
| 941 | |
| 942 | __ Bind(GetEntryLabel()); |
| 943 | SaveLiveRegisters(codegen, locations); |
| 944 | |
| 945 | // We may have to change the index's value, but as `index_` is a |
| 946 | // constant member (like other "inputs" of this slow path), |
| 947 | // introduce a copy of it, `index`. |
| 948 | Location index = index_; |
| 949 | if (index_.IsValid()) { |
| 950 | // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
| 951 | if (instruction_->IsArrayGet()) { |
| 952 | // Compute the actual memory offset and store it in `index`. |
| 953 | vixl32::Register index_reg = RegisterFrom(index_); |
| 954 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_reg.GetCode())); |
| 955 | if (codegen->IsCoreCalleeSaveRegister(index_reg.GetCode())) { |
| 956 | // We are about to change the value of `index_reg` (see the |
| 957 | // calls to art::arm::Thumb2Assembler::Lsl and |
| 958 | // art::arm::Thumb2Assembler::AddConstant below), but it has |
| 959 | // not been saved by the previous call to |
| 960 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 961 | // callee-save register -- |
| 962 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 963 | // callee-save registers, as it has been designed with the |
| 964 | // assumption that callee-save registers are supposed to be |
| 965 | // handled by the called function. So, as a callee-save |
| 966 | // register, `index_reg` _would_ eventually be saved onto |
| 967 | // the stack, but it would be too late: we would have |
| 968 | // changed its value earlier. Therefore, we manually save |
| 969 | // it here into another freely available register, |
| 970 | // `free_reg`, chosen of course among the caller-save |
| 971 | // registers (as a callee-save `free_reg` register would |
| 972 | // exhibit the same problem). |
| 973 | // |
| 974 | // Note we could have requested a temporary register from |
| 975 | // the register allocator instead; but we prefer not to, as |
| 976 | // this is a slow path, and we know we can find a |
| 977 | // caller-save register that is available. |
| 978 | vixl32::Register free_reg = FindAvailableCallerSaveRegister(codegen); |
| 979 | __ Mov(free_reg, index_reg); |
| 980 | index_reg = free_reg; |
| 981 | index = LocationFrom(index_reg); |
| 982 | } else { |
| 983 | // The initial register stored in `index_` has already been |
| 984 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 985 | // (as it is not a callee-save register), so we can freely |
| 986 | // use it. |
| 987 | } |
| 988 | // Shifting the index value contained in `index_reg` by the scale |
| 989 | // factor (2) cannot overflow in practice, as the runtime is |
| 990 | // unable to allocate object arrays with a size larger than |
| 991 | // 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 992 | __ Lsl(index_reg, index_reg, TIMES_4); |
| 993 | static_assert( |
| 994 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 995 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 996 | __ Add(index_reg, index_reg, offset_); |
| 997 | } else { |
| 998 | // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile |
| 999 | // intrinsics, `index_` is not shifted by a scale factor of 2 |
| 1000 | // (as in the case of ArrayGet), as it is actually an offset |
| 1001 | // to an object field within an object. |
| 1002 | DCHECK(instruction_->IsInvoke()) << instruction_->DebugName(); |
| 1003 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 1004 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 1005 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 1006 | << instruction_->AsInvoke()->GetIntrinsic(); |
| 1007 | DCHECK_EQ(offset_, 0U); |
| 1008 | DCHECK(index_.IsRegisterPair()); |
| 1009 | // UnsafeGet's offset location is a register pair, the low |
| 1010 | // part contains the correct offset. |
| 1011 | index = index_.ToLow(); |
| 1012 | } |
| 1013 | } |
| 1014 | |
| 1015 | // We're moving two or three locations to locations that could |
| 1016 | // overlap, so we need a parallel move resolver. |
| 1017 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 1018 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 1019 | parallel_move.AddMove(ref_, |
| 1020 | LocationFrom(calling_convention.GetRegisterAt(0)), |
| 1021 | Primitive::kPrimNot, |
| 1022 | nullptr); |
| 1023 | parallel_move.AddMove(obj_, |
| 1024 | LocationFrom(calling_convention.GetRegisterAt(1)), |
| 1025 | Primitive::kPrimNot, |
| 1026 | nullptr); |
| 1027 | if (index.IsValid()) { |
| 1028 | parallel_move.AddMove(index, |
| 1029 | LocationFrom(calling_convention.GetRegisterAt(2)), |
| 1030 | Primitive::kPrimInt, |
| 1031 | nullptr); |
| 1032 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 1033 | } else { |
| 1034 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 1035 | __ Mov(calling_convention.GetRegisterAt(2), offset_); |
| 1036 | } |
| 1037 | arm_codegen->InvokeRuntime(kQuickReadBarrierSlow, instruction_, instruction_->GetDexPc(), this); |
| 1038 | CheckEntrypointTypes< |
| 1039 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 1040 | arm_codegen->Move32(out_, LocationFrom(r0)); |
| 1041 | |
| 1042 | RestoreLiveRegisters(codegen, locations); |
| 1043 | __ B(GetExitLabel()); |
| 1044 | } |
| 1045 | |
| 1046 | const char* GetDescription() const OVERRIDE { |
| 1047 | return "ReadBarrierForHeapReferenceSlowPathARMVIXL"; |
| 1048 | } |
| 1049 | |
| 1050 | private: |
| 1051 | vixl32::Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
| 1052 | uint32_t ref = RegisterFrom(ref_).GetCode(); |
| 1053 | uint32_t obj = RegisterFrom(obj_).GetCode(); |
| 1054 | for (uint32_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 1055 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 1056 | return vixl32::Register(i); |
| 1057 | } |
| 1058 | } |
| 1059 | // We shall never fail to find a free caller-save register, as |
| 1060 | // there are more than two core caller-save registers on ARM |
| 1061 | // (meaning it is possible to find one which is different from |
| 1062 | // `ref` and `obj`). |
| 1063 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 1064 | LOG(FATAL) << "Could not find a free caller-save register"; |
| 1065 | UNREACHABLE(); |
| 1066 | } |
| 1067 | |
| 1068 | const Location out_; |
| 1069 | const Location ref_; |
| 1070 | const Location obj_; |
| 1071 | const uint32_t offset_; |
| 1072 | // An additional location containing an index to an array. |
| 1073 | // Only used for HArrayGet and the UnsafeGetObject & |
| 1074 | // UnsafeGetObjectVolatile intrinsics. |
| 1075 | const Location index_; |
| 1076 | |
| 1077 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathARMVIXL); |
| 1078 | }; |
| 1079 | |
| 1080 | // Slow path generating a read barrier for a GC root. |
| 1081 | class ReadBarrierForRootSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 1082 | public: |
| 1083 | ReadBarrierForRootSlowPathARMVIXL(HInstruction* instruction, Location out, Location root) |
| 1084 | : SlowPathCodeARMVIXL(instruction), out_(out), root_(root) { |
| 1085 | DCHECK(kEmitCompilerReadBarrier); |
| 1086 | } |
| 1087 | |
| 1088 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 1089 | LocationSummary* locations = instruction_->GetLocations(); |
| 1090 | vixl32::Register reg_out = RegisterFrom(out_); |
| 1091 | DCHECK(locations->CanCall()); |
| 1092 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out.GetCode())); |
| 1093 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 1094 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 1095 | << instruction_->DebugName(); |
| 1096 | |
| 1097 | __ Bind(GetEntryLabel()); |
| 1098 | SaveLiveRegisters(codegen, locations); |
| 1099 | |
| 1100 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 1101 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 1102 | arm_codegen->Move32(LocationFrom(calling_convention.GetRegisterAt(0)), root_); |
| 1103 | arm_codegen->InvokeRuntime(kQuickReadBarrierForRootSlow, |
| 1104 | instruction_, |
| 1105 | instruction_->GetDexPc(), |
| 1106 | this); |
| 1107 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 1108 | arm_codegen->Move32(out_, LocationFrom(r0)); |
| 1109 | |
| 1110 | RestoreLiveRegisters(codegen, locations); |
| 1111 | __ B(GetExitLabel()); |
| 1112 | } |
| 1113 | |
| 1114 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathARMVIXL"; } |
| 1115 | |
| 1116 | private: |
| 1117 | const Location out_; |
| 1118 | const Location root_; |
| 1119 | |
| 1120 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathARMVIXL); |
| 1121 | }; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 1122 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1123 | inline vixl32::Condition ARMCondition(IfCondition cond) { |
| 1124 | switch (cond) { |
| 1125 | case kCondEQ: return eq; |
| 1126 | case kCondNE: return ne; |
| 1127 | case kCondLT: return lt; |
| 1128 | case kCondLE: return le; |
| 1129 | case kCondGT: return gt; |
| 1130 | case kCondGE: return ge; |
| 1131 | case kCondB: return lo; |
| 1132 | case kCondBE: return ls; |
| 1133 | case kCondA: return hi; |
| 1134 | case kCondAE: return hs; |
| 1135 | } |
| 1136 | LOG(FATAL) << "Unreachable"; |
| 1137 | UNREACHABLE(); |
| 1138 | } |
| 1139 | |
| 1140 | // Maps signed condition to unsigned condition. |
| 1141 | inline vixl32::Condition ARMUnsignedCondition(IfCondition cond) { |
| 1142 | switch (cond) { |
| 1143 | case kCondEQ: return eq; |
| 1144 | case kCondNE: return ne; |
| 1145 | // Signed to unsigned. |
| 1146 | case kCondLT: return lo; |
| 1147 | case kCondLE: return ls; |
| 1148 | case kCondGT: return hi; |
| 1149 | case kCondGE: return hs; |
| 1150 | // Unsigned remain unchanged. |
| 1151 | case kCondB: return lo; |
| 1152 | case kCondBE: return ls; |
| 1153 | case kCondA: return hi; |
| 1154 | case kCondAE: return hs; |
| 1155 | } |
| 1156 | LOG(FATAL) << "Unreachable"; |
| 1157 | UNREACHABLE(); |
| 1158 | } |
| 1159 | |
| 1160 | inline vixl32::Condition ARMFPCondition(IfCondition cond, bool gt_bias) { |
| 1161 | // The ARM condition codes can express all the necessary branches, see the |
| 1162 | // "Meaning (floating-point)" column in the table A8-1 of the ARMv7 reference manual. |
| 1163 | // There is no dex instruction or HIR that would need the missing conditions |
| 1164 | // "equal or unordered" or "not equal". |
| 1165 | switch (cond) { |
| 1166 | case kCondEQ: return eq; |
| 1167 | case kCondNE: return ne /* unordered */; |
| 1168 | case kCondLT: return gt_bias ? cc : lt /* unordered */; |
| 1169 | case kCondLE: return gt_bias ? ls : le /* unordered */; |
| 1170 | case kCondGT: return gt_bias ? hi /* unordered */ : gt; |
| 1171 | case kCondGE: return gt_bias ? cs /* unordered */ : ge; |
| 1172 | default: |
| 1173 | LOG(FATAL) << "UNREACHABLE"; |
| 1174 | UNREACHABLE(); |
| 1175 | } |
| 1176 | } |
| 1177 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1178 | void CodeGeneratorARMVIXL::DumpCoreRegister(std::ostream& stream, int reg) const { |
| 1179 | stream << vixl32::Register(reg); |
| 1180 | } |
| 1181 | |
| 1182 | void CodeGeneratorARMVIXL::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
| 1183 | stream << vixl32::SRegister(reg); |
| 1184 | } |
| 1185 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 1186 | static uint32_t ComputeSRegisterListMask(const SRegisterList& regs) { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1187 | uint32_t mask = 0; |
| 1188 | for (uint32_t i = regs.GetFirstSRegister().GetCode(); |
| 1189 | i <= regs.GetLastSRegister().GetCode(); |
| 1190 | ++i) { |
| 1191 | mask |= (1 << i); |
| 1192 | } |
| 1193 | return mask; |
| 1194 | } |
| 1195 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 1196 | // Saves the register in the stack. Returns the size taken on stack. |
| 1197 | size_t CodeGeneratorARMVIXL::SaveCoreRegister(size_t stack_index ATTRIBUTE_UNUSED, |
| 1198 | uint32_t reg_id ATTRIBUTE_UNUSED) { |
| 1199 | TODO_VIXL32(FATAL); |
| 1200 | return 0; |
| 1201 | } |
| 1202 | |
| 1203 | // Restores the register from the stack. Returns the size taken on stack. |
| 1204 | size_t CodeGeneratorARMVIXL::RestoreCoreRegister(size_t stack_index ATTRIBUTE_UNUSED, |
| 1205 | uint32_t reg_id ATTRIBUTE_UNUSED) { |
| 1206 | TODO_VIXL32(FATAL); |
| 1207 | return 0; |
| 1208 | } |
| 1209 | |
| 1210 | size_t CodeGeneratorARMVIXL::SaveFloatingPointRegister(size_t stack_index ATTRIBUTE_UNUSED, |
| 1211 | uint32_t reg_id ATTRIBUTE_UNUSED) { |
| 1212 | TODO_VIXL32(FATAL); |
| 1213 | return 0; |
| 1214 | } |
| 1215 | |
| 1216 | size_t CodeGeneratorARMVIXL::RestoreFloatingPointRegister(size_t stack_index ATTRIBUTE_UNUSED, |
| 1217 | uint32_t reg_id ATTRIBUTE_UNUSED) { |
| 1218 | TODO_VIXL32(FATAL); |
| 1219 | return 0; |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 1220 | } |
| 1221 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1222 | #undef __ |
| 1223 | |
| 1224 | CodeGeneratorARMVIXL::CodeGeneratorARMVIXL(HGraph* graph, |
| 1225 | const ArmInstructionSetFeatures& isa_features, |
| 1226 | const CompilerOptions& compiler_options, |
| 1227 | OptimizingCompilerStats* stats) |
| 1228 | : CodeGenerator(graph, |
| 1229 | kNumberOfCoreRegisters, |
| 1230 | kNumberOfSRegisters, |
| 1231 | kNumberOfRegisterPairs, |
| 1232 | kCoreCalleeSaves.GetList(), |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 1233 | ComputeSRegisterListMask(kFpuCalleeSaves), |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1234 | compiler_options, |
| 1235 | stats), |
| 1236 | block_labels_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 1237 | jump_tables_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1238 | location_builder_(graph, this), |
| 1239 | instruction_visitor_(graph, this), |
| 1240 | move_resolver_(graph->GetArena(), this), |
| 1241 | assembler_(graph->GetArena()), |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 1242 | isa_features_(isa_features), |
| 1243 | relative_call_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1244 | pc_relative_dex_cache_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1245 | pc_relative_string_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1246 | pc_relative_type_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)) { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1247 | // Always save the LR register to mimic Quick. |
| 1248 | AddAllocatedRegister(Location::RegisterLocation(LR)); |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 1249 | // Give d14 and d15 as scratch registers to VIXL. |
| 1250 | // They are removed from the register allocator in `SetupBlockedRegisters()`. |
| 1251 | // TODO(VIXL): We need two scratch D registers for `EmitSwap` when swapping two double stack |
| 1252 | // slots. If that is sufficiently rare, and we have pressure on FP registers, we could instead |
| 1253 | // spill in `EmitSwap`. But if we actually are guaranteed to have 32 D registers, we could give |
| 1254 | // d30 and d31 to VIXL to avoid removing registers from the allocator. If that is the case, we may |
| 1255 | // also want to investigate giving those 14 other D registers to the allocator. |
| 1256 | GetVIXLAssembler()->GetScratchVRegisterList()->Combine(d14); |
| 1257 | GetVIXLAssembler()->GetScratchVRegisterList()->Combine(d15); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1258 | } |
| 1259 | |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 1260 | void JumpTableARMVIXL::EmitTable(CodeGeneratorARMVIXL* codegen) { |
| 1261 | uint32_t num_entries = switch_instr_->GetNumEntries(); |
| 1262 | DCHECK_GE(num_entries, kPackedSwitchCompareJumpThreshold); |
| 1263 | |
| 1264 | // 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] | 1265 | // underlying code buffer and we have generated a jump table of the right size, using |
| 1266 | // codegen->GetVIXLAssembler()->GetBuffer().Align(); |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 1267 | ExactAssemblyScope aas(codegen->GetVIXLAssembler(), |
| 1268 | num_entries * sizeof(int32_t), |
| 1269 | CodeBufferCheckScope::kMaximumSize); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 1270 | // TODO(VIXL): Check that using lower case bind is fine here. |
| 1271 | codegen->GetVIXLAssembler()->bind(&table_start_); |
Artem Serov | 09a940d | 2016-11-11 16:15:11 +0000 | [diff] [blame] | 1272 | for (uint32_t i = 0; i < num_entries; i++) { |
| 1273 | codegen->GetVIXLAssembler()->place(bb_addresses_[i].get()); |
| 1274 | } |
| 1275 | } |
| 1276 | |
| 1277 | void JumpTableARMVIXL::FixTable(CodeGeneratorARMVIXL* codegen) { |
| 1278 | uint32_t num_entries = switch_instr_->GetNumEntries(); |
| 1279 | DCHECK_GE(num_entries, kPackedSwitchCompareJumpThreshold); |
| 1280 | |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 1281 | const ArenaVector<HBasicBlock*>& successors = switch_instr_->GetBlock()->GetSuccessors(); |
| 1282 | for (uint32_t i = 0; i < num_entries; i++) { |
| 1283 | vixl32::Label* target_label = codegen->GetLabelOf(successors[i]); |
| 1284 | DCHECK(target_label->IsBound()); |
| 1285 | int32_t jump_offset = target_label->GetLocation() - table_start_.GetLocation(); |
| 1286 | // When doing BX to address we need to have lower bit set to 1 in T32. |
| 1287 | if (codegen->GetVIXLAssembler()->IsUsingT32()) { |
| 1288 | jump_offset++; |
| 1289 | } |
| 1290 | DCHECK_GT(jump_offset, std::numeric_limits<int32_t>::min()); |
| 1291 | DCHECK_LE(jump_offset, std::numeric_limits<int32_t>::max()); |
Artem Serov | 09a940d | 2016-11-11 16:15:11 +0000 | [diff] [blame] | 1292 | |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 1293 | bb_addresses_[i].get()->UpdateValue(jump_offset, codegen->GetVIXLAssembler()->GetBuffer()); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 1294 | } |
| 1295 | } |
| 1296 | |
Artem Serov | 09a940d | 2016-11-11 16:15:11 +0000 | [diff] [blame] | 1297 | void CodeGeneratorARMVIXL::FixJumpTables() { |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 1298 | for (auto&& jump_table : jump_tables_) { |
Artem Serov | 09a940d | 2016-11-11 16:15:11 +0000 | [diff] [blame] | 1299 | jump_table->FixTable(this); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 1300 | } |
| 1301 | } |
| 1302 | |
Andreas Gampe | ca620d7 | 2016-11-08 08:09:33 -0800 | [diff] [blame] | 1303 | #define __ reinterpret_cast<ArmVIXLAssembler*>(GetAssembler())->GetVIXLAssembler()-> // NOLINT |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1304 | |
| 1305 | void CodeGeneratorARMVIXL::Finalize(CodeAllocator* allocator) { |
Artem Serov | 09a940d | 2016-11-11 16:15:11 +0000 | [diff] [blame] | 1306 | FixJumpTables(); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1307 | GetAssembler()->FinalizeCode(); |
| 1308 | CodeGenerator::Finalize(allocator); |
| 1309 | } |
| 1310 | |
| 1311 | void CodeGeneratorARMVIXL::SetupBlockedRegisters() const { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1312 | // Stack register, LR and PC are always reserved. |
| 1313 | blocked_core_registers_[SP] = true; |
| 1314 | blocked_core_registers_[LR] = true; |
| 1315 | blocked_core_registers_[PC] = true; |
| 1316 | |
| 1317 | // Reserve thread register. |
| 1318 | blocked_core_registers_[TR] = true; |
| 1319 | |
| 1320 | // Reserve temp register. |
| 1321 | blocked_core_registers_[IP] = true; |
| 1322 | |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 1323 | // Registers s28-s31 (d14-d15) are left to VIXL for scratch registers. |
| 1324 | // (They are given to the `MacroAssembler` in `CodeGeneratorARMVIXL::CodeGeneratorARMVIXL`.) |
| 1325 | blocked_fpu_registers_[28] = true; |
| 1326 | blocked_fpu_registers_[29] = true; |
| 1327 | blocked_fpu_registers_[30] = true; |
| 1328 | blocked_fpu_registers_[31] = true; |
| 1329 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1330 | if (GetGraph()->IsDebuggable()) { |
| 1331 | // Stubs do not save callee-save floating point registers. If the graph |
| 1332 | // is debuggable, we need to deal with these registers differently. For |
| 1333 | // now, just block them. |
| 1334 | for (uint32_t i = kFpuCalleeSaves.GetFirstSRegister().GetCode(); |
| 1335 | i <= kFpuCalleeSaves.GetLastSRegister().GetCode(); |
| 1336 | ++i) { |
| 1337 | blocked_fpu_registers_[i] = true; |
| 1338 | } |
| 1339 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1340 | } |
| 1341 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1342 | InstructionCodeGeneratorARMVIXL::InstructionCodeGeneratorARMVIXL(HGraph* graph, |
| 1343 | CodeGeneratorARMVIXL* codegen) |
| 1344 | : InstructionCodeGenerator(graph, codegen), |
| 1345 | assembler_(codegen->GetAssembler()), |
| 1346 | codegen_(codegen) {} |
| 1347 | |
| 1348 | void CodeGeneratorARMVIXL::ComputeSpillMask() { |
| 1349 | core_spill_mask_ = allocated_registers_.GetCoreRegisters() & core_callee_save_mask_; |
| 1350 | DCHECK_NE(core_spill_mask_, 0u) << "At least the return address register must be saved"; |
| 1351 | // There is no easy instruction to restore just the PC on thumb2. We spill and |
| 1352 | // restore another arbitrary register. |
| 1353 | core_spill_mask_ |= (1 << kCoreAlwaysSpillRegister.GetCode()); |
| 1354 | fpu_spill_mask_ = allocated_registers_.GetFloatingPointRegisters() & fpu_callee_save_mask_; |
| 1355 | // We use vpush and vpop for saving and restoring floating point registers, which take |
| 1356 | // a SRegister and the number of registers to save/restore after that SRegister. We |
| 1357 | // therefore update the `fpu_spill_mask_` to also contain those registers not allocated, |
| 1358 | // but in the range. |
| 1359 | if (fpu_spill_mask_ != 0) { |
| 1360 | uint32_t least_significant_bit = LeastSignificantBit(fpu_spill_mask_); |
| 1361 | uint32_t most_significant_bit = MostSignificantBit(fpu_spill_mask_); |
| 1362 | for (uint32_t i = least_significant_bit + 1 ; i < most_significant_bit; ++i) { |
| 1363 | fpu_spill_mask_ |= (1 << i); |
| 1364 | } |
| 1365 | } |
| 1366 | } |
| 1367 | |
| 1368 | void CodeGeneratorARMVIXL::GenerateFrameEntry() { |
| 1369 | bool skip_overflow_check = |
| 1370 | IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kArm); |
| 1371 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
| 1372 | __ Bind(&frame_entry_label_); |
| 1373 | |
| 1374 | if (HasEmptyFrame()) { |
| 1375 | return; |
| 1376 | } |
| 1377 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1378 | if (!skip_overflow_check) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 1379 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 1380 | vixl32::Register temp = temps.Acquire(); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1381 | __ Sub(temp, sp, static_cast<int32_t>(GetStackOverflowReservedBytes(kArm))); |
| 1382 | // The load must immediately precede RecordPcInfo. |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 1383 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 1384 | vixl32::kMaxInstructionSizeInBytes, |
| 1385 | CodeBufferCheckScope::kMaximumSize); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 1386 | __ ldr(temp, MemOperand(temp)); |
| 1387 | RecordPcInfo(nullptr, 0); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1388 | } |
| 1389 | |
| 1390 | __ Push(RegisterList(core_spill_mask_)); |
| 1391 | GetAssembler()->cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(core_spill_mask_)); |
| 1392 | GetAssembler()->cfi().RelOffsetForMany(DWARFReg(kMethodRegister), |
| 1393 | 0, |
| 1394 | core_spill_mask_, |
| 1395 | kArmWordSize); |
| 1396 | if (fpu_spill_mask_ != 0) { |
| 1397 | uint32_t first = LeastSignificantBit(fpu_spill_mask_); |
| 1398 | |
| 1399 | // Check that list is contiguous. |
| 1400 | DCHECK_EQ(fpu_spill_mask_ >> CTZ(fpu_spill_mask_), ~0u >> (32 - POPCOUNT(fpu_spill_mask_))); |
| 1401 | |
| 1402 | __ Vpush(SRegisterList(vixl32::SRegister(first), POPCOUNT(fpu_spill_mask_))); |
| 1403 | GetAssembler()->cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(fpu_spill_mask_)); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 1404 | GetAssembler()->cfi().RelOffsetForMany(DWARFReg(s0), 0, fpu_spill_mask_, kArmWordSize); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1405 | } |
Scott Wakeling | bffdc70 | 2016-12-07 17:46:03 +0000 | [diff] [blame] | 1406 | |
| 1407 | if (GetGraph()->HasShouldDeoptimizeFlag()) { |
| 1408 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 1409 | vixl32::Register temp = temps.Acquire(); |
| 1410 | // Initialize should_deoptimize flag to 0. |
| 1411 | __ Mov(temp, 0); |
| 1412 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, -kShouldDeoptimizeFlagSize); |
| 1413 | } |
| 1414 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1415 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 1416 | __ Sub(sp, sp, adjust); |
| 1417 | GetAssembler()->cfi().AdjustCFAOffset(adjust); |
Scott Wakeling | bffdc70 | 2016-12-07 17:46:03 +0000 | [diff] [blame] | 1418 | |
| 1419 | // Save the current method if we need it. Note that we do not |
| 1420 | // do this in HCurrentMethod, as the instruction might have been removed |
| 1421 | // in the SSA graph. |
| 1422 | if (RequiresCurrentMethod()) { |
| 1423 | GetAssembler()->StoreToOffset(kStoreWord, kMethodRegister, sp, 0); |
| 1424 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1425 | } |
| 1426 | |
| 1427 | void CodeGeneratorARMVIXL::GenerateFrameExit() { |
| 1428 | if (HasEmptyFrame()) { |
| 1429 | __ Bx(lr); |
| 1430 | return; |
| 1431 | } |
| 1432 | GetAssembler()->cfi().RememberState(); |
| 1433 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 1434 | __ Add(sp, sp, adjust); |
| 1435 | GetAssembler()->cfi().AdjustCFAOffset(-adjust); |
| 1436 | if (fpu_spill_mask_ != 0) { |
| 1437 | uint32_t first = LeastSignificantBit(fpu_spill_mask_); |
| 1438 | |
| 1439 | // Check that list is contiguous. |
| 1440 | DCHECK_EQ(fpu_spill_mask_ >> CTZ(fpu_spill_mask_), ~0u >> (32 - POPCOUNT(fpu_spill_mask_))); |
| 1441 | |
| 1442 | __ Vpop(SRegisterList(vixl32::SRegister(first), POPCOUNT(fpu_spill_mask_))); |
| 1443 | GetAssembler()->cfi().AdjustCFAOffset( |
| 1444 | -static_cast<int>(kArmWordSize) * POPCOUNT(fpu_spill_mask_)); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 1445 | GetAssembler()->cfi().RestoreMany(DWARFReg(vixl32::SRegister(0)), fpu_spill_mask_); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1446 | } |
| 1447 | // Pop LR into PC to return. |
| 1448 | DCHECK_NE(core_spill_mask_ & (1 << kLrCode), 0U); |
| 1449 | uint32_t pop_mask = (core_spill_mask_ & (~(1 << kLrCode))) | 1 << kPcCode; |
| 1450 | __ Pop(RegisterList(pop_mask)); |
| 1451 | GetAssembler()->cfi().RestoreState(); |
| 1452 | GetAssembler()->cfi().DefCFAOffset(GetFrameSize()); |
| 1453 | } |
| 1454 | |
| 1455 | void CodeGeneratorARMVIXL::Bind(HBasicBlock* block) { |
| 1456 | __ Bind(GetLabelOf(block)); |
| 1457 | } |
| 1458 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 1459 | Location InvokeDexCallingConventionVisitorARMVIXL::GetNextLocation(Primitive::Type type) { |
| 1460 | switch (type) { |
| 1461 | case Primitive::kPrimBoolean: |
| 1462 | case Primitive::kPrimByte: |
| 1463 | case Primitive::kPrimChar: |
| 1464 | case Primitive::kPrimShort: |
| 1465 | case Primitive::kPrimInt: |
| 1466 | case Primitive::kPrimNot: { |
| 1467 | uint32_t index = gp_index_++; |
| 1468 | uint32_t stack_index = stack_index_++; |
| 1469 | if (index < calling_convention.GetNumberOfRegisters()) { |
| 1470 | return LocationFrom(calling_convention.GetRegisterAt(index)); |
| 1471 | } else { |
| 1472 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
| 1473 | } |
| 1474 | } |
| 1475 | |
| 1476 | case Primitive::kPrimLong: { |
| 1477 | uint32_t index = gp_index_; |
| 1478 | uint32_t stack_index = stack_index_; |
| 1479 | gp_index_ += 2; |
| 1480 | stack_index_ += 2; |
| 1481 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
| 1482 | if (calling_convention.GetRegisterAt(index).Is(r1)) { |
| 1483 | // Skip R1, and use R2_R3 instead. |
| 1484 | gp_index_++; |
| 1485 | index++; |
| 1486 | } |
| 1487 | } |
| 1488 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
| 1489 | DCHECK_EQ(calling_convention.GetRegisterAt(index).GetCode() + 1, |
| 1490 | calling_convention.GetRegisterAt(index + 1).GetCode()); |
| 1491 | |
| 1492 | return LocationFrom(calling_convention.GetRegisterAt(index), |
| 1493 | calling_convention.GetRegisterAt(index + 1)); |
| 1494 | } else { |
| 1495 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
| 1496 | } |
| 1497 | } |
| 1498 | |
| 1499 | case Primitive::kPrimFloat: { |
| 1500 | uint32_t stack_index = stack_index_++; |
| 1501 | if (float_index_ % 2 == 0) { |
| 1502 | float_index_ = std::max(double_index_, float_index_); |
| 1503 | } |
| 1504 | if (float_index_ < calling_convention.GetNumberOfFpuRegisters()) { |
| 1505 | return LocationFrom(calling_convention.GetFpuRegisterAt(float_index_++)); |
| 1506 | } else { |
| 1507 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
| 1508 | } |
| 1509 | } |
| 1510 | |
| 1511 | case Primitive::kPrimDouble: { |
| 1512 | double_index_ = std::max(double_index_, RoundUp(float_index_, 2)); |
| 1513 | uint32_t stack_index = stack_index_; |
| 1514 | stack_index_ += 2; |
| 1515 | if (double_index_ + 1 < calling_convention.GetNumberOfFpuRegisters()) { |
| 1516 | uint32_t index = double_index_; |
| 1517 | double_index_ += 2; |
| 1518 | Location result = LocationFrom( |
| 1519 | calling_convention.GetFpuRegisterAt(index), |
| 1520 | calling_convention.GetFpuRegisterAt(index + 1)); |
| 1521 | DCHECK(ExpectedPairLayout(result)); |
| 1522 | return result; |
| 1523 | } else { |
| 1524 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
| 1525 | } |
| 1526 | } |
| 1527 | |
| 1528 | case Primitive::kPrimVoid: |
| 1529 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 1530 | break; |
| 1531 | } |
| 1532 | return Location::NoLocation(); |
| 1533 | } |
| 1534 | |
| 1535 | Location InvokeDexCallingConventionVisitorARMVIXL::GetReturnLocation(Primitive::Type type) const { |
| 1536 | switch (type) { |
| 1537 | case Primitive::kPrimBoolean: |
| 1538 | case Primitive::kPrimByte: |
| 1539 | case Primitive::kPrimChar: |
| 1540 | case Primitive::kPrimShort: |
| 1541 | case Primitive::kPrimInt: |
| 1542 | case Primitive::kPrimNot: { |
| 1543 | return LocationFrom(r0); |
| 1544 | } |
| 1545 | |
| 1546 | case Primitive::kPrimFloat: { |
| 1547 | return LocationFrom(s0); |
| 1548 | } |
| 1549 | |
| 1550 | case Primitive::kPrimLong: { |
| 1551 | return LocationFrom(r0, r1); |
| 1552 | } |
| 1553 | |
| 1554 | case Primitive::kPrimDouble: { |
| 1555 | return LocationFrom(s0, s1); |
| 1556 | } |
| 1557 | |
| 1558 | case Primitive::kPrimVoid: |
| 1559 | return Location::NoLocation(); |
| 1560 | } |
| 1561 | |
| 1562 | UNREACHABLE(); |
| 1563 | } |
| 1564 | |
| 1565 | Location InvokeDexCallingConventionVisitorARMVIXL::GetMethodLocation() const { |
| 1566 | return LocationFrom(kMethodRegister); |
| 1567 | } |
| 1568 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 1569 | void CodeGeneratorARMVIXL::Move32(Location destination, Location source) { |
| 1570 | if (source.Equals(destination)) { |
| 1571 | return; |
| 1572 | } |
| 1573 | if (destination.IsRegister()) { |
| 1574 | if (source.IsRegister()) { |
| 1575 | __ Mov(RegisterFrom(destination), RegisterFrom(source)); |
| 1576 | } else if (source.IsFpuRegister()) { |
| 1577 | __ Vmov(RegisterFrom(destination), SRegisterFrom(source)); |
| 1578 | } else { |
| 1579 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 1580 | RegisterFrom(destination), |
| 1581 | sp, |
| 1582 | source.GetStackIndex()); |
| 1583 | } |
| 1584 | } else if (destination.IsFpuRegister()) { |
| 1585 | if (source.IsRegister()) { |
| 1586 | __ Vmov(SRegisterFrom(destination), RegisterFrom(source)); |
| 1587 | } else if (source.IsFpuRegister()) { |
| 1588 | __ Vmov(SRegisterFrom(destination), SRegisterFrom(source)); |
| 1589 | } else { |
| 1590 | GetAssembler()->LoadSFromOffset(SRegisterFrom(destination), sp, source.GetStackIndex()); |
| 1591 | } |
| 1592 | } else { |
| 1593 | DCHECK(destination.IsStackSlot()) << destination; |
| 1594 | if (source.IsRegister()) { |
| 1595 | GetAssembler()->StoreToOffset(kStoreWord, |
| 1596 | RegisterFrom(source), |
| 1597 | sp, |
| 1598 | destination.GetStackIndex()); |
| 1599 | } else if (source.IsFpuRegister()) { |
| 1600 | GetAssembler()->StoreSToOffset(SRegisterFrom(source), sp, destination.GetStackIndex()); |
| 1601 | } else { |
| 1602 | DCHECK(source.IsStackSlot()) << source; |
| 1603 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 1604 | vixl32::Register temp = temps.Acquire(); |
| 1605 | GetAssembler()->LoadFromOffset(kLoadWord, temp, sp, source.GetStackIndex()); |
| 1606 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, destination.GetStackIndex()); |
| 1607 | } |
| 1608 | } |
| 1609 | } |
| 1610 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 1611 | void CodeGeneratorARMVIXL::MoveConstant(Location location, int32_t value) { |
| 1612 | DCHECK(location.IsRegister()); |
| 1613 | __ Mov(RegisterFrom(location), value); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1614 | } |
| 1615 | |
| 1616 | void CodeGeneratorARMVIXL::MoveLocation(Location dst, Location src, Primitive::Type dst_type) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 1617 | // TODO(VIXL): Maybe refactor to have the 'move' implementation here and use it in |
| 1618 | // `ParallelMoveResolverARMVIXL::EmitMove`, as is done in the `arm64` backend. |
| 1619 | HParallelMove move(GetGraph()->GetArena()); |
| 1620 | move.AddMove(src, dst, dst_type, nullptr); |
| 1621 | GetMoveResolver()->EmitNativeCode(&move); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1622 | } |
| 1623 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 1624 | void CodeGeneratorARMVIXL::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1625 | if (location.IsRegister()) { |
| 1626 | locations->AddTemp(location); |
| 1627 | } else if (location.IsRegisterPair()) { |
| 1628 | locations->AddTemp(LocationFrom(LowRegisterFrom(location))); |
| 1629 | locations->AddTemp(LocationFrom(HighRegisterFrom(location))); |
| 1630 | } else { |
| 1631 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1632 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1633 | } |
| 1634 | |
| 1635 | void CodeGeneratorARMVIXL::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 1636 | HInstruction* instruction, |
| 1637 | uint32_t dex_pc, |
| 1638 | SlowPathCode* slow_path) { |
| 1639 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 1640 | __ Ldr(lr, MemOperand(tr, GetThreadOffset<kArmPointerSize>(entrypoint).Int32Value())); |
| 1641 | // Ensure the pc position is recorded immediately after the `blx` instruction. |
| 1642 | // 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] | 1643 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 1644 | vixl32::k16BitT32InstructionSizeInBytes, |
| 1645 | CodeBufferCheckScope::kExactSize); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 1646 | __ blx(lr); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1647 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 1648 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 1649 | } |
| 1650 | } |
| 1651 | |
| 1652 | void CodeGeneratorARMVIXL::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 1653 | HInstruction* instruction, |
| 1654 | SlowPathCode* slow_path) { |
| 1655 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 1656 | __ Ldr(lr, MemOperand(tr, entry_point_offset)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1657 | __ Blx(lr); |
| 1658 | } |
| 1659 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1660 | void InstructionCodeGeneratorARMVIXL::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
| 1661 | DCHECK(!successor->IsExitBlock()); |
| 1662 | HBasicBlock* block = got->GetBlock(); |
| 1663 | HInstruction* previous = got->GetPrevious(); |
| 1664 | HLoopInformation* info = block->GetLoopInformation(); |
| 1665 | |
| 1666 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
| 1667 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck()); |
| 1668 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 1669 | return; |
| 1670 | } |
| 1671 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 1672 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 1673 | } |
| 1674 | if (!codegen_->GoesToNextBlock(block, successor)) { |
| 1675 | __ B(codegen_->GetLabelOf(successor)); |
| 1676 | } |
| 1677 | } |
| 1678 | |
| 1679 | void LocationsBuilderARMVIXL::VisitGoto(HGoto* got) { |
| 1680 | got->SetLocations(nullptr); |
| 1681 | } |
| 1682 | |
| 1683 | void InstructionCodeGeneratorARMVIXL::VisitGoto(HGoto* got) { |
| 1684 | HandleGoto(got, got->GetSuccessor()); |
| 1685 | } |
| 1686 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 1687 | void LocationsBuilderARMVIXL::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1688 | try_boundary->SetLocations(nullptr); |
| 1689 | } |
| 1690 | |
| 1691 | void InstructionCodeGeneratorARMVIXL::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1692 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 1693 | if (!successor->IsExitBlock()) { |
| 1694 | HandleGoto(try_boundary, successor); |
| 1695 | } |
| 1696 | } |
| 1697 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1698 | void LocationsBuilderARMVIXL::VisitExit(HExit* exit) { |
| 1699 | exit->SetLocations(nullptr); |
| 1700 | } |
| 1701 | |
| 1702 | void InstructionCodeGeneratorARMVIXL::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
| 1703 | } |
| 1704 | |
| 1705 | void InstructionCodeGeneratorARMVIXL::GenerateVcmp(HInstruction* instruction) { |
| 1706 | Primitive::Type type = instruction->InputAt(0)->GetType(); |
| 1707 | Location lhs_loc = instruction->GetLocations()->InAt(0); |
| 1708 | Location rhs_loc = instruction->GetLocations()->InAt(1); |
| 1709 | if (rhs_loc.IsConstant()) { |
| 1710 | // 0.0 is the only immediate that can be encoded directly in |
| 1711 | // a VCMP instruction. |
| 1712 | // |
| 1713 | // Both the JLS (section 15.20.1) and the JVMS (section 6.5) |
| 1714 | // specify that in a floating-point comparison, positive zero |
| 1715 | // and negative zero are considered equal, so we can use the |
| 1716 | // literal 0.0 for both cases here. |
| 1717 | // |
| 1718 | // Note however that some methods (Float.equal, Float.compare, |
| 1719 | // Float.compareTo, Double.equal, Double.compare, |
| 1720 | // Double.compareTo, Math.max, Math.min, StrictMath.max, |
| 1721 | // StrictMath.min) consider 0.0 to be (strictly) greater than |
| 1722 | // -0.0. So if we ever translate calls to these methods into a |
| 1723 | // HCompare instruction, we must handle the -0.0 case with |
| 1724 | // care here. |
| 1725 | DCHECK(rhs_loc.GetConstant()->IsArithmeticZero()); |
| 1726 | if (type == Primitive::kPrimFloat) { |
| 1727 | __ Vcmp(F32, InputSRegisterAt(instruction, 0), 0.0); |
| 1728 | } else { |
| 1729 | DCHECK_EQ(type, Primitive::kPrimDouble); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 1730 | __ Vcmp(F64, DRegisterFrom(lhs_loc), 0.0); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1731 | } |
| 1732 | } else { |
| 1733 | if (type == Primitive::kPrimFloat) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 1734 | __ Vcmp(InputSRegisterAt(instruction, 0), InputSRegisterAt(instruction, 1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1735 | } else { |
| 1736 | DCHECK_EQ(type, Primitive::kPrimDouble); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 1737 | __ Vcmp(DRegisterFrom(lhs_loc), DRegisterFrom(rhs_loc)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1738 | } |
| 1739 | } |
| 1740 | } |
| 1741 | |
| 1742 | void InstructionCodeGeneratorARMVIXL::GenerateFPJumps(HCondition* cond, |
| 1743 | vixl32::Label* true_label, |
| 1744 | vixl32::Label* false_label ATTRIBUTE_UNUSED) { |
| 1745 | // To branch on the result of the FP compare we transfer FPSCR to APSR (encoded as PC in VMRS). |
| 1746 | __ Vmrs(RegisterOrAPSR_nzcv(kPcCode), FPSCR); |
| 1747 | __ B(ARMFPCondition(cond->GetCondition(), cond->IsGtBias()), true_label); |
| 1748 | } |
| 1749 | |
| 1750 | void InstructionCodeGeneratorARMVIXL::GenerateLongComparesAndJumps(HCondition* cond, |
| 1751 | vixl32::Label* true_label, |
| 1752 | vixl32::Label* false_label) { |
| 1753 | LocationSummary* locations = cond->GetLocations(); |
| 1754 | Location left = locations->InAt(0); |
| 1755 | Location right = locations->InAt(1); |
| 1756 | IfCondition if_cond = cond->GetCondition(); |
| 1757 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 1758 | vixl32::Register left_high = HighRegisterFrom(left); |
| 1759 | vixl32::Register left_low = LowRegisterFrom(left); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1760 | IfCondition true_high_cond = if_cond; |
| 1761 | IfCondition false_high_cond = cond->GetOppositeCondition(); |
| 1762 | vixl32::Condition final_condition = ARMUnsignedCondition(if_cond); // unsigned on lower part |
| 1763 | |
| 1764 | // Set the conditions for the test, remembering that == needs to be |
| 1765 | // decided using the low words. |
| 1766 | // TODO: consider avoiding jumps with temporary and CMP low+SBC high |
| 1767 | switch (if_cond) { |
| 1768 | case kCondEQ: |
| 1769 | case kCondNE: |
| 1770 | // Nothing to do. |
| 1771 | break; |
| 1772 | case kCondLT: |
| 1773 | false_high_cond = kCondGT; |
| 1774 | break; |
| 1775 | case kCondLE: |
| 1776 | true_high_cond = kCondLT; |
| 1777 | break; |
| 1778 | case kCondGT: |
| 1779 | false_high_cond = kCondLT; |
| 1780 | break; |
| 1781 | case kCondGE: |
| 1782 | true_high_cond = kCondGT; |
| 1783 | break; |
| 1784 | case kCondB: |
| 1785 | false_high_cond = kCondA; |
| 1786 | break; |
| 1787 | case kCondBE: |
| 1788 | true_high_cond = kCondB; |
| 1789 | break; |
| 1790 | case kCondA: |
| 1791 | false_high_cond = kCondB; |
| 1792 | break; |
| 1793 | case kCondAE: |
| 1794 | true_high_cond = kCondA; |
| 1795 | break; |
| 1796 | } |
| 1797 | if (right.IsConstant()) { |
| 1798 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
| 1799 | int32_t val_low = Low32Bits(value); |
| 1800 | int32_t val_high = High32Bits(value); |
| 1801 | |
| 1802 | __ Cmp(left_high, val_high); |
| 1803 | if (if_cond == kCondNE) { |
| 1804 | __ B(ARMCondition(true_high_cond), true_label); |
| 1805 | } else if (if_cond == kCondEQ) { |
| 1806 | __ B(ARMCondition(false_high_cond), false_label); |
| 1807 | } else { |
| 1808 | __ B(ARMCondition(true_high_cond), true_label); |
| 1809 | __ B(ARMCondition(false_high_cond), false_label); |
| 1810 | } |
| 1811 | // Must be equal high, so compare the lows. |
| 1812 | __ Cmp(left_low, val_low); |
| 1813 | } else { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 1814 | vixl32::Register right_high = HighRegisterFrom(right); |
| 1815 | vixl32::Register right_low = LowRegisterFrom(right); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1816 | |
| 1817 | __ Cmp(left_high, right_high); |
| 1818 | if (if_cond == kCondNE) { |
| 1819 | __ B(ARMCondition(true_high_cond), true_label); |
| 1820 | } else if (if_cond == kCondEQ) { |
| 1821 | __ B(ARMCondition(false_high_cond), false_label); |
| 1822 | } else { |
| 1823 | __ B(ARMCondition(true_high_cond), true_label); |
| 1824 | __ B(ARMCondition(false_high_cond), false_label); |
| 1825 | } |
| 1826 | // Must be equal high, so compare the lows. |
| 1827 | __ Cmp(left_low, right_low); |
| 1828 | } |
| 1829 | // The last comparison might be unsigned. |
| 1830 | // TODO: optimize cases where this is always true/false |
| 1831 | __ B(final_condition, true_label); |
| 1832 | } |
| 1833 | |
| 1834 | void InstructionCodeGeneratorARMVIXL::GenerateCompareTestAndBranch(HCondition* condition, |
| 1835 | vixl32::Label* true_target_in, |
| 1836 | vixl32::Label* false_target_in) { |
| 1837 | // Generated branching requires both targets to be explicit. If either of the |
| 1838 | // targets is nullptr (fallthrough) use and bind `fallthrough` instead. |
| 1839 | vixl32::Label fallthrough; |
| 1840 | vixl32::Label* true_target = (true_target_in == nullptr) ? &fallthrough : true_target_in; |
| 1841 | vixl32::Label* false_target = (false_target_in == nullptr) ? &fallthrough : false_target_in; |
| 1842 | |
| 1843 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1844 | switch (type) { |
| 1845 | case Primitive::kPrimLong: |
| 1846 | GenerateLongComparesAndJumps(condition, true_target, false_target); |
| 1847 | break; |
| 1848 | case Primitive::kPrimFloat: |
| 1849 | case Primitive::kPrimDouble: |
| 1850 | GenerateVcmp(condition); |
| 1851 | GenerateFPJumps(condition, true_target, false_target); |
| 1852 | break; |
| 1853 | default: |
| 1854 | LOG(FATAL) << "Unexpected compare type " << type; |
| 1855 | } |
| 1856 | |
| 1857 | if (false_target != &fallthrough) { |
| 1858 | __ B(false_target); |
| 1859 | } |
| 1860 | |
| 1861 | if (true_target_in == nullptr || false_target_in == nullptr) { |
| 1862 | __ Bind(&fallthrough); |
| 1863 | } |
| 1864 | } |
| 1865 | |
| 1866 | void InstructionCodeGeneratorARMVIXL::GenerateTestAndBranch(HInstruction* instruction, |
| 1867 | size_t condition_input_index, |
| 1868 | vixl32::Label* true_target, |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 1869 | vixl32::Label* false_target, |
| 1870 | bool far_target) { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1871 | HInstruction* cond = instruction->InputAt(condition_input_index); |
| 1872 | |
| 1873 | if (true_target == nullptr && false_target == nullptr) { |
| 1874 | // Nothing to do. The code always falls through. |
| 1875 | return; |
| 1876 | } else if (cond->IsIntConstant()) { |
| 1877 | // Constant condition, statically compared against "true" (integer value 1). |
| 1878 | if (cond->AsIntConstant()->IsTrue()) { |
| 1879 | if (true_target != nullptr) { |
| 1880 | __ B(true_target); |
| 1881 | } |
| 1882 | } else { |
| 1883 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
| 1884 | if (false_target != nullptr) { |
| 1885 | __ B(false_target); |
| 1886 | } |
| 1887 | } |
| 1888 | return; |
| 1889 | } |
| 1890 | |
| 1891 | // The following code generates these patterns: |
| 1892 | // (1) true_target == nullptr && false_target != nullptr |
| 1893 | // - opposite condition true => branch to false_target |
| 1894 | // (2) true_target != nullptr && false_target == nullptr |
| 1895 | // - condition true => branch to true_target |
| 1896 | // (3) true_target != nullptr && false_target != nullptr |
| 1897 | // - condition true => branch to true_target |
| 1898 | // - branch to false_target |
| 1899 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 1900 | // Condition has been materialized, compare the output to 0. |
| 1901 | if (kIsDebugBuild) { |
| 1902 | Location cond_val = instruction->GetLocations()->InAt(condition_input_index); |
| 1903 | DCHECK(cond_val.IsRegister()); |
| 1904 | } |
| 1905 | if (true_target == nullptr) { |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 1906 | __ CompareAndBranchIfZero(InputRegisterAt(instruction, condition_input_index), |
| 1907 | false_target, |
| 1908 | far_target); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1909 | } else { |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 1910 | __ CompareAndBranchIfNonZero(InputRegisterAt(instruction, condition_input_index), |
| 1911 | true_target, |
| 1912 | far_target); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1913 | } |
| 1914 | } else { |
| 1915 | // Condition has not been materialized. Use its inputs as the comparison and |
| 1916 | // its condition as the branch condition. |
| 1917 | HCondition* condition = cond->AsCondition(); |
| 1918 | |
| 1919 | // If this is a long or FP comparison that has been folded into |
| 1920 | // the HCondition, generate the comparison directly. |
| 1921 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1922 | if (type == Primitive::kPrimLong || Primitive::IsFloatingPointType(type)) { |
| 1923 | GenerateCompareTestAndBranch(condition, true_target, false_target); |
| 1924 | return; |
| 1925 | } |
| 1926 | |
| 1927 | LocationSummary* locations = cond->GetLocations(); |
| 1928 | DCHECK(locations->InAt(0).IsRegister()); |
| 1929 | vixl32::Register left = InputRegisterAt(cond, 0); |
| 1930 | Location right = locations->InAt(1); |
| 1931 | if (right.IsRegister()) { |
| 1932 | __ Cmp(left, InputRegisterAt(cond, 1)); |
| 1933 | } else { |
| 1934 | DCHECK(right.IsConstant()); |
| 1935 | __ Cmp(left, CodeGenerator::GetInt32ValueOf(right.GetConstant())); |
| 1936 | } |
| 1937 | if (true_target == nullptr) { |
| 1938 | __ B(ARMCondition(condition->GetOppositeCondition()), false_target); |
| 1939 | } else { |
| 1940 | __ B(ARMCondition(condition->GetCondition()), true_target); |
| 1941 | } |
| 1942 | } |
| 1943 | |
| 1944 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 1945 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 1946 | if (true_target != nullptr && false_target != nullptr) { |
| 1947 | __ B(false_target); |
| 1948 | } |
| 1949 | } |
| 1950 | |
| 1951 | void LocationsBuilderARMVIXL::VisitIf(HIf* if_instr) { |
| 1952 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); |
| 1953 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
| 1954 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1955 | } |
| 1956 | } |
| 1957 | |
| 1958 | void InstructionCodeGeneratorARMVIXL::VisitIf(HIf* if_instr) { |
| 1959 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 1960 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 1961 | vixl32::Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 1962 | nullptr : codegen_->GetLabelOf(true_successor); |
| 1963 | vixl32::Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 1964 | nullptr : codegen_->GetLabelOf(false_successor); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1965 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
| 1966 | } |
| 1967 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 1968 | void LocationsBuilderARMVIXL::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 1969 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 1970 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
| 1971 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| 1972 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
| 1973 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1974 | } |
| 1975 | } |
| 1976 | |
| 1977 | void InstructionCodeGeneratorARMVIXL::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 1978 | SlowPathCodeARMVIXL* slow_path = |
| 1979 | deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathARMVIXL>(deoptimize); |
| 1980 | GenerateTestAndBranch(deoptimize, |
| 1981 | /* condition_input_index */ 0, |
| 1982 | slow_path->GetEntryLabel(), |
| 1983 | /* false_target */ nullptr); |
| 1984 | } |
| 1985 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 1986 | void LocationsBuilderARMVIXL::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 1987 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 1988 | LocationSummary(flag, LocationSummary::kNoCall); |
| 1989 | locations->SetOut(Location::RequiresRegister()); |
| 1990 | } |
| 1991 | |
| 1992 | void InstructionCodeGeneratorARMVIXL::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 1993 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 1994 | OutputRegister(flag), |
| 1995 | sp, |
| 1996 | codegen_->GetStackOffsetOfShouldDeoptimizeFlag()); |
| 1997 | } |
| 1998 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 1999 | void LocationsBuilderARMVIXL::VisitSelect(HSelect* select) { |
| 2000 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(select); |
| 2001 | if (Primitive::IsFloatingPointType(select->GetType())) { |
| 2002 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2003 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2004 | } else { |
| 2005 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2006 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2007 | } |
| 2008 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
| 2009 | locations->SetInAt(2, Location::RequiresRegister()); |
| 2010 | } |
| 2011 | locations->SetOut(Location::SameAsFirstInput()); |
| 2012 | } |
| 2013 | |
| 2014 | void InstructionCodeGeneratorARMVIXL::VisitSelect(HSelect* select) { |
| 2015 | LocationSummary* locations = select->GetLocations(); |
| 2016 | vixl32::Label false_target; |
| 2017 | GenerateTestAndBranch(select, |
| 2018 | /* condition_input_index */ 2, |
| 2019 | /* true_target */ nullptr, |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 2020 | &false_target, |
| 2021 | /* far_target */ false); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2022 | codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType()); |
| 2023 | __ Bind(&false_target); |
| 2024 | } |
| 2025 | |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 2026 | void LocationsBuilderARMVIXL::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| 2027 | new (GetGraph()->GetArena()) LocationSummary(info); |
| 2028 | } |
| 2029 | |
| 2030 | void InstructionCodeGeneratorARMVIXL::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 2031 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
| 2032 | } |
| 2033 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2034 | void CodeGeneratorARMVIXL::GenerateNop() { |
| 2035 | __ Nop(); |
| 2036 | } |
| 2037 | |
| 2038 | void LocationsBuilderARMVIXL::HandleCondition(HCondition* cond) { |
| 2039 | LocationSummary* locations = |
| 2040 | new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall); |
| 2041 | // Handle the long/FP comparisons made in instruction simplification. |
| 2042 | switch (cond->InputAt(0)->GetType()) { |
| 2043 | case Primitive::kPrimLong: |
| 2044 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2045 | locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1))); |
| 2046 | if (!cond->IsEmittedAtUseSite()) { |
| 2047 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 2048 | } |
| 2049 | break; |
| 2050 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2051 | case Primitive::kPrimFloat: |
| 2052 | case Primitive::kPrimDouble: |
| 2053 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 2054 | locations->SetInAt(1, ArithmeticZeroOrFpuRegister(cond->InputAt(1))); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2055 | if (!cond->IsEmittedAtUseSite()) { |
| 2056 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2057 | } |
| 2058 | break; |
| 2059 | |
| 2060 | default: |
| 2061 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2062 | locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1))); |
| 2063 | if (!cond->IsEmittedAtUseSite()) { |
| 2064 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2065 | } |
| 2066 | } |
| 2067 | } |
| 2068 | |
| 2069 | void InstructionCodeGeneratorARMVIXL::HandleCondition(HCondition* cond) { |
| 2070 | if (cond->IsEmittedAtUseSite()) { |
| 2071 | return; |
| 2072 | } |
| 2073 | |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 2074 | Location right = cond->GetLocations()->InAt(1); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2075 | vixl32::Register out = OutputRegister(cond); |
| 2076 | vixl32::Label true_label, false_label; |
| 2077 | |
| 2078 | switch (cond->InputAt(0)->GetType()) { |
| 2079 | default: { |
| 2080 | // Integer case. |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 2081 | if (right.IsRegister()) { |
| 2082 | __ Cmp(InputRegisterAt(cond, 0), InputOperandAt(cond, 1)); |
| 2083 | } else { |
| 2084 | DCHECK(right.IsConstant()); |
| 2085 | __ Cmp(InputRegisterAt(cond, 0), |
| 2086 | CodeGenerator::GetInt32ValueOf(right.GetConstant())); |
| 2087 | } |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 2088 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 2089 | 3 * vixl32::kMaxInstructionSizeInBytes, |
| 2090 | CodeBufferCheckScope::kMaximumSize); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2091 | __ ite(ARMCondition(cond->GetCondition())); |
| 2092 | __ mov(ARMCondition(cond->GetCondition()), OutputRegister(cond), 1); |
| 2093 | __ mov(ARMCondition(cond->GetOppositeCondition()), OutputRegister(cond), 0); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2094 | return; |
| 2095 | } |
| 2096 | case Primitive::kPrimLong: |
| 2097 | GenerateLongComparesAndJumps(cond, &true_label, &false_label); |
| 2098 | break; |
| 2099 | case Primitive::kPrimFloat: |
| 2100 | case Primitive::kPrimDouble: |
| 2101 | GenerateVcmp(cond); |
| 2102 | GenerateFPJumps(cond, &true_label, &false_label); |
| 2103 | break; |
| 2104 | } |
| 2105 | |
| 2106 | // Convert the jumps into the result. |
| 2107 | vixl32::Label done_label; |
| 2108 | |
| 2109 | // False case: result = 0. |
| 2110 | __ Bind(&false_label); |
| 2111 | __ Mov(out, 0); |
| 2112 | __ B(&done_label); |
| 2113 | |
| 2114 | // True case: result = 1. |
| 2115 | __ Bind(&true_label); |
| 2116 | __ Mov(out, 1); |
| 2117 | __ Bind(&done_label); |
| 2118 | } |
| 2119 | |
| 2120 | void LocationsBuilderARMVIXL::VisitEqual(HEqual* comp) { |
| 2121 | HandleCondition(comp); |
| 2122 | } |
| 2123 | |
| 2124 | void InstructionCodeGeneratorARMVIXL::VisitEqual(HEqual* comp) { |
| 2125 | HandleCondition(comp); |
| 2126 | } |
| 2127 | |
| 2128 | void LocationsBuilderARMVIXL::VisitNotEqual(HNotEqual* comp) { |
| 2129 | HandleCondition(comp); |
| 2130 | } |
| 2131 | |
| 2132 | void InstructionCodeGeneratorARMVIXL::VisitNotEqual(HNotEqual* comp) { |
| 2133 | HandleCondition(comp); |
| 2134 | } |
| 2135 | |
| 2136 | void LocationsBuilderARMVIXL::VisitLessThan(HLessThan* comp) { |
| 2137 | HandleCondition(comp); |
| 2138 | } |
| 2139 | |
| 2140 | void InstructionCodeGeneratorARMVIXL::VisitLessThan(HLessThan* comp) { |
| 2141 | HandleCondition(comp); |
| 2142 | } |
| 2143 | |
| 2144 | void LocationsBuilderARMVIXL::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| 2145 | HandleCondition(comp); |
| 2146 | } |
| 2147 | |
| 2148 | void InstructionCodeGeneratorARMVIXL::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| 2149 | HandleCondition(comp); |
| 2150 | } |
| 2151 | |
| 2152 | void LocationsBuilderARMVIXL::VisitGreaterThan(HGreaterThan* comp) { |
| 2153 | HandleCondition(comp); |
| 2154 | } |
| 2155 | |
| 2156 | void InstructionCodeGeneratorARMVIXL::VisitGreaterThan(HGreaterThan* comp) { |
| 2157 | HandleCondition(comp); |
| 2158 | } |
| 2159 | |
| 2160 | void LocationsBuilderARMVIXL::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| 2161 | HandleCondition(comp); |
| 2162 | } |
| 2163 | |
| 2164 | void InstructionCodeGeneratorARMVIXL::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| 2165 | HandleCondition(comp); |
| 2166 | } |
| 2167 | |
| 2168 | void LocationsBuilderARMVIXL::VisitBelow(HBelow* comp) { |
| 2169 | HandleCondition(comp); |
| 2170 | } |
| 2171 | |
| 2172 | void InstructionCodeGeneratorARMVIXL::VisitBelow(HBelow* comp) { |
| 2173 | HandleCondition(comp); |
| 2174 | } |
| 2175 | |
| 2176 | void LocationsBuilderARMVIXL::VisitBelowOrEqual(HBelowOrEqual* comp) { |
| 2177 | HandleCondition(comp); |
| 2178 | } |
| 2179 | |
| 2180 | void InstructionCodeGeneratorARMVIXL::VisitBelowOrEqual(HBelowOrEqual* comp) { |
| 2181 | HandleCondition(comp); |
| 2182 | } |
| 2183 | |
| 2184 | void LocationsBuilderARMVIXL::VisitAbove(HAbove* comp) { |
| 2185 | HandleCondition(comp); |
| 2186 | } |
| 2187 | |
| 2188 | void InstructionCodeGeneratorARMVIXL::VisitAbove(HAbove* comp) { |
| 2189 | HandleCondition(comp); |
| 2190 | } |
| 2191 | |
| 2192 | void LocationsBuilderARMVIXL::VisitAboveOrEqual(HAboveOrEqual* comp) { |
| 2193 | HandleCondition(comp); |
| 2194 | } |
| 2195 | |
| 2196 | void InstructionCodeGeneratorARMVIXL::VisitAboveOrEqual(HAboveOrEqual* comp) { |
| 2197 | HandleCondition(comp); |
| 2198 | } |
| 2199 | |
| 2200 | void LocationsBuilderARMVIXL::VisitIntConstant(HIntConstant* constant) { |
| 2201 | LocationSummary* locations = |
| 2202 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 2203 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2204 | } |
| 2205 | |
| 2206 | void InstructionCodeGeneratorARMVIXL::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
| 2207 | // Will be generated at use site. |
| 2208 | } |
| 2209 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2210 | void LocationsBuilderARMVIXL::VisitNullConstant(HNullConstant* constant) { |
| 2211 | LocationSummary* locations = |
| 2212 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 2213 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2214 | } |
| 2215 | |
| 2216 | void InstructionCodeGeneratorARMVIXL::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
| 2217 | // Will be generated at use site. |
| 2218 | } |
| 2219 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2220 | void LocationsBuilderARMVIXL::VisitLongConstant(HLongConstant* constant) { |
| 2221 | LocationSummary* locations = |
| 2222 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 2223 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2224 | } |
| 2225 | |
| 2226 | void InstructionCodeGeneratorARMVIXL::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
| 2227 | // Will be generated at use site. |
| 2228 | } |
| 2229 | |
Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 2230 | void LocationsBuilderARMVIXL::VisitFloatConstant(HFloatConstant* constant) { |
| 2231 | LocationSummary* locations = |
| 2232 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 2233 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2234 | } |
| 2235 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 2236 | void InstructionCodeGeneratorARMVIXL::VisitFloatConstant( |
| 2237 | HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 2238 | // Will be generated at use site. |
| 2239 | } |
| 2240 | |
| 2241 | void LocationsBuilderARMVIXL::VisitDoubleConstant(HDoubleConstant* constant) { |
| 2242 | LocationSummary* locations = |
| 2243 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 2244 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2245 | } |
| 2246 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 2247 | void InstructionCodeGeneratorARMVIXL::VisitDoubleConstant( |
| 2248 | HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 2249 | // Will be generated at use site. |
| 2250 | } |
| 2251 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2252 | void LocationsBuilderARMVIXL::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 2253 | memory_barrier->SetLocations(nullptr); |
| 2254 | } |
| 2255 | |
| 2256 | void InstructionCodeGeneratorARMVIXL::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 2257 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
| 2258 | } |
| 2259 | |
| 2260 | void LocationsBuilderARMVIXL::VisitReturnVoid(HReturnVoid* ret) { |
| 2261 | ret->SetLocations(nullptr); |
| 2262 | } |
| 2263 | |
| 2264 | void InstructionCodeGeneratorARMVIXL::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
| 2265 | codegen_->GenerateFrameExit(); |
| 2266 | } |
| 2267 | |
| 2268 | void LocationsBuilderARMVIXL::VisitReturn(HReturn* ret) { |
| 2269 | LocationSummary* locations = |
| 2270 | new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall); |
| 2271 | locations->SetInAt(0, parameter_visitor_.GetReturnLocation(ret->InputAt(0)->GetType())); |
| 2272 | } |
| 2273 | |
| 2274 | void InstructionCodeGeneratorARMVIXL::VisitReturn(HReturn* ret ATTRIBUTE_UNUSED) { |
| 2275 | codegen_->GenerateFrameExit(); |
| 2276 | } |
| 2277 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 2278 | void LocationsBuilderARMVIXL::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2279 | // The trampoline uses the same calling convention as dex calling conventions, |
| 2280 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 2281 | // the method_idx. |
| 2282 | HandleInvoke(invoke); |
| 2283 | } |
| 2284 | |
| 2285 | void InstructionCodeGeneratorARMVIXL::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2286 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 2287 | } |
| 2288 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2289 | void LocationsBuilderARMVIXL::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
| 2290 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2291 | // art::PrepareForRegisterAllocation. |
| 2292 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
| 2293 | |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 2294 | IntrinsicLocationsBuilderARMVIXL intrinsic(codegen_); |
| 2295 | if (intrinsic.TryDispatch(invoke)) { |
| 2296 | if (invoke->GetLocations()->CanCall() && invoke->HasPcRelativeDexCache()) { |
| 2297 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::Any()); |
| 2298 | } |
| 2299 | return; |
| 2300 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2301 | |
| 2302 | HandleInvoke(invoke); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 2303 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2304 | // For PC-relative dex cache the invoke has an extra input, the PC-relative address base. |
| 2305 | if (invoke->HasPcRelativeDexCache()) { |
| 2306 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::RequiresRegister()); |
| 2307 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2308 | } |
| 2309 | |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 2310 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARMVIXL* codegen) { |
| 2311 | if (invoke->GetLocations()->Intrinsified()) { |
| 2312 | IntrinsicCodeGeneratorARMVIXL intrinsic(codegen); |
| 2313 | intrinsic.Dispatch(invoke); |
| 2314 | return true; |
| 2315 | } |
| 2316 | return false; |
| 2317 | } |
| 2318 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2319 | void InstructionCodeGeneratorARMVIXL::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
| 2320 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2321 | // art::PrepareForRegisterAllocation. |
| 2322 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
| 2323 | |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 2324 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2325 | return; |
| 2326 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2327 | |
| 2328 | LocationSummary* locations = invoke->GetLocations(); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2329 | codegen_->GenerateStaticOrDirectCall( |
| 2330 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2331 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 2332 | } |
| 2333 | |
| 2334 | void LocationsBuilderARMVIXL::HandleInvoke(HInvoke* invoke) { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2335 | InvokeDexCallingConventionVisitorARMVIXL calling_convention_visitor; |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2336 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
| 2337 | } |
| 2338 | |
| 2339 | void LocationsBuilderARMVIXL::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 2340 | IntrinsicLocationsBuilderARMVIXL intrinsic(codegen_); |
| 2341 | if (intrinsic.TryDispatch(invoke)) { |
| 2342 | return; |
| 2343 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2344 | |
| 2345 | HandleInvoke(invoke); |
| 2346 | } |
| 2347 | |
| 2348 | void InstructionCodeGeneratorARMVIXL::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 2349 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2350 | return; |
| 2351 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2352 | |
| 2353 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2354 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 2355 | DCHECK(!codegen_->IsLeafMethod()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2356 | } |
| 2357 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 2358 | void LocationsBuilderARMVIXL::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2359 | HandleInvoke(invoke); |
| 2360 | // Add the hidden argument. |
| 2361 | invoke->GetLocations()->AddTemp(LocationFrom(r12)); |
| 2362 | } |
| 2363 | |
| 2364 | void InstructionCodeGeneratorARMVIXL::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2365 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
| 2366 | LocationSummary* locations = invoke->GetLocations(); |
| 2367 | vixl32::Register temp = RegisterFrom(locations->GetTemp(0)); |
| 2368 | vixl32::Register hidden_reg = RegisterFrom(locations->GetTemp(1)); |
| 2369 | Location receiver = locations->InAt(0); |
| 2370 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2371 | |
| 2372 | DCHECK(!receiver.IsStackSlot()); |
| 2373 | |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 2374 | // Ensure the pc position is recorded immediately after the `ldr` instruction. |
| 2375 | { |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 2376 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 2377 | vixl32::kMaxInstructionSizeInBytes, |
| 2378 | CodeBufferCheckScope::kMaximumSize); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 2379 | // /* HeapReference<Class> */ temp = receiver->klass_ |
| 2380 | __ ldr(temp, MemOperand(RegisterFrom(receiver), class_offset)); |
| 2381 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
| 2382 | } |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 2383 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 2384 | // emit a read barrier for the previous class reference load. |
| 2385 | // However this is not required in practice, as this is an |
| 2386 | // intermediate/temporary reference and because the current |
| 2387 | // concurrent copying collector keeps the from-space memory |
| 2388 | // intact/accessible until the end of the marking phase (the |
| 2389 | // concurrent copying collector may not in the future). |
| 2390 | GetAssembler()->MaybeUnpoisonHeapReference(temp); |
| 2391 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 2392 | temp, |
| 2393 | temp, |
| 2394 | mirror::Class::ImtPtrOffset(kArmPointerSize).Uint32Value()); |
| 2395 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
| 2396 | invoke->GetImtIndex(), kArmPointerSize)); |
| 2397 | // temp = temp->GetImtEntryAt(method_offset); |
| 2398 | GetAssembler()->LoadFromOffset(kLoadWord, temp, temp, method_offset); |
| 2399 | uint32_t entry_point = |
| 2400 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize).Int32Value(); |
| 2401 | // LR = temp->GetEntryPoint(); |
| 2402 | GetAssembler()->LoadFromOffset(kLoadWord, lr, temp, entry_point); |
| 2403 | |
| 2404 | // Set the hidden (in r12) argument. It is done here, right before a BLX to prevent other |
| 2405 | // instruction from clobbering it as they might use r12 as a scratch register. |
| 2406 | DCHECK(hidden_reg.Is(r12)); |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 2407 | |
| 2408 | { |
| 2409 | // The VIXL macro assembler may clobber any of the scratch registers that are available to it, |
| 2410 | // so it checks if the application is using them (by passing them to the macro assembler |
| 2411 | // methods). The following application of UseScratchRegisterScope corrects VIXL's notion of |
| 2412 | // what is available, and is the opposite of the standard usage: Instead of requesting a |
| 2413 | // temporary location, it imposes an external constraint (i.e. a specific register is reserved |
| 2414 | // for the hidden argument). Note that this works even if VIXL needs a scratch register itself |
| 2415 | // (to materialize the constant), since the destination register becomes available for such use |
| 2416 | // internally for the duration of the macro instruction. |
| 2417 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2418 | temps.Exclude(hidden_reg); |
| 2419 | __ Mov(hidden_reg, invoke->GetDexMethodIndex()); |
| 2420 | } |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 2421 | { |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 2422 | // Ensure the pc position is recorded immediately after the `blx` instruction. |
| 2423 | // 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] | 2424 | ExactAssemblyScope aas(GetVIXLAssembler(), |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 2425 | vixl32::k16BitT32InstructionSizeInBytes, |
| 2426 | CodeBufferCheckScope::kExactSize); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 2427 | // LR(); |
| 2428 | __ blx(lr); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 2429 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 2430 | DCHECK(!codegen_->IsLeafMethod()); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 2431 | } |
| 2432 | } |
| 2433 | |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 2434 | void LocationsBuilderARMVIXL::VisitNeg(HNeg* neg) { |
| 2435 | LocationSummary* locations = |
| 2436 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 2437 | switch (neg->GetResultType()) { |
| 2438 | case Primitive::kPrimInt: { |
| 2439 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2440 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2441 | break; |
| 2442 | } |
| 2443 | case Primitive::kPrimLong: { |
| 2444 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2445 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 2446 | break; |
| 2447 | } |
| 2448 | |
| 2449 | case Primitive::kPrimFloat: |
| 2450 | case Primitive::kPrimDouble: |
| 2451 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2452 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 2453 | break; |
| 2454 | |
| 2455 | default: |
| 2456 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2457 | } |
| 2458 | } |
| 2459 | |
| 2460 | void InstructionCodeGeneratorARMVIXL::VisitNeg(HNeg* neg) { |
| 2461 | LocationSummary* locations = neg->GetLocations(); |
| 2462 | Location out = locations->Out(); |
| 2463 | Location in = locations->InAt(0); |
| 2464 | switch (neg->GetResultType()) { |
| 2465 | case Primitive::kPrimInt: |
| 2466 | __ Rsb(OutputRegister(neg), InputRegisterAt(neg, 0), 0); |
| 2467 | break; |
| 2468 | |
| 2469 | case Primitive::kPrimLong: |
| 2470 | // out.lo = 0 - in.lo (and update the carry/borrow (C) flag) |
| 2471 | __ Rsbs(LowRegisterFrom(out), LowRegisterFrom(in), 0); |
| 2472 | // We cannot emit an RSC (Reverse Subtract with Carry) |
| 2473 | // instruction here, as it does not exist in the Thumb-2 |
| 2474 | // instruction set. We use the following approach |
| 2475 | // using SBC and SUB instead. |
| 2476 | // |
| 2477 | // out.hi = -C |
| 2478 | __ Sbc(HighRegisterFrom(out), HighRegisterFrom(out), HighRegisterFrom(out)); |
| 2479 | // out.hi = out.hi - in.hi |
| 2480 | __ Sub(HighRegisterFrom(out), HighRegisterFrom(out), HighRegisterFrom(in)); |
| 2481 | break; |
| 2482 | |
| 2483 | case Primitive::kPrimFloat: |
| 2484 | case Primitive::kPrimDouble: |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 2485 | // TODO(VIXL): Consider introducing an InputVRegister() |
| 2486 | // helper function (equivalent to InputRegister()). |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 2487 | __ Vneg(OutputVRegister(neg), InputVRegisterAt(neg, 0)); |
| 2488 | break; |
| 2489 | |
| 2490 | default: |
| 2491 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2492 | } |
| 2493 | } |
| 2494 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2495 | void LocationsBuilderARMVIXL::VisitTypeConversion(HTypeConversion* conversion) { |
| 2496 | Primitive::Type result_type = conversion->GetResultType(); |
| 2497 | Primitive::Type input_type = conversion->GetInputType(); |
| 2498 | DCHECK_NE(result_type, input_type); |
| 2499 | |
| 2500 | // The float-to-long, double-to-long and long-to-float type conversions |
| 2501 | // rely on a call to the runtime. |
| 2502 | LocationSummary::CallKind call_kind = |
| 2503 | (((input_type == Primitive::kPrimFloat || input_type == Primitive::kPrimDouble) |
| 2504 | && result_type == Primitive::kPrimLong) |
| 2505 | || (input_type == Primitive::kPrimLong && result_type == Primitive::kPrimFloat)) |
| 2506 | ? LocationSummary::kCallOnMainOnly |
| 2507 | : LocationSummary::kNoCall; |
| 2508 | LocationSummary* locations = |
| 2509 | new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind); |
| 2510 | |
| 2511 | // The Java language does not allow treating boolean as an integral type but |
| 2512 | // our bit representation makes it safe. |
| 2513 | |
| 2514 | switch (result_type) { |
| 2515 | case Primitive::kPrimByte: |
| 2516 | switch (input_type) { |
| 2517 | case Primitive::kPrimLong: |
| 2518 | // Type conversion from long to byte is a result of code transformations. |
| 2519 | case Primitive::kPrimBoolean: |
| 2520 | // Boolean input is a result of code transformations. |
| 2521 | case Primitive::kPrimShort: |
| 2522 | case Primitive::kPrimInt: |
| 2523 | case Primitive::kPrimChar: |
| 2524 | // Processing a Dex `int-to-byte' instruction. |
| 2525 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2526 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2527 | break; |
| 2528 | |
| 2529 | default: |
| 2530 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2531 | << " to " << result_type; |
| 2532 | } |
| 2533 | break; |
| 2534 | |
| 2535 | case Primitive::kPrimShort: |
| 2536 | switch (input_type) { |
| 2537 | case Primitive::kPrimLong: |
| 2538 | // Type conversion from long to short is a result of code transformations. |
| 2539 | case Primitive::kPrimBoolean: |
| 2540 | // Boolean input is a result of code transformations. |
| 2541 | case Primitive::kPrimByte: |
| 2542 | case Primitive::kPrimInt: |
| 2543 | case Primitive::kPrimChar: |
| 2544 | // Processing a Dex `int-to-short' instruction. |
| 2545 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2546 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2547 | break; |
| 2548 | |
| 2549 | default: |
| 2550 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2551 | << " to " << result_type; |
| 2552 | } |
| 2553 | break; |
| 2554 | |
| 2555 | case Primitive::kPrimInt: |
| 2556 | switch (input_type) { |
| 2557 | case Primitive::kPrimLong: |
| 2558 | // Processing a Dex `long-to-int' instruction. |
| 2559 | locations->SetInAt(0, Location::Any()); |
| 2560 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2561 | break; |
| 2562 | |
| 2563 | case Primitive::kPrimFloat: |
| 2564 | // Processing a Dex `float-to-int' instruction. |
| 2565 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2566 | locations->SetOut(Location::RequiresRegister()); |
| 2567 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2568 | break; |
| 2569 | |
| 2570 | case Primitive::kPrimDouble: |
| 2571 | // Processing a Dex `double-to-int' instruction. |
| 2572 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2573 | locations->SetOut(Location::RequiresRegister()); |
| 2574 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2575 | break; |
| 2576 | |
| 2577 | default: |
| 2578 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2579 | << " to " << result_type; |
| 2580 | } |
| 2581 | break; |
| 2582 | |
| 2583 | case Primitive::kPrimLong: |
| 2584 | switch (input_type) { |
| 2585 | case Primitive::kPrimBoolean: |
| 2586 | // Boolean input is a result of code transformations. |
| 2587 | case Primitive::kPrimByte: |
| 2588 | case Primitive::kPrimShort: |
| 2589 | case Primitive::kPrimInt: |
| 2590 | case Primitive::kPrimChar: |
| 2591 | // Processing a Dex `int-to-long' instruction. |
| 2592 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2593 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2594 | break; |
| 2595 | |
| 2596 | case Primitive::kPrimFloat: { |
| 2597 | // Processing a Dex `float-to-long' instruction. |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2598 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 2599 | locations->SetInAt(0, LocationFrom(calling_convention.GetFpuRegisterAt(0))); |
| 2600 | locations->SetOut(LocationFrom(r0, r1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2601 | break; |
| 2602 | } |
| 2603 | |
| 2604 | case Primitive::kPrimDouble: { |
| 2605 | // Processing a Dex `double-to-long' instruction. |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2606 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 2607 | locations->SetInAt(0, LocationFrom(calling_convention.GetFpuRegisterAt(0), |
| 2608 | calling_convention.GetFpuRegisterAt(1))); |
| 2609 | locations->SetOut(LocationFrom(r0, r1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2610 | break; |
| 2611 | } |
| 2612 | |
| 2613 | default: |
| 2614 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2615 | << " to " << result_type; |
| 2616 | } |
| 2617 | break; |
| 2618 | |
| 2619 | case Primitive::kPrimChar: |
| 2620 | switch (input_type) { |
| 2621 | case Primitive::kPrimLong: |
| 2622 | // Type conversion from long to char is a result of code transformations. |
| 2623 | case Primitive::kPrimBoolean: |
| 2624 | // Boolean input is a result of code transformations. |
| 2625 | case Primitive::kPrimByte: |
| 2626 | case Primitive::kPrimShort: |
| 2627 | case Primitive::kPrimInt: |
| 2628 | // Processing a Dex `int-to-char' instruction. |
| 2629 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2630 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2631 | break; |
| 2632 | |
| 2633 | default: |
| 2634 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2635 | << " to " << result_type; |
| 2636 | } |
| 2637 | break; |
| 2638 | |
| 2639 | case Primitive::kPrimFloat: |
| 2640 | switch (input_type) { |
| 2641 | case Primitive::kPrimBoolean: |
| 2642 | // Boolean input is a result of code transformations. |
| 2643 | case Primitive::kPrimByte: |
| 2644 | case Primitive::kPrimShort: |
| 2645 | case Primitive::kPrimInt: |
| 2646 | case Primitive::kPrimChar: |
| 2647 | // Processing a Dex `int-to-float' instruction. |
| 2648 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2649 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2650 | break; |
| 2651 | |
| 2652 | case Primitive::kPrimLong: { |
| 2653 | // Processing a Dex `long-to-float' instruction. |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2654 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 2655 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0), |
| 2656 | calling_convention.GetRegisterAt(1))); |
| 2657 | locations->SetOut(LocationFrom(calling_convention.GetFpuRegisterAt(0))); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2658 | break; |
| 2659 | } |
| 2660 | |
| 2661 | case Primitive::kPrimDouble: |
| 2662 | // Processing a Dex `double-to-float' instruction. |
| 2663 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2664 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 2665 | break; |
| 2666 | |
| 2667 | default: |
| 2668 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2669 | << " to " << result_type; |
| 2670 | }; |
| 2671 | break; |
| 2672 | |
| 2673 | case Primitive::kPrimDouble: |
| 2674 | switch (input_type) { |
| 2675 | case Primitive::kPrimBoolean: |
| 2676 | // Boolean input is a result of code transformations. |
| 2677 | case Primitive::kPrimByte: |
| 2678 | case Primitive::kPrimShort: |
| 2679 | case Primitive::kPrimInt: |
| 2680 | case Primitive::kPrimChar: |
| 2681 | // Processing a Dex `int-to-double' instruction. |
| 2682 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2683 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2684 | break; |
| 2685 | |
| 2686 | case Primitive::kPrimLong: |
| 2687 | // Processing a Dex `long-to-double' instruction. |
| 2688 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2689 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2690 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2691 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2692 | break; |
| 2693 | |
| 2694 | case Primitive::kPrimFloat: |
| 2695 | // Processing a Dex `float-to-double' instruction. |
| 2696 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2697 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 2698 | break; |
| 2699 | |
| 2700 | default: |
| 2701 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2702 | << " to " << result_type; |
| 2703 | }; |
| 2704 | break; |
| 2705 | |
| 2706 | default: |
| 2707 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2708 | << " to " << result_type; |
| 2709 | } |
| 2710 | } |
| 2711 | |
| 2712 | void InstructionCodeGeneratorARMVIXL::VisitTypeConversion(HTypeConversion* conversion) { |
| 2713 | LocationSummary* locations = conversion->GetLocations(); |
| 2714 | Location out = locations->Out(); |
| 2715 | Location in = locations->InAt(0); |
| 2716 | Primitive::Type result_type = conversion->GetResultType(); |
| 2717 | Primitive::Type input_type = conversion->GetInputType(); |
| 2718 | DCHECK_NE(result_type, input_type); |
| 2719 | switch (result_type) { |
| 2720 | case Primitive::kPrimByte: |
| 2721 | switch (input_type) { |
| 2722 | case Primitive::kPrimLong: |
| 2723 | // Type conversion from long to byte is a result of code transformations. |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2724 | __ Sbfx(OutputRegister(conversion), LowRegisterFrom(in), 0, 8); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2725 | break; |
| 2726 | case Primitive::kPrimBoolean: |
| 2727 | // Boolean input is a result of code transformations. |
| 2728 | case Primitive::kPrimShort: |
| 2729 | case Primitive::kPrimInt: |
| 2730 | case Primitive::kPrimChar: |
| 2731 | // Processing a Dex `int-to-byte' instruction. |
| 2732 | __ Sbfx(OutputRegister(conversion), InputRegisterAt(conversion, 0), 0, 8); |
| 2733 | break; |
| 2734 | |
| 2735 | default: |
| 2736 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2737 | << " to " << result_type; |
| 2738 | } |
| 2739 | break; |
| 2740 | |
| 2741 | case Primitive::kPrimShort: |
| 2742 | switch (input_type) { |
| 2743 | case Primitive::kPrimLong: |
| 2744 | // Type conversion from long to short is a result of code transformations. |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2745 | __ Sbfx(OutputRegister(conversion), LowRegisterFrom(in), 0, 16); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2746 | break; |
| 2747 | case Primitive::kPrimBoolean: |
| 2748 | // Boolean input is a result of code transformations. |
| 2749 | case Primitive::kPrimByte: |
| 2750 | case Primitive::kPrimInt: |
| 2751 | case Primitive::kPrimChar: |
| 2752 | // Processing a Dex `int-to-short' instruction. |
| 2753 | __ Sbfx(OutputRegister(conversion), InputRegisterAt(conversion, 0), 0, 16); |
| 2754 | break; |
| 2755 | |
| 2756 | default: |
| 2757 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2758 | << " to " << result_type; |
| 2759 | } |
| 2760 | break; |
| 2761 | |
| 2762 | case Primitive::kPrimInt: |
| 2763 | switch (input_type) { |
| 2764 | case Primitive::kPrimLong: |
| 2765 | // Processing a Dex `long-to-int' instruction. |
| 2766 | DCHECK(out.IsRegister()); |
| 2767 | if (in.IsRegisterPair()) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2768 | __ Mov(OutputRegister(conversion), LowRegisterFrom(in)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2769 | } else if (in.IsDoubleStackSlot()) { |
| 2770 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 2771 | OutputRegister(conversion), |
| 2772 | sp, |
| 2773 | in.GetStackIndex()); |
| 2774 | } else { |
| 2775 | DCHECK(in.IsConstant()); |
| 2776 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2777 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2778 | __ Mov(OutputRegister(conversion), static_cast<int32_t>(value)); |
| 2779 | } |
| 2780 | break; |
| 2781 | |
| 2782 | case Primitive::kPrimFloat: { |
| 2783 | // Processing a Dex `float-to-int' instruction. |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2784 | vixl32::SRegister temp = LowSRegisterFrom(locations->GetTemp(0)); |
Scott Wakeling | fb0b7d4 | 2016-10-28 16:11:08 +0100 | [diff] [blame] | 2785 | __ Vcvt(S32, F32, temp, InputSRegisterAt(conversion, 0)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2786 | __ Vmov(OutputRegister(conversion), temp); |
| 2787 | break; |
| 2788 | } |
| 2789 | |
| 2790 | case Primitive::kPrimDouble: { |
| 2791 | // Processing a Dex `double-to-int' instruction. |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2792 | vixl32::SRegister temp_s = LowSRegisterFrom(locations->GetTemp(0)); |
Scott Wakeling | fb0b7d4 | 2016-10-28 16:11:08 +0100 | [diff] [blame] | 2793 | __ Vcvt(S32, F64, temp_s, DRegisterFrom(in)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2794 | __ Vmov(OutputRegister(conversion), temp_s); |
| 2795 | break; |
| 2796 | } |
| 2797 | |
| 2798 | default: |
| 2799 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2800 | << " to " << result_type; |
| 2801 | } |
| 2802 | break; |
| 2803 | |
| 2804 | case Primitive::kPrimLong: |
| 2805 | switch (input_type) { |
| 2806 | case Primitive::kPrimBoolean: |
| 2807 | // Boolean input is a result of code transformations. |
| 2808 | case Primitive::kPrimByte: |
| 2809 | case Primitive::kPrimShort: |
| 2810 | case Primitive::kPrimInt: |
| 2811 | case Primitive::kPrimChar: |
| 2812 | // Processing a Dex `int-to-long' instruction. |
| 2813 | DCHECK(out.IsRegisterPair()); |
| 2814 | DCHECK(in.IsRegister()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2815 | __ Mov(LowRegisterFrom(out), InputRegisterAt(conversion, 0)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2816 | // Sign extension. |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2817 | __ Asr(HighRegisterFrom(out), LowRegisterFrom(out), 31); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2818 | break; |
| 2819 | |
| 2820 | case Primitive::kPrimFloat: |
| 2821 | // Processing a Dex `float-to-long' instruction. |
| 2822 | codegen_->InvokeRuntime(kQuickF2l, conversion, conversion->GetDexPc()); |
| 2823 | CheckEntrypointTypes<kQuickF2l, int64_t, float>(); |
| 2824 | break; |
| 2825 | |
| 2826 | case Primitive::kPrimDouble: |
| 2827 | // Processing a Dex `double-to-long' instruction. |
| 2828 | codegen_->InvokeRuntime(kQuickD2l, conversion, conversion->GetDexPc()); |
| 2829 | CheckEntrypointTypes<kQuickD2l, int64_t, double>(); |
| 2830 | break; |
| 2831 | |
| 2832 | default: |
| 2833 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2834 | << " to " << result_type; |
| 2835 | } |
| 2836 | break; |
| 2837 | |
| 2838 | case Primitive::kPrimChar: |
| 2839 | switch (input_type) { |
| 2840 | case Primitive::kPrimLong: |
| 2841 | // Type conversion from long to char is a result of code transformations. |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2842 | __ Ubfx(OutputRegister(conversion), LowRegisterFrom(in), 0, 16); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2843 | break; |
| 2844 | case Primitive::kPrimBoolean: |
| 2845 | // Boolean input is a result of code transformations. |
| 2846 | case Primitive::kPrimByte: |
| 2847 | case Primitive::kPrimShort: |
| 2848 | case Primitive::kPrimInt: |
| 2849 | // Processing a Dex `int-to-char' instruction. |
| 2850 | __ Ubfx(OutputRegister(conversion), InputRegisterAt(conversion, 0), 0, 16); |
| 2851 | break; |
| 2852 | |
| 2853 | default: |
| 2854 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2855 | << " to " << result_type; |
| 2856 | } |
| 2857 | break; |
| 2858 | |
| 2859 | case Primitive::kPrimFloat: |
| 2860 | switch (input_type) { |
| 2861 | case Primitive::kPrimBoolean: |
| 2862 | // Boolean input is a result of code transformations. |
| 2863 | case Primitive::kPrimByte: |
| 2864 | case Primitive::kPrimShort: |
| 2865 | case Primitive::kPrimInt: |
| 2866 | case Primitive::kPrimChar: { |
| 2867 | // Processing a Dex `int-to-float' instruction. |
| 2868 | __ Vmov(OutputSRegister(conversion), InputRegisterAt(conversion, 0)); |
Scott Wakeling | fb0b7d4 | 2016-10-28 16:11:08 +0100 | [diff] [blame] | 2869 | __ Vcvt(F32, S32, OutputSRegister(conversion), OutputSRegister(conversion)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2870 | break; |
| 2871 | } |
| 2872 | |
| 2873 | case Primitive::kPrimLong: |
| 2874 | // Processing a Dex `long-to-float' instruction. |
| 2875 | codegen_->InvokeRuntime(kQuickL2f, conversion, conversion->GetDexPc()); |
| 2876 | CheckEntrypointTypes<kQuickL2f, float, int64_t>(); |
| 2877 | break; |
| 2878 | |
| 2879 | case Primitive::kPrimDouble: |
| 2880 | // Processing a Dex `double-to-float' instruction. |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 2881 | __ Vcvt(F32, F64, OutputSRegister(conversion), DRegisterFrom(in)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2882 | break; |
| 2883 | |
| 2884 | default: |
| 2885 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2886 | << " to " << result_type; |
| 2887 | }; |
| 2888 | break; |
| 2889 | |
| 2890 | case Primitive::kPrimDouble: |
| 2891 | switch (input_type) { |
| 2892 | case Primitive::kPrimBoolean: |
| 2893 | // Boolean input is a result of code transformations. |
| 2894 | case Primitive::kPrimByte: |
| 2895 | case Primitive::kPrimShort: |
| 2896 | case Primitive::kPrimInt: |
| 2897 | case Primitive::kPrimChar: { |
| 2898 | // Processing a Dex `int-to-double' instruction. |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2899 | __ Vmov(LowSRegisterFrom(out), InputRegisterAt(conversion, 0)); |
Scott Wakeling | fb0b7d4 | 2016-10-28 16:11:08 +0100 | [diff] [blame] | 2900 | __ Vcvt(F64, S32, DRegisterFrom(out), LowSRegisterFrom(out)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2901 | break; |
| 2902 | } |
| 2903 | |
| 2904 | case Primitive::kPrimLong: { |
| 2905 | // Processing a Dex `long-to-double' instruction. |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2906 | vixl32::Register low = LowRegisterFrom(in); |
| 2907 | vixl32::Register high = HighRegisterFrom(in); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2908 | vixl32::SRegister out_s = LowSRegisterFrom(out); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 2909 | vixl32::DRegister out_d = DRegisterFrom(out); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2910 | vixl32::SRegister temp_s = LowSRegisterFrom(locations->GetTemp(0)); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 2911 | vixl32::DRegister temp_d = DRegisterFrom(locations->GetTemp(0)); |
Scott Wakeling | fb0b7d4 | 2016-10-28 16:11:08 +0100 | [diff] [blame] | 2912 | vixl32::DRegister constant_d = DRegisterFrom(locations->GetTemp(1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2913 | |
| 2914 | // temp_d = int-to-double(high) |
| 2915 | __ Vmov(temp_s, high); |
Scott Wakeling | fb0b7d4 | 2016-10-28 16:11:08 +0100 | [diff] [blame] | 2916 | __ Vcvt(F64, S32, temp_d, temp_s); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2917 | // constant_d = k2Pow32EncodingForDouble |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2918 | __ Vmov(constant_d, bit_cast<double, int64_t>(k2Pow32EncodingForDouble)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2919 | // out_d = unsigned-to-double(low) |
| 2920 | __ Vmov(out_s, low); |
| 2921 | __ Vcvt(F64, U32, out_d, out_s); |
| 2922 | // out_d += temp_d * constant_d |
| 2923 | __ Vmla(F64, out_d, temp_d, constant_d); |
| 2924 | break; |
| 2925 | } |
| 2926 | |
| 2927 | case Primitive::kPrimFloat: |
| 2928 | // Processing a Dex `float-to-double' instruction. |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 2929 | __ Vcvt(F64, F32, DRegisterFrom(out), InputSRegisterAt(conversion, 0)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2930 | break; |
| 2931 | |
| 2932 | default: |
| 2933 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2934 | << " to " << result_type; |
| 2935 | }; |
| 2936 | break; |
| 2937 | |
| 2938 | default: |
| 2939 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2940 | << " to " << result_type; |
| 2941 | } |
| 2942 | } |
| 2943 | |
| 2944 | void LocationsBuilderARMVIXL::VisitAdd(HAdd* add) { |
| 2945 | LocationSummary* locations = |
| 2946 | new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall); |
| 2947 | switch (add->GetResultType()) { |
| 2948 | case Primitive::kPrimInt: { |
| 2949 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2950 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
| 2951 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2952 | break; |
| 2953 | } |
| 2954 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2955 | case Primitive::kPrimLong: { |
| 2956 | locations->SetInAt(0, Location::RequiresRegister()); |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 2957 | locations->SetInAt(1, ArmEncodableConstantOrRegister(add->InputAt(1), ADD)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2958 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2959 | break; |
| 2960 | } |
| 2961 | |
| 2962 | case Primitive::kPrimFloat: |
| 2963 | case Primitive::kPrimDouble: { |
| 2964 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2965 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2966 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 2967 | break; |
| 2968 | } |
| 2969 | |
| 2970 | default: |
| 2971 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
| 2972 | } |
| 2973 | } |
| 2974 | |
| 2975 | void InstructionCodeGeneratorARMVIXL::VisitAdd(HAdd* add) { |
| 2976 | LocationSummary* locations = add->GetLocations(); |
| 2977 | Location out = locations->Out(); |
| 2978 | Location first = locations->InAt(0); |
| 2979 | Location second = locations->InAt(1); |
| 2980 | |
| 2981 | switch (add->GetResultType()) { |
| 2982 | case Primitive::kPrimInt: { |
| 2983 | __ Add(OutputRegister(add), InputRegisterAt(add, 0), InputOperandAt(add, 1)); |
| 2984 | } |
| 2985 | break; |
| 2986 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2987 | case Primitive::kPrimLong: { |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 2988 | if (second.IsConstant()) { |
| 2989 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant())); |
| 2990 | GenerateAddLongConst(out, first, value); |
| 2991 | } else { |
| 2992 | DCHECK(second.IsRegisterPair()); |
| 2993 | __ Adds(LowRegisterFrom(out), LowRegisterFrom(first), LowRegisterFrom(second)); |
| 2994 | __ Adc(HighRegisterFrom(out), HighRegisterFrom(first), HighRegisterFrom(second)); |
| 2995 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2996 | break; |
| 2997 | } |
| 2998 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2999 | case Primitive::kPrimFloat: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3000 | case Primitive::kPrimDouble: |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3001 | __ Vadd(OutputVRegister(add), InputVRegisterAt(add, 0), InputVRegisterAt(add, 1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3002 | break; |
| 3003 | |
| 3004 | default: |
| 3005 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
| 3006 | } |
| 3007 | } |
| 3008 | |
| 3009 | void LocationsBuilderARMVIXL::VisitSub(HSub* sub) { |
| 3010 | LocationSummary* locations = |
| 3011 | new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); |
| 3012 | switch (sub->GetResultType()) { |
| 3013 | case Primitive::kPrimInt: { |
| 3014 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3015 | locations->SetInAt(1, Location::RegisterOrConstant(sub->InputAt(1))); |
| 3016 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3017 | break; |
| 3018 | } |
| 3019 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3020 | case Primitive::kPrimLong: { |
| 3021 | locations->SetInAt(0, Location::RequiresRegister()); |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 3022 | locations->SetInAt(1, ArmEncodableConstantOrRegister(sub->InputAt(1), SUB)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3023 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3024 | break; |
| 3025 | } |
| 3026 | case Primitive::kPrimFloat: |
| 3027 | case Primitive::kPrimDouble: { |
| 3028 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3029 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3030 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3031 | break; |
| 3032 | } |
| 3033 | default: |
| 3034 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
| 3035 | } |
| 3036 | } |
| 3037 | |
| 3038 | void InstructionCodeGeneratorARMVIXL::VisitSub(HSub* sub) { |
| 3039 | LocationSummary* locations = sub->GetLocations(); |
| 3040 | Location out = locations->Out(); |
| 3041 | Location first = locations->InAt(0); |
| 3042 | Location second = locations->InAt(1); |
| 3043 | switch (sub->GetResultType()) { |
| 3044 | case Primitive::kPrimInt: { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3045 | __ Sub(OutputRegister(sub), InputRegisterAt(sub, 0), InputOperandAt(sub, 1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3046 | break; |
| 3047 | } |
| 3048 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3049 | case Primitive::kPrimLong: { |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 3050 | if (second.IsConstant()) { |
| 3051 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant())); |
| 3052 | GenerateAddLongConst(out, first, -value); |
| 3053 | } else { |
| 3054 | DCHECK(second.IsRegisterPair()); |
| 3055 | __ Subs(LowRegisterFrom(out), LowRegisterFrom(first), LowRegisterFrom(second)); |
| 3056 | __ Sbc(HighRegisterFrom(out), HighRegisterFrom(first), HighRegisterFrom(second)); |
| 3057 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3058 | break; |
| 3059 | } |
| 3060 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3061 | case Primitive::kPrimFloat: |
| 3062 | case Primitive::kPrimDouble: |
| 3063 | __ Vsub(OutputVRegister(sub), InputVRegisterAt(sub, 0), InputVRegisterAt(sub, 1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3064 | break; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3065 | |
| 3066 | default: |
| 3067 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
| 3068 | } |
| 3069 | } |
| 3070 | |
| 3071 | void LocationsBuilderARMVIXL::VisitMul(HMul* mul) { |
| 3072 | LocationSummary* locations = |
| 3073 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 3074 | switch (mul->GetResultType()) { |
| 3075 | case Primitive::kPrimInt: |
| 3076 | case Primitive::kPrimLong: { |
| 3077 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3078 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3079 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3080 | break; |
| 3081 | } |
| 3082 | |
| 3083 | case Primitive::kPrimFloat: |
| 3084 | case Primitive::kPrimDouble: { |
| 3085 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3086 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3087 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3088 | break; |
| 3089 | } |
| 3090 | |
| 3091 | default: |
| 3092 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 3093 | } |
| 3094 | } |
| 3095 | |
| 3096 | void InstructionCodeGeneratorARMVIXL::VisitMul(HMul* mul) { |
| 3097 | LocationSummary* locations = mul->GetLocations(); |
| 3098 | Location out = locations->Out(); |
| 3099 | Location first = locations->InAt(0); |
| 3100 | Location second = locations->InAt(1); |
| 3101 | switch (mul->GetResultType()) { |
| 3102 | case Primitive::kPrimInt: { |
| 3103 | __ Mul(OutputRegister(mul), InputRegisterAt(mul, 0), InputRegisterAt(mul, 1)); |
| 3104 | break; |
| 3105 | } |
| 3106 | case Primitive::kPrimLong: { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3107 | vixl32::Register out_hi = HighRegisterFrom(out); |
| 3108 | vixl32::Register out_lo = LowRegisterFrom(out); |
| 3109 | vixl32::Register in1_hi = HighRegisterFrom(first); |
| 3110 | vixl32::Register in1_lo = LowRegisterFrom(first); |
| 3111 | vixl32::Register in2_hi = HighRegisterFrom(second); |
| 3112 | vixl32::Register in2_lo = LowRegisterFrom(second); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3113 | |
| 3114 | // Extra checks to protect caused by the existence of R1_R2. |
| 3115 | // The algorithm is wrong if out.hi is either in1.lo or in2.lo: |
| 3116 | // (e.g. in1=r0_r1, in2=r2_r3 and out=r1_r2); |
| 3117 | DCHECK_NE(out_hi.GetCode(), in1_lo.GetCode()); |
| 3118 | DCHECK_NE(out_hi.GetCode(), in2_lo.GetCode()); |
| 3119 | |
| 3120 | // input: in1 - 64 bits, in2 - 64 bits |
| 3121 | // output: out |
| 3122 | // formula: out.hi : out.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo |
| 3123 | // parts: out.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32] |
| 3124 | // parts: out.lo = (in1.lo * in2.lo)[31:0] |
| 3125 | |
| 3126 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 3127 | vixl32::Register temp = temps.Acquire(); |
| 3128 | // temp <- in1.lo * in2.hi |
| 3129 | __ Mul(temp, in1_lo, in2_hi); |
| 3130 | // out.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3131 | __ Mla(out_hi, in1_hi, in2_lo, temp); |
| 3132 | // out.lo <- (in1.lo * in2.lo)[31:0]; |
| 3133 | __ Umull(out_lo, temp, in1_lo, in2_lo); |
| 3134 | // 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] | 3135 | __ Add(out_hi, out_hi, temp); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3136 | break; |
| 3137 | } |
| 3138 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3139 | case Primitive::kPrimFloat: |
| 3140 | case Primitive::kPrimDouble: |
| 3141 | __ Vmul(OutputVRegister(mul), InputVRegisterAt(mul, 0), InputVRegisterAt(mul, 1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3142 | break; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3143 | |
| 3144 | default: |
| 3145 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 3146 | } |
| 3147 | } |
| 3148 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3149 | void InstructionCodeGeneratorARMVIXL::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 3150 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3151 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 3152 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3153 | Location second = instruction->GetLocations()->InAt(1); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3154 | DCHECK(second.IsConstant()); |
| 3155 | |
| 3156 | vixl32::Register out = OutputRegister(instruction); |
| 3157 | vixl32::Register dividend = InputRegisterAt(instruction, 0); |
| 3158 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 3159 | DCHECK(imm == 1 || imm == -1); |
| 3160 | |
| 3161 | if (instruction->IsRem()) { |
| 3162 | __ Mov(out, 0); |
| 3163 | } else { |
| 3164 | if (imm == 1) { |
| 3165 | __ Mov(out, dividend); |
| 3166 | } else { |
| 3167 | __ Rsb(out, dividend, 0); |
| 3168 | } |
| 3169 | } |
| 3170 | } |
| 3171 | |
| 3172 | void InstructionCodeGeneratorARMVIXL::DivRemByPowerOfTwo(HBinaryOperation* instruction) { |
| 3173 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3174 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 3175 | |
| 3176 | LocationSummary* locations = instruction->GetLocations(); |
| 3177 | Location second = locations->InAt(1); |
| 3178 | DCHECK(second.IsConstant()); |
| 3179 | |
| 3180 | vixl32::Register out = OutputRegister(instruction); |
| 3181 | vixl32::Register dividend = InputRegisterAt(instruction, 0); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3182 | vixl32::Register temp = RegisterFrom(locations->GetTemp(0)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3183 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 3184 | uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm)); |
| 3185 | int ctz_imm = CTZ(abs_imm); |
| 3186 | |
| 3187 | if (ctz_imm == 1) { |
| 3188 | __ Lsr(temp, dividend, 32 - ctz_imm); |
| 3189 | } else { |
| 3190 | __ Asr(temp, dividend, 31); |
| 3191 | __ Lsr(temp, temp, 32 - ctz_imm); |
| 3192 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3193 | __ Add(out, temp, dividend); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3194 | |
| 3195 | if (instruction->IsDiv()) { |
| 3196 | __ Asr(out, out, ctz_imm); |
| 3197 | if (imm < 0) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3198 | __ Rsb(out, out, 0); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3199 | } |
| 3200 | } else { |
| 3201 | __ Ubfx(out, out, 0, ctz_imm); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3202 | __ Sub(out, out, temp); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3203 | } |
| 3204 | } |
| 3205 | |
| 3206 | void InstructionCodeGeneratorARMVIXL::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 3207 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3208 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 3209 | |
| 3210 | LocationSummary* locations = instruction->GetLocations(); |
| 3211 | Location second = locations->InAt(1); |
| 3212 | DCHECK(second.IsConstant()); |
| 3213 | |
| 3214 | vixl32::Register out = OutputRegister(instruction); |
| 3215 | vixl32::Register dividend = InputRegisterAt(instruction, 0); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3216 | vixl32::Register temp1 = RegisterFrom(locations->GetTemp(0)); |
| 3217 | vixl32::Register temp2 = RegisterFrom(locations->GetTemp(1)); |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 3218 | int32_t imm = Int32ConstantFrom(second); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3219 | |
| 3220 | int64_t magic; |
| 3221 | int shift; |
| 3222 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 3223 | |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 3224 | // TODO(VIXL): Change the static cast to Operand::From() after VIXL is fixed. |
| 3225 | __ Mov(temp1, static_cast<int32_t>(magic)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3226 | __ Smull(temp2, temp1, dividend, temp1); |
| 3227 | |
| 3228 | if (imm > 0 && magic < 0) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3229 | __ Add(temp1, temp1, dividend); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3230 | } else if (imm < 0 && magic > 0) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3231 | __ Sub(temp1, temp1, dividend); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3232 | } |
| 3233 | |
| 3234 | if (shift != 0) { |
| 3235 | __ Asr(temp1, temp1, shift); |
| 3236 | } |
| 3237 | |
| 3238 | if (instruction->IsDiv()) { |
| 3239 | __ Sub(out, temp1, Operand(temp1, vixl32::Shift(ASR), 31)); |
| 3240 | } else { |
| 3241 | __ Sub(temp1, temp1, Operand(temp1, vixl32::Shift(ASR), 31)); |
| 3242 | // TODO: Strength reduction for mls. |
| 3243 | __ Mov(temp2, imm); |
| 3244 | __ Mls(out, temp1, temp2, dividend); |
| 3245 | } |
| 3246 | } |
| 3247 | |
| 3248 | void InstructionCodeGeneratorARMVIXL::GenerateDivRemConstantIntegral( |
| 3249 | HBinaryOperation* instruction) { |
| 3250 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3251 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 3252 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3253 | Location second = instruction->GetLocations()->InAt(1); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3254 | DCHECK(second.IsConstant()); |
| 3255 | |
| 3256 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 3257 | if (imm == 0) { |
| 3258 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 3259 | } else if (imm == 1 || imm == -1) { |
| 3260 | DivRemOneOrMinusOne(instruction); |
| 3261 | } else if (IsPowerOfTwo(AbsOrMin(imm))) { |
| 3262 | DivRemByPowerOfTwo(instruction); |
| 3263 | } else { |
| 3264 | DCHECK(imm <= -2 || imm >= 2); |
| 3265 | GenerateDivRemWithAnyConstant(instruction); |
| 3266 | } |
| 3267 | } |
| 3268 | |
| 3269 | void LocationsBuilderARMVIXL::VisitDiv(HDiv* div) { |
| 3270 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 3271 | if (div->GetResultType() == Primitive::kPrimLong) { |
| 3272 | // pLdiv runtime call. |
| 3273 | call_kind = LocationSummary::kCallOnMainOnly; |
| 3274 | } else if (div->GetResultType() == Primitive::kPrimInt && div->InputAt(1)->IsConstant()) { |
| 3275 | // sdiv will be replaced by other instruction sequence. |
| 3276 | } else if (div->GetResultType() == Primitive::kPrimInt && |
| 3277 | !codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 3278 | // pIdivmod runtime call. |
| 3279 | call_kind = LocationSummary::kCallOnMainOnly; |
| 3280 | } |
| 3281 | |
| 3282 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind); |
| 3283 | |
| 3284 | switch (div->GetResultType()) { |
| 3285 | case Primitive::kPrimInt: { |
| 3286 | if (div->InputAt(1)->IsConstant()) { |
| 3287 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3288 | locations->SetInAt(1, Location::ConstantLocation(div->InputAt(1)->AsConstant())); |
| 3289 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3290 | int32_t value = div->InputAt(1)->AsIntConstant()->GetValue(); |
| 3291 | if (value == 1 || value == 0 || value == -1) { |
| 3292 | // No temp register required. |
| 3293 | } else { |
| 3294 | locations->AddTemp(Location::RequiresRegister()); |
| 3295 | if (!IsPowerOfTwo(AbsOrMin(value))) { |
| 3296 | locations->AddTemp(Location::RequiresRegister()); |
| 3297 | } |
| 3298 | } |
| 3299 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 3300 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3301 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3302 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3303 | } else { |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 3304 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 3305 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 3306 | locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(1))); |
| 3307 | // Note: divrem will compute both the quotient and the remainder as the pair R0 and R1, but |
| 3308 | // we only need the former. |
| 3309 | locations->SetOut(LocationFrom(r0)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3310 | } |
| 3311 | break; |
| 3312 | } |
| 3313 | case Primitive::kPrimLong: { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 3314 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 3315 | locations->SetInAt(0, LocationFrom( |
| 3316 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3317 | locations->SetInAt(1, LocationFrom( |
| 3318 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 3319 | locations->SetOut(LocationFrom(r0, r1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3320 | break; |
| 3321 | } |
| 3322 | case Primitive::kPrimFloat: |
| 3323 | case Primitive::kPrimDouble: { |
| 3324 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3325 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3326 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3327 | break; |
| 3328 | } |
| 3329 | |
| 3330 | default: |
| 3331 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3332 | } |
| 3333 | } |
| 3334 | |
| 3335 | void InstructionCodeGeneratorARMVIXL::VisitDiv(HDiv* div) { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 3336 | Location lhs = div->GetLocations()->InAt(0); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3337 | Location rhs = div->GetLocations()->InAt(1); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3338 | |
| 3339 | switch (div->GetResultType()) { |
| 3340 | case Primitive::kPrimInt: { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3341 | if (rhs.IsConstant()) { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3342 | GenerateDivRemConstantIntegral(div); |
| 3343 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 3344 | __ Sdiv(OutputRegister(div), InputRegisterAt(div, 0), InputRegisterAt(div, 1)); |
| 3345 | } else { |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 3346 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 3347 | DCHECK(calling_convention.GetRegisterAt(0).Is(RegisterFrom(lhs))); |
| 3348 | DCHECK(calling_convention.GetRegisterAt(1).Is(RegisterFrom(rhs))); |
| 3349 | DCHECK(r0.Is(OutputRegister(div))); |
| 3350 | |
| 3351 | codegen_->InvokeRuntime(kQuickIdivmod, div, div->GetDexPc()); |
| 3352 | CheckEntrypointTypes<kQuickIdivmod, int32_t, int32_t, int32_t>(); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3353 | } |
| 3354 | break; |
| 3355 | } |
| 3356 | |
| 3357 | case Primitive::kPrimLong: { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 3358 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 3359 | DCHECK(calling_convention.GetRegisterAt(0).Is(LowRegisterFrom(lhs))); |
| 3360 | DCHECK(calling_convention.GetRegisterAt(1).Is(HighRegisterFrom(lhs))); |
| 3361 | DCHECK(calling_convention.GetRegisterAt(2).Is(LowRegisterFrom(rhs))); |
| 3362 | DCHECK(calling_convention.GetRegisterAt(3).Is(HighRegisterFrom(rhs))); |
| 3363 | DCHECK(LowRegisterFrom(div->GetLocations()->Out()).Is(r0)); |
| 3364 | DCHECK(HighRegisterFrom(div->GetLocations()->Out()).Is(r1)); |
| 3365 | |
| 3366 | codegen_->InvokeRuntime(kQuickLdiv, div, div->GetDexPc()); |
| 3367 | CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>(); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3368 | break; |
| 3369 | } |
| 3370 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3371 | case Primitive::kPrimFloat: |
| 3372 | case Primitive::kPrimDouble: |
| 3373 | __ Vdiv(OutputVRegister(div), InputVRegisterAt(div, 0), InputVRegisterAt(div, 1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3374 | break; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3375 | |
| 3376 | default: |
| 3377 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3378 | } |
| 3379 | } |
| 3380 | |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 3381 | void LocationsBuilderARMVIXL::VisitRem(HRem* rem) { |
| 3382 | Primitive::Type type = rem->GetResultType(); |
| 3383 | |
| 3384 | // Most remainders are implemented in the runtime. |
| 3385 | LocationSummary::CallKind call_kind = LocationSummary::kCallOnMainOnly; |
| 3386 | if (rem->GetResultType() == Primitive::kPrimInt && rem->InputAt(1)->IsConstant()) { |
| 3387 | // sdiv will be replaced by other instruction sequence. |
| 3388 | call_kind = LocationSummary::kNoCall; |
| 3389 | } else if ((rem->GetResultType() == Primitive::kPrimInt) |
| 3390 | && codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 3391 | // Have hardware divide instruction for int, do it with three instructions. |
| 3392 | call_kind = LocationSummary::kNoCall; |
| 3393 | } |
| 3394 | |
| 3395 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind); |
| 3396 | |
| 3397 | switch (type) { |
| 3398 | case Primitive::kPrimInt: { |
| 3399 | if (rem->InputAt(1)->IsConstant()) { |
| 3400 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3401 | locations->SetInAt(1, Location::ConstantLocation(rem->InputAt(1)->AsConstant())); |
| 3402 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3403 | int32_t value = rem->InputAt(1)->AsIntConstant()->GetValue(); |
| 3404 | if (value == 1 || value == 0 || value == -1) { |
| 3405 | // No temp register required. |
| 3406 | } else { |
| 3407 | locations->AddTemp(Location::RequiresRegister()); |
| 3408 | if (!IsPowerOfTwo(AbsOrMin(value))) { |
| 3409 | locations->AddTemp(Location::RequiresRegister()); |
| 3410 | } |
| 3411 | } |
| 3412 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 3413 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3414 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3415 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3416 | locations->AddTemp(Location::RequiresRegister()); |
| 3417 | } else { |
| 3418 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 3419 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 3420 | locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(1))); |
| 3421 | // Note: divrem will compute both the quotient and the remainder as the pair R0 and R1, but |
| 3422 | // we only need the latter. |
| 3423 | locations->SetOut(LocationFrom(r1)); |
| 3424 | } |
| 3425 | break; |
| 3426 | } |
| 3427 | case Primitive::kPrimLong: { |
| 3428 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 3429 | locations->SetInAt(0, LocationFrom( |
| 3430 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3431 | locations->SetInAt(1, LocationFrom( |
| 3432 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 3433 | // The runtime helper puts the output in R2,R3. |
| 3434 | locations->SetOut(LocationFrom(r2, r3)); |
| 3435 | break; |
| 3436 | } |
| 3437 | case Primitive::kPrimFloat: { |
| 3438 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 3439 | locations->SetInAt(0, LocationFrom(calling_convention.GetFpuRegisterAt(0))); |
| 3440 | locations->SetInAt(1, LocationFrom(calling_convention.GetFpuRegisterAt(1))); |
| 3441 | locations->SetOut(LocationFrom(s0)); |
| 3442 | break; |
| 3443 | } |
| 3444 | |
| 3445 | case Primitive::kPrimDouble: { |
| 3446 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 3447 | locations->SetInAt(0, LocationFrom( |
| 3448 | calling_convention.GetFpuRegisterAt(0), calling_convention.GetFpuRegisterAt(1))); |
| 3449 | locations->SetInAt(1, LocationFrom( |
| 3450 | calling_convention.GetFpuRegisterAt(2), calling_convention.GetFpuRegisterAt(3))); |
| 3451 | locations->SetOut(LocationFrom(s0, s1)); |
| 3452 | break; |
| 3453 | } |
| 3454 | |
| 3455 | default: |
| 3456 | LOG(FATAL) << "Unexpected rem type " << type; |
| 3457 | } |
| 3458 | } |
| 3459 | |
| 3460 | void InstructionCodeGeneratorARMVIXL::VisitRem(HRem* rem) { |
| 3461 | LocationSummary* locations = rem->GetLocations(); |
| 3462 | Location second = locations->InAt(1); |
| 3463 | |
| 3464 | Primitive::Type type = rem->GetResultType(); |
| 3465 | switch (type) { |
| 3466 | case Primitive::kPrimInt: { |
| 3467 | vixl32::Register reg1 = InputRegisterAt(rem, 0); |
| 3468 | vixl32::Register out_reg = OutputRegister(rem); |
| 3469 | if (second.IsConstant()) { |
| 3470 | GenerateDivRemConstantIntegral(rem); |
| 3471 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 3472 | vixl32::Register reg2 = RegisterFrom(second); |
| 3473 | vixl32::Register temp = RegisterFrom(locations->GetTemp(0)); |
| 3474 | |
| 3475 | // temp = reg1 / reg2 (integer division) |
| 3476 | // dest = reg1 - temp * reg2 |
| 3477 | __ Sdiv(temp, reg1, reg2); |
| 3478 | __ Mls(out_reg, temp, reg2, reg1); |
| 3479 | } else { |
| 3480 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 3481 | DCHECK(reg1.Is(calling_convention.GetRegisterAt(0))); |
| 3482 | DCHECK(RegisterFrom(second).Is(calling_convention.GetRegisterAt(1))); |
| 3483 | DCHECK(out_reg.Is(r1)); |
| 3484 | |
| 3485 | codegen_->InvokeRuntime(kQuickIdivmod, rem, rem->GetDexPc()); |
| 3486 | CheckEntrypointTypes<kQuickIdivmod, int32_t, int32_t, int32_t>(); |
| 3487 | } |
| 3488 | break; |
| 3489 | } |
| 3490 | |
| 3491 | case Primitive::kPrimLong: { |
| 3492 | codegen_->InvokeRuntime(kQuickLmod, rem, rem->GetDexPc()); |
| 3493 | CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>(); |
| 3494 | break; |
| 3495 | } |
| 3496 | |
| 3497 | case Primitive::kPrimFloat: { |
| 3498 | codegen_->InvokeRuntime(kQuickFmodf, rem, rem->GetDexPc()); |
| 3499 | CheckEntrypointTypes<kQuickFmodf, float, float, float>(); |
| 3500 | break; |
| 3501 | } |
| 3502 | |
| 3503 | case Primitive::kPrimDouble: { |
| 3504 | codegen_->InvokeRuntime(kQuickFmod, rem, rem->GetDexPc()); |
| 3505 | CheckEntrypointTypes<kQuickFmod, double, double, double>(); |
| 3506 | break; |
| 3507 | } |
| 3508 | |
| 3509 | default: |
| 3510 | LOG(FATAL) << "Unexpected rem type " << type; |
| 3511 | } |
| 3512 | } |
| 3513 | |
| 3514 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3515 | void LocationsBuilderARMVIXL::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 3516 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3517 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3518 | } |
| 3519 | |
| 3520 | void InstructionCodeGeneratorARMVIXL::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 3521 | DivZeroCheckSlowPathARMVIXL* slow_path = |
| 3522 | new (GetGraph()->GetArena()) DivZeroCheckSlowPathARMVIXL(instruction); |
| 3523 | codegen_->AddSlowPath(slow_path); |
| 3524 | |
| 3525 | LocationSummary* locations = instruction->GetLocations(); |
| 3526 | Location value = locations->InAt(0); |
| 3527 | |
| 3528 | switch (instruction->GetType()) { |
| 3529 | case Primitive::kPrimBoolean: |
| 3530 | case Primitive::kPrimByte: |
| 3531 | case Primitive::kPrimChar: |
| 3532 | case Primitive::kPrimShort: |
| 3533 | case Primitive::kPrimInt: { |
| 3534 | if (value.IsRegister()) { |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 3535 | __ CompareAndBranchIfZero(InputRegisterAt(instruction, 0), slow_path->GetEntryLabel()); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3536 | } else { |
| 3537 | DCHECK(value.IsConstant()) << value; |
| 3538 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
| 3539 | __ B(slow_path->GetEntryLabel()); |
| 3540 | } |
| 3541 | } |
| 3542 | break; |
| 3543 | } |
| 3544 | case Primitive::kPrimLong: { |
| 3545 | if (value.IsRegisterPair()) { |
| 3546 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 3547 | vixl32::Register temp = temps.Acquire(); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3548 | __ Orrs(temp, LowRegisterFrom(value), HighRegisterFrom(value)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3549 | __ B(eq, slow_path->GetEntryLabel()); |
| 3550 | } else { |
| 3551 | DCHECK(value.IsConstant()) << value; |
| 3552 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 3553 | __ B(slow_path->GetEntryLabel()); |
| 3554 | } |
| 3555 | } |
| 3556 | break; |
| 3557 | } |
| 3558 | default: |
| 3559 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
| 3560 | } |
| 3561 | } |
| 3562 | |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 3563 | void InstructionCodeGeneratorARMVIXL::HandleIntegerRotate(HRor* ror) { |
| 3564 | LocationSummary* locations = ror->GetLocations(); |
| 3565 | vixl32::Register in = InputRegisterAt(ror, 0); |
| 3566 | Location rhs = locations->InAt(1); |
| 3567 | vixl32::Register out = OutputRegister(ror); |
| 3568 | |
| 3569 | if (rhs.IsConstant()) { |
| 3570 | // Arm32 and Thumb2 assemblers require a rotation on the interval [1,31], |
| 3571 | // so map all rotations to a +ve. equivalent in that range. |
| 3572 | // (e.g. left *or* right by -2 bits == 30 bits in the same direction.) |
| 3573 | uint32_t rot = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()) & 0x1F; |
| 3574 | if (rot) { |
| 3575 | // Rotate, mapping left rotations to right equivalents if necessary. |
| 3576 | // (e.g. left by 2 bits == right by 30.) |
| 3577 | __ Ror(out, in, rot); |
| 3578 | } else if (!out.Is(in)) { |
| 3579 | __ Mov(out, in); |
| 3580 | } |
| 3581 | } else { |
| 3582 | __ Ror(out, in, RegisterFrom(rhs)); |
| 3583 | } |
| 3584 | } |
| 3585 | |
| 3586 | // Gain some speed by mapping all Long rotates onto equivalent pairs of Integer |
| 3587 | // rotates by swapping input regs (effectively rotating by the first 32-bits of |
| 3588 | // a larger rotation) or flipping direction (thus treating larger right/left |
| 3589 | // rotations as sub-word sized rotations in the other direction) as appropriate. |
| 3590 | void InstructionCodeGeneratorARMVIXL::HandleLongRotate(HRor* ror) { |
| 3591 | LocationSummary* locations = ror->GetLocations(); |
| 3592 | vixl32::Register in_reg_lo = LowRegisterFrom(locations->InAt(0)); |
| 3593 | vixl32::Register in_reg_hi = HighRegisterFrom(locations->InAt(0)); |
| 3594 | Location rhs = locations->InAt(1); |
| 3595 | vixl32::Register out_reg_lo = LowRegisterFrom(locations->Out()); |
| 3596 | vixl32::Register out_reg_hi = HighRegisterFrom(locations->Out()); |
| 3597 | |
| 3598 | if (rhs.IsConstant()) { |
| 3599 | uint64_t rot = CodeGenerator::GetInt64ValueOf(rhs.GetConstant()); |
| 3600 | // Map all rotations to +ve. equivalents on the interval [0,63]. |
| 3601 | rot &= kMaxLongShiftDistance; |
| 3602 | // For rotates over a word in size, 'pre-rotate' by 32-bits to keep rotate |
| 3603 | // logic below to a simple pair of binary orr. |
| 3604 | // (e.g. 34 bits == in_reg swap + 2 bits right.) |
| 3605 | if (rot >= kArmBitsPerWord) { |
| 3606 | rot -= kArmBitsPerWord; |
| 3607 | std::swap(in_reg_hi, in_reg_lo); |
| 3608 | } |
| 3609 | // Rotate, or mov to out for zero or word size rotations. |
| 3610 | if (rot != 0u) { |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 3611 | __ Lsr(out_reg_hi, in_reg_hi, Operand::From(rot)); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 3612 | __ 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] | 3613 | __ Lsr(out_reg_lo, in_reg_lo, Operand::From(rot)); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 3614 | __ Orr(out_reg_lo, out_reg_lo, Operand(in_reg_hi, ShiftType::LSL, kArmBitsPerWord - rot)); |
| 3615 | } else { |
| 3616 | __ Mov(out_reg_lo, in_reg_lo); |
| 3617 | __ Mov(out_reg_hi, in_reg_hi); |
| 3618 | } |
| 3619 | } else { |
| 3620 | vixl32::Register shift_right = RegisterFrom(locations->GetTemp(0)); |
| 3621 | vixl32::Register shift_left = RegisterFrom(locations->GetTemp(1)); |
| 3622 | vixl32::Label end; |
| 3623 | vixl32::Label shift_by_32_plus_shift_right; |
| 3624 | |
| 3625 | __ And(shift_right, RegisterFrom(rhs), 0x1F); |
| 3626 | __ Lsrs(shift_left, RegisterFrom(rhs), 6); |
Scott Wakeling | bffdc70 | 2016-12-07 17:46:03 +0000 | [diff] [blame] | 3627 | __ Rsb(LeaveFlags, shift_left, shift_right, Operand::From(kArmBitsPerWord)); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 3628 | __ B(cc, &shift_by_32_plus_shift_right); |
| 3629 | |
| 3630 | // out_reg_hi = (reg_hi << shift_left) | (reg_lo >> shift_right). |
| 3631 | // out_reg_lo = (reg_lo << shift_left) | (reg_hi >> shift_right). |
| 3632 | __ Lsl(out_reg_hi, in_reg_hi, shift_left); |
| 3633 | __ Lsr(out_reg_lo, in_reg_lo, shift_right); |
| 3634 | __ Add(out_reg_hi, out_reg_hi, out_reg_lo); |
| 3635 | __ Lsl(out_reg_lo, in_reg_lo, shift_left); |
| 3636 | __ Lsr(shift_left, in_reg_hi, shift_right); |
| 3637 | __ Add(out_reg_lo, out_reg_lo, shift_left); |
| 3638 | __ B(&end); |
| 3639 | |
| 3640 | __ Bind(&shift_by_32_plus_shift_right); // Shift by 32+shift_right. |
| 3641 | // out_reg_hi = (reg_hi >> shift_right) | (reg_lo << shift_left). |
| 3642 | // out_reg_lo = (reg_lo >> shift_right) | (reg_hi << shift_left). |
| 3643 | __ Lsr(out_reg_hi, in_reg_hi, shift_right); |
| 3644 | __ Lsl(out_reg_lo, in_reg_lo, shift_left); |
| 3645 | __ Add(out_reg_hi, out_reg_hi, out_reg_lo); |
| 3646 | __ Lsr(out_reg_lo, in_reg_lo, shift_right); |
| 3647 | __ Lsl(shift_right, in_reg_hi, shift_left); |
| 3648 | __ Add(out_reg_lo, out_reg_lo, shift_right); |
| 3649 | |
| 3650 | __ Bind(&end); |
| 3651 | } |
| 3652 | } |
| 3653 | |
| 3654 | void LocationsBuilderARMVIXL::VisitRor(HRor* ror) { |
| 3655 | LocationSummary* locations = |
| 3656 | new (GetGraph()->GetArena()) LocationSummary(ror, LocationSummary::kNoCall); |
| 3657 | switch (ror->GetResultType()) { |
| 3658 | case Primitive::kPrimInt: { |
| 3659 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3660 | locations->SetInAt(1, Location::RegisterOrConstant(ror->InputAt(1))); |
| 3661 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3662 | break; |
| 3663 | } |
| 3664 | case Primitive::kPrimLong: { |
| 3665 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3666 | if (ror->InputAt(1)->IsConstant()) { |
| 3667 | locations->SetInAt(1, Location::ConstantLocation(ror->InputAt(1)->AsConstant())); |
| 3668 | } else { |
| 3669 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3670 | locations->AddTemp(Location::RequiresRegister()); |
| 3671 | locations->AddTemp(Location::RequiresRegister()); |
| 3672 | } |
| 3673 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 3674 | break; |
| 3675 | } |
| 3676 | default: |
| 3677 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 3678 | } |
| 3679 | } |
| 3680 | |
| 3681 | void InstructionCodeGeneratorARMVIXL::VisitRor(HRor* ror) { |
| 3682 | Primitive::Type type = ror->GetResultType(); |
| 3683 | switch (type) { |
| 3684 | case Primitive::kPrimInt: { |
| 3685 | HandleIntegerRotate(ror); |
| 3686 | break; |
| 3687 | } |
| 3688 | case Primitive::kPrimLong: { |
| 3689 | HandleLongRotate(ror); |
| 3690 | break; |
| 3691 | } |
| 3692 | default: |
| 3693 | LOG(FATAL) << "Unexpected operation type " << type; |
| 3694 | UNREACHABLE(); |
| 3695 | } |
| 3696 | } |
| 3697 | |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 3698 | void LocationsBuilderARMVIXL::HandleShift(HBinaryOperation* op) { |
| 3699 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3700 | |
| 3701 | LocationSummary* locations = |
| 3702 | new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall); |
| 3703 | |
| 3704 | switch (op->GetResultType()) { |
| 3705 | case Primitive::kPrimInt: { |
| 3706 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3707 | if (op->InputAt(1)->IsConstant()) { |
| 3708 | locations->SetInAt(1, Location::ConstantLocation(op->InputAt(1)->AsConstant())); |
| 3709 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3710 | } else { |
| 3711 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3712 | // Make the output overlap, as it will be used to hold the masked |
| 3713 | // second input. |
| 3714 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 3715 | } |
| 3716 | break; |
| 3717 | } |
| 3718 | case Primitive::kPrimLong: { |
| 3719 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3720 | if (op->InputAt(1)->IsConstant()) { |
| 3721 | locations->SetInAt(1, Location::ConstantLocation(op->InputAt(1)->AsConstant())); |
| 3722 | // For simplicity, use kOutputOverlap even though we only require that low registers |
| 3723 | // don't clash with high registers which the register allocator currently guarantees. |
| 3724 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 3725 | } else { |
| 3726 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3727 | locations->AddTemp(Location::RequiresRegister()); |
| 3728 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 3729 | } |
| 3730 | break; |
| 3731 | } |
| 3732 | default: |
| 3733 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
| 3734 | } |
| 3735 | } |
| 3736 | |
| 3737 | void InstructionCodeGeneratorARMVIXL::HandleShift(HBinaryOperation* op) { |
| 3738 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3739 | |
| 3740 | LocationSummary* locations = op->GetLocations(); |
| 3741 | Location out = locations->Out(); |
| 3742 | Location first = locations->InAt(0); |
| 3743 | Location second = locations->InAt(1); |
| 3744 | |
| 3745 | Primitive::Type type = op->GetResultType(); |
| 3746 | switch (type) { |
| 3747 | case Primitive::kPrimInt: { |
| 3748 | vixl32::Register out_reg = OutputRegister(op); |
| 3749 | vixl32::Register first_reg = InputRegisterAt(op, 0); |
| 3750 | if (second.IsRegister()) { |
| 3751 | vixl32::Register second_reg = RegisterFrom(second); |
| 3752 | // ARM doesn't mask the shift count so we need to do it ourselves. |
| 3753 | __ And(out_reg, second_reg, kMaxIntShiftDistance); |
| 3754 | if (op->IsShl()) { |
| 3755 | __ Lsl(out_reg, first_reg, out_reg); |
| 3756 | } else if (op->IsShr()) { |
| 3757 | __ Asr(out_reg, first_reg, out_reg); |
| 3758 | } else { |
| 3759 | __ Lsr(out_reg, first_reg, out_reg); |
| 3760 | } |
| 3761 | } else { |
| 3762 | int32_t cst = second.GetConstant()->AsIntConstant()->GetValue(); |
| 3763 | uint32_t shift_value = cst & kMaxIntShiftDistance; |
| 3764 | if (shift_value == 0) { // ARM does not support shifting with 0 immediate. |
| 3765 | __ Mov(out_reg, first_reg); |
| 3766 | } else if (op->IsShl()) { |
| 3767 | __ Lsl(out_reg, first_reg, shift_value); |
| 3768 | } else if (op->IsShr()) { |
| 3769 | __ Asr(out_reg, first_reg, shift_value); |
| 3770 | } else { |
| 3771 | __ Lsr(out_reg, first_reg, shift_value); |
| 3772 | } |
| 3773 | } |
| 3774 | break; |
| 3775 | } |
| 3776 | case Primitive::kPrimLong: { |
| 3777 | vixl32::Register o_h = HighRegisterFrom(out); |
| 3778 | vixl32::Register o_l = LowRegisterFrom(out); |
| 3779 | |
| 3780 | vixl32::Register high = HighRegisterFrom(first); |
| 3781 | vixl32::Register low = LowRegisterFrom(first); |
| 3782 | |
| 3783 | if (second.IsRegister()) { |
| 3784 | vixl32::Register temp = RegisterFrom(locations->GetTemp(0)); |
| 3785 | |
| 3786 | vixl32::Register second_reg = RegisterFrom(second); |
| 3787 | |
| 3788 | if (op->IsShl()) { |
| 3789 | __ And(o_l, second_reg, kMaxLongShiftDistance); |
| 3790 | // Shift the high part |
| 3791 | __ Lsl(o_h, high, o_l); |
| 3792 | // Shift the low part and `or` what overflew on the high part |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 3793 | __ Rsb(temp, o_l, Operand::From(kArmBitsPerWord)); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 3794 | __ Lsr(temp, low, temp); |
| 3795 | __ Orr(o_h, o_h, temp); |
| 3796 | // If the shift is > 32 bits, override the high part |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 3797 | __ Subs(temp, o_l, Operand::From(kArmBitsPerWord)); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 3798 | { |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 3799 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 3800 | 2 * vixl32::kMaxInstructionSizeInBytes, |
| 3801 | CodeBufferCheckScope::kMaximumSize); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 3802 | __ it(pl); |
| 3803 | __ lsl(pl, o_h, low, temp); |
| 3804 | } |
| 3805 | // Shift the low part |
| 3806 | __ Lsl(o_l, low, o_l); |
| 3807 | } else if (op->IsShr()) { |
| 3808 | __ And(o_h, second_reg, kMaxLongShiftDistance); |
| 3809 | // Shift the low part |
| 3810 | __ Lsr(o_l, low, o_h); |
| 3811 | // Shift the high part and `or` what underflew on the low part |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 3812 | __ Rsb(temp, o_h, Operand::From(kArmBitsPerWord)); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 3813 | __ Lsl(temp, high, temp); |
| 3814 | __ Orr(o_l, o_l, temp); |
| 3815 | // If the shift is > 32 bits, override the low part |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 3816 | __ Subs(temp, o_h, Operand::From(kArmBitsPerWord)); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 3817 | { |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 3818 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 3819 | 2 * vixl32::kMaxInstructionSizeInBytes, |
| 3820 | CodeBufferCheckScope::kMaximumSize); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 3821 | __ it(pl); |
| 3822 | __ asr(pl, o_l, high, temp); |
| 3823 | } |
| 3824 | // Shift the high part |
| 3825 | __ Asr(o_h, high, o_h); |
| 3826 | } else { |
| 3827 | __ And(o_h, second_reg, kMaxLongShiftDistance); |
| 3828 | // same as Shr except we use `Lsr`s and not `Asr`s |
| 3829 | __ Lsr(o_l, low, o_h); |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 3830 | __ Rsb(temp, o_h, Operand::From(kArmBitsPerWord)); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 3831 | __ Lsl(temp, high, temp); |
| 3832 | __ Orr(o_l, o_l, temp); |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 3833 | __ Subs(temp, o_h, Operand::From(kArmBitsPerWord)); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 3834 | { |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 3835 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 3836 | 2 * vixl32::kMaxInstructionSizeInBytes, |
| 3837 | CodeBufferCheckScope::kMaximumSize); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 3838 | __ it(pl); |
| 3839 | __ lsr(pl, o_l, high, temp); |
| 3840 | } |
| 3841 | __ Lsr(o_h, high, o_h); |
| 3842 | } |
| 3843 | } else { |
| 3844 | // Register allocator doesn't create partial overlap. |
| 3845 | DCHECK(!o_l.Is(high)); |
| 3846 | DCHECK(!o_h.Is(low)); |
| 3847 | int32_t cst = second.GetConstant()->AsIntConstant()->GetValue(); |
| 3848 | uint32_t shift_value = cst & kMaxLongShiftDistance; |
| 3849 | if (shift_value > 32) { |
| 3850 | if (op->IsShl()) { |
| 3851 | __ Lsl(o_h, low, shift_value - 32); |
| 3852 | __ Mov(o_l, 0); |
| 3853 | } else if (op->IsShr()) { |
| 3854 | __ Asr(o_l, high, shift_value - 32); |
| 3855 | __ Asr(o_h, high, 31); |
| 3856 | } else { |
| 3857 | __ Lsr(o_l, high, shift_value - 32); |
| 3858 | __ Mov(o_h, 0); |
| 3859 | } |
| 3860 | } else if (shift_value == 32) { |
| 3861 | if (op->IsShl()) { |
| 3862 | __ Mov(o_h, low); |
| 3863 | __ Mov(o_l, 0); |
| 3864 | } else if (op->IsShr()) { |
| 3865 | __ Mov(o_l, high); |
| 3866 | __ Asr(o_h, high, 31); |
| 3867 | } else { |
| 3868 | __ Mov(o_l, high); |
| 3869 | __ Mov(o_h, 0); |
| 3870 | } |
| 3871 | } else if (shift_value == 1) { |
| 3872 | if (op->IsShl()) { |
| 3873 | __ Lsls(o_l, low, 1); |
| 3874 | __ Adc(o_h, high, high); |
| 3875 | } else if (op->IsShr()) { |
| 3876 | __ Asrs(o_h, high, 1); |
| 3877 | __ Rrx(o_l, low); |
| 3878 | } else { |
| 3879 | __ Lsrs(o_h, high, 1); |
| 3880 | __ Rrx(o_l, low); |
| 3881 | } |
| 3882 | } else { |
| 3883 | DCHECK(2 <= shift_value && shift_value < 32) << shift_value; |
| 3884 | if (op->IsShl()) { |
| 3885 | __ Lsl(o_h, high, shift_value); |
| 3886 | __ Orr(o_h, o_h, Operand(low, ShiftType::LSR, 32 - shift_value)); |
| 3887 | __ Lsl(o_l, low, shift_value); |
| 3888 | } else if (op->IsShr()) { |
| 3889 | __ Lsr(o_l, low, shift_value); |
| 3890 | __ Orr(o_l, o_l, Operand(high, ShiftType::LSL, 32 - shift_value)); |
| 3891 | __ Asr(o_h, high, shift_value); |
| 3892 | } else { |
| 3893 | __ Lsr(o_l, low, shift_value); |
| 3894 | __ Orr(o_l, o_l, Operand(high, ShiftType::LSL, 32 - shift_value)); |
| 3895 | __ Lsr(o_h, high, shift_value); |
| 3896 | } |
| 3897 | } |
| 3898 | } |
| 3899 | break; |
| 3900 | } |
| 3901 | default: |
| 3902 | LOG(FATAL) << "Unexpected operation type " << type; |
| 3903 | UNREACHABLE(); |
| 3904 | } |
| 3905 | } |
| 3906 | |
| 3907 | void LocationsBuilderARMVIXL::VisitShl(HShl* shl) { |
| 3908 | HandleShift(shl); |
| 3909 | } |
| 3910 | |
| 3911 | void InstructionCodeGeneratorARMVIXL::VisitShl(HShl* shl) { |
| 3912 | HandleShift(shl); |
| 3913 | } |
| 3914 | |
| 3915 | void LocationsBuilderARMVIXL::VisitShr(HShr* shr) { |
| 3916 | HandleShift(shr); |
| 3917 | } |
| 3918 | |
| 3919 | void InstructionCodeGeneratorARMVIXL::VisitShr(HShr* shr) { |
| 3920 | HandleShift(shr); |
| 3921 | } |
| 3922 | |
| 3923 | void LocationsBuilderARMVIXL::VisitUShr(HUShr* ushr) { |
| 3924 | HandleShift(ushr); |
| 3925 | } |
| 3926 | |
| 3927 | void InstructionCodeGeneratorARMVIXL::VisitUShr(HUShr* ushr) { |
| 3928 | HandleShift(ushr); |
| 3929 | } |
| 3930 | |
| 3931 | void LocationsBuilderARMVIXL::VisitNewInstance(HNewInstance* instruction) { |
| 3932 | LocationSummary* locations = |
| 3933 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
| 3934 | if (instruction->IsStringAlloc()) { |
| 3935 | locations->AddTemp(LocationFrom(kMethodRegister)); |
| 3936 | } else { |
| 3937 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 3938 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 3939 | locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(1))); |
| 3940 | } |
| 3941 | locations->SetOut(LocationFrom(r0)); |
| 3942 | } |
| 3943 | |
| 3944 | void InstructionCodeGeneratorARMVIXL::VisitNewInstance(HNewInstance* instruction) { |
| 3945 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 3946 | // of poisoning the reference. |
| 3947 | if (instruction->IsStringAlloc()) { |
| 3948 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 3949 | vixl32::Register temp = RegisterFrom(instruction->GetLocations()->GetTemp(0)); |
| 3950 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize); |
| 3951 | GetAssembler()->LoadFromOffset(kLoadWord, temp, tr, QUICK_ENTRY_POINT(pNewEmptyString)); |
| 3952 | GetAssembler()->LoadFromOffset(kLoadWord, lr, temp, code_offset.Int32Value()); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 3953 | // 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] | 3954 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 3955 | vixl32::k16BitT32InstructionSizeInBytes, |
| 3956 | CodeBufferCheckScope::kExactSize); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 3957 | __ blx(lr); |
| 3958 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 3959 | } else { |
| 3960 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
| 3961 | CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, ArtMethod*>(); |
| 3962 | } |
| 3963 | } |
| 3964 | |
| 3965 | void LocationsBuilderARMVIXL::VisitNewArray(HNewArray* instruction) { |
| 3966 | LocationSummary* locations = |
| 3967 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
| 3968 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 3969 | locations->AddTemp(LocationFrom(calling_convention.GetRegisterAt(0))); |
| 3970 | locations->SetOut(LocationFrom(r0)); |
| 3971 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(1))); |
| 3972 | locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(2))); |
| 3973 | } |
| 3974 | |
| 3975 | void InstructionCodeGeneratorARMVIXL::VisitNewArray(HNewArray* instruction) { |
| 3976 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 3977 | __ Mov(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex().index_); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 3978 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 3979 | // of poisoning the reference. |
| 3980 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
| 3981 | CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck, void*, uint32_t, int32_t, ArtMethod*>(); |
| 3982 | } |
| 3983 | |
| 3984 | void LocationsBuilderARMVIXL::VisitParameterValue(HParameterValue* instruction) { |
| 3985 | LocationSummary* locations = |
| 3986 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 3987 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 3988 | if (location.IsStackSlot()) { |
| 3989 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 3990 | } else if (location.IsDoubleStackSlot()) { |
| 3991 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 3992 | } |
| 3993 | locations->SetOut(location); |
| 3994 | } |
| 3995 | |
| 3996 | void InstructionCodeGeneratorARMVIXL::VisitParameterValue( |
| 3997 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
| 3998 | // Nothing to do, the parameter is already at its location. |
| 3999 | } |
| 4000 | |
| 4001 | void LocationsBuilderARMVIXL::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 4002 | LocationSummary* locations = |
| 4003 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4004 | locations->SetOut(LocationFrom(kMethodRegister)); |
| 4005 | } |
| 4006 | |
| 4007 | void InstructionCodeGeneratorARMVIXL::VisitCurrentMethod( |
| 4008 | HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
| 4009 | // Nothing to do, the method is already at its location. |
| 4010 | } |
| 4011 | |
| 4012 | void LocationsBuilderARMVIXL::VisitNot(HNot* not_) { |
| 4013 | LocationSummary* locations = |
| 4014 | new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall); |
| 4015 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4016 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4017 | } |
| 4018 | |
| 4019 | void InstructionCodeGeneratorARMVIXL::VisitNot(HNot* not_) { |
| 4020 | LocationSummary* locations = not_->GetLocations(); |
| 4021 | Location out = locations->Out(); |
| 4022 | Location in = locations->InAt(0); |
| 4023 | switch (not_->GetResultType()) { |
| 4024 | case Primitive::kPrimInt: |
| 4025 | __ Mvn(OutputRegister(not_), InputRegisterAt(not_, 0)); |
| 4026 | break; |
| 4027 | |
| 4028 | case Primitive::kPrimLong: |
| 4029 | __ Mvn(LowRegisterFrom(out), LowRegisterFrom(in)); |
| 4030 | __ Mvn(HighRegisterFrom(out), HighRegisterFrom(in)); |
| 4031 | break; |
| 4032 | |
| 4033 | default: |
| 4034 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 4035 | } |
| 4036 | } |
| 4037 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 4038 | void LocationsBuilderARMVIXL::VisitBooleanNot(HBooleanNot* bool_not) { |
| 4039 | LocationSummary* locations = |
| 4040 | new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall); |
| 4041 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4042 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4043 | } |
| 4044 | |
| 4045 | void InstructionCodeGeneratorARMVIXL::VisitBooleanNot(HBooleanNot* bool_not) { |
| 4046 | __ Eor(OutputRegister(bool_not), InputRegister(bool_not), 1); |
| 4047 | } |
| 4048 | |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4049 | void LocationsBuilderARMVIXL::VisitCompare(HCompare* compare) { |
| 4050 | LocationSummary* locations = |
| 4051 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
| 4052 | switch (compare->InputAt(0)->GetType()) { |
| 4053 | case Primitive::kPrimBoolean: |
| 4054 | case Primitive::kPrimByte: |
| 4055 | case Primitive::kPrimShort: |
| 4056 | case Primitive::kPrimChar: |
| 4057 | case Primitive::kPrimInt: |
| 4058 | case Primitive::kPrimLong: { |
| 4059 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4060 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4061 | // Output overlaps because it is written before doing the low comparison. |
| 4062 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 4063 | break; |
| 4064 | } |
| 4065 | case Primitive::kPrimFloat: |
| 4066 | case Primitive::kPrimDouble: { |
| 4067 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4068 | locations->SetInAt(1, ArithmeticZeroOrFpuRegister(compare->InputAt(1))); |
| 4069 | locations->SetOut(Location::RequiresRegister()); |
| 4070 | break; |
| 4071 | } |
| 4072 | default: |
| 4073 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 4074 | } |
| 4075 | } |
| 4076 | |
| 4077 | void InstructionCodeGeneratorARMVIXL::VisitCompare(HCompare* compare) { |
| 4078 | LocationSummary* locations = compare->GetLocations(); |
| 4079 | vixl32::Register out = OutputRegister(compare); |
| 4080 | Location left = locations->InAt(0); |
| 4081 | Location right = locations->InAt(1); |
| 4082 | |
| 4083 | vixl32::Label less, greater, done; |
| 4084 | Primitive::Type type = compare->InputAt(0)->GetType(); |
| 4085 | vixl32::Condition less_cond = vixl32::Condition(kNone); |
| 4086 | switch (type) { |
| 4087 | case Primitive::kPrimBoolean: |
| 4088 | case Primitive::kPrimByte: |
| 4089 | case Primitive::kPrimShort: |
| 4090 | case Primitive::kPrimChar: |
| 4091 | case Primitive::kPrimInt: { |
| 4092 | // Emit move to `out` before the `Cmp`, as `Mov` might affect the status flags. |
| 4093 | __ Mov(out, 0); |
| 4094 | __ Cmp(RegisterFrom(left), RegisterFrom(right)); // Signed compare. |
| 4095 | less_cond = lt; |
| 4096 | break; |
| 4097 | } |
| 4098 | case Primitive::kPrimLong: { |
| 4099 | __ Cmp(HighRegisterFrom(left), HighRegisterFrom(right)); // Signed compare. |
| 4100 | __ B(lt, &less); |
| 4101 | __ B(gt, &greater); |
| 4102 | // Emit move to `out` before the last `Cmp`, as `Mov` might affect the status flags. |
| 4103 | __ Mov(out, 0); |
| 4104 | __ Cmp(LowRegisterFrom(left), LowRegisterFrom(right)); // Unsigned compare. |
| 4105 | less_cond = lo; |
| 4106 | break; |
| 4107 | } |
| 4108 | case Primitive::kPrimFloat: |
| 4109 | case Primitive::kPrimDouble: { |
| 4110 | __ Mov(out, 0); |
| 4111 | GenerateVcmp(compare); |
| 4112 | // To branch on the FP compare result we transfer FPSCR to APSR (encoded as PC in VMRS). |
| 4113 | __ Vmrs(RegisterOrAPSR_nzcv(kPcCode), FPSCR); |
| 4114 | less_cond = ARMFPCondition(kCondLT, compare->IsGtBias()); |
| 4115 | break; |
| 4116 | } |
| 4117 | default: |
| 4118 | LOG(FATAL) << "Unexpected compare type " << type; |
| 4119 | UNREACHABLE(); |
| 4120 | } |
| 4121 | |
| 4122 | __ B(eq, &done); |
| 4123 | __ B(less_cond, &less); |
| 4124 | |
| 4125 | __ Bind(&greater); |
| 4126 | __ Mov(out, 1); |
| 4127 | __ B(&done); |
| 4128 | |
| 4129 | __ Bind(&less); |
| 4130 | __ Mov(out, -1); |
| 4131 | |
| 4132 | __ Bind(&done); |
| 4133 | } |
| 4134 | |
| 4135 | void LocationsBuilderARMVIXL::VisitPhi(HPhi* instruction) { |
| 4136 | LocationSummary* locations = |
| 4137 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4138 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
| 4139 | locations->SetInAt(i, Location::Any()); |
| 4140 | } |
| 4141 | locations->SetOut(Location::Any()); |
| 4142 | } |
| 4143 | |
| 4144 | void InstructionCodeGeneratorARMVIXL::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
| 4145 | LOG(FATAL) << "Unreachable"; |
| 4146 | } |
| 4147 | |
| 4148 | void CodeGeneratorARMVIXL::GenerateMemoryBarrier(MemBarrierKind kind) { |
| 4149 | // TODO (ported from quick): revisit ARM barrier kinds. |
| 4150 | DmbOptions flavor = DmbOptions::ISH; // Quiet C++ warnings. |
| 4151 | switch (kind) { |
| 4152 | case MemBarrierKind::kAnyStore: |
| 4153 | case MemBarrierKind::kLoadAny: |
| 4154 | case MemBarrierKind::kAnyAny: { |
| 4155 | flavor = DmbOptions::ISH; |
| 4156 | break; |
| 4157 | } |
| 4158 | case MemBarrierKind::kStoreStore: { |
| 4159 | flavor = DmbOptions::ISHST; |
| 4160 | break; |
| 4161 | } |
| 4162 | default: |
| 4163 | LOG(FATAL) << "Unexpected memory barrier " << kind; |
| 4164 | } |
| 4165 | __ Dmb(flavor); |
| 4166 | } |
| 4167 | |
| 4168 | void InstructionCodeGeneratorARMVIXL::GenerateWideAtomicLoad(vixl32::Register addr, |
| 4169 | uint32_t offset, |
| 4170 | vixl32::Register out_lo, |
| 4171 | vixl32::Register out_hi) { |
| 4172 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 4173 | if (offset != 0) { |
| 4174 | vixl32::Register temp = temps.Acquire(); |
| 4175 | __ Add(temp, addr, offset); |
| 4176 | addr = temp; |
| 4177 | } |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 4178 | __ Ldrexd(out_lo, out_hi, MemOperand(addr)); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4179 | } |
| 4180 | |
| 4181 | void InstructionCodeGeneratorARMVIXL::GenerateWideAtomicStore(vixl32::Register addr, |
| 4182 | uint32_t offset, |
| 4183 | vixl32::Register value_lo, |
| 4184 | vixl32::Register value_hi, |
| 4185 | vixl32::Register temp1, |
| 4186 | vixl32::Register temp2, |
| 4187 | HInstruction* instruction) { |
| 4188 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 4189 | vixl32::Label fail; |
| 4190 | if (offset != 0) { |
| 4191 | vixl32::Register temp = temps.Acquire(); |
| 4192 | __ Add(temp, addr, offset); |
| 4193 | addr = temp; |
| 4194 | } |
| 4195 | __ Bind(&fail); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 4196 | { |
| 4197 | // Ensure the pc position is recorded immediately after the `ldrexd` instruction. |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 4198 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 4199 | vixl32::kMaxInstructionSizeInBytes, |
| 4200 | CodeBufferCheckScope::kMaximumSize); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 4201 | // We need a load followed by store. (The address used in a STREX instruction must |
| 4202 | // be the same as the address in the most recently executed LDREX instruction.) |
| 4203 | __ ldrexd(temp1, temp2, MemOperand(addr)); |
| 4204 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4205 | } |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 4206 | __ Strexd(temp1, value_lo, value_hi, MemOperand(addr)); |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 4207 | __ CompareAndBranchIfNonZero(temp1, &fail); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4208 | } |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 4209 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4210 | void LocationsBuilderARMVIXL::HandleFieldSet( |
| 4211 | HInstruction* instruction, const FieldInfo& field_info) { |
| 4212 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4213 | |
| 4214 | LocationSummary* locations = |
| 4215 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4216 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4217 | |
| 4218 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4219 | if (Primitive::IsFloatingPointType(field_type)) { |
| 4220 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4221 | } else { |
| 4222 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4223 | } |
| 4224 | |
| 4225 | bool is_wide = field_type == Primitive::kPrimLong || field_type == Primitive::kPrimDouble; |
| 4226 | bool generate_volatile = field_info.IsVolatile() |
| 4227 | && is_wide |
| 4228 | && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
| 4229 | bool needs_write_barrier = |
| 4230 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
| 4231 | // Temporary registers for the write barrier. |
| 4232 | // TODO: consider renaming StoreNeedsWriteBarrier to StoreNeedsGCMark. |
| 4233 | if (needs_write_barrier) { |
| 4234 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for reference poisoning too. |
| 4235 | locations->AddTemp(Location::RequiresRegister()); |
| 4236 | } else if (generate_volatile) { |
| 4237 | // ARM encoding have some additional constraints for ldrexd/strexd: |
| 4238 | // - registers need to be consecutive |
| 4239 | // - the first register should be even but not R14. |
| 4240 | // We don't test for ARM yet, and the assertion makes sure that we |
| 4241 | // revisit this if we ever enable ARM encoding. |
| 4242 | DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet()); |
| 4243 | |
| 4244 | locations->AddTemp(Location::RequiresRegister()); |
| 4245 | locations->AddTemp(Location::RequiresRegister()); |
| 4246 | if (field_type == Primitive::kPrimDouble) { |
| 4247 | // For doubles we need two more registers to copy the value. |
| 4248 | locations->AddTemp(LocationFrom(r2)); |
| 4249 | locations->AddTemp(LocationFrom(r3)); |
| 4250 | } |
| 4251 | } |
| 4252 | } |
| 4253 | |
| 4254 | void InstructionCodeGeneratorARMVIXL::HandleFieldSet(HInstruction* instruction, |
| 4255 | const FieldInfo& field_info, |
| 4256 | bool value_can_be_null) { |
| 4257 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4258 | |
| 4259 | LocationSummary* locations = instruction->GetLocations(); |
| 4260 | vixl32::Register base = InputRegisterAt(instruction, 0); |
| 4261 | Location value = locations->InAt(1); |
| 4262 | |
| 4263 | bool is_volatile = field_info.IsVolatile(); |
| 4264 | bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
| 4265 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4266 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 4267 | bool needs_write_barrier = |
| 4268 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
| 4269 | |
| 4270 | if (is_volatile) { |
| 4271 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
| 4272 | } |
| 4273 | |
| 4274 | switch (field_type) { |
| 4275 | case Primitive::kPrimBoolean: |
| 4276 | case Primitive::kPrimByte: { |
| 4277 | GetAssembler()->StoreToOffset(kStoreByte, RegisterFrom(value), base, offset); |
| 4278 | break; |
| 4279 | } |
| 4280 | |
| 4281 | case Primitive::kPrimShort: |
| 4282 | case Primitive::kPrimChar: { |
| 4283 | GetAssembler()->StoreToOffset(kStoreHalfword, RegisterFrom(value), base, offset); |
| 4284 | break; |
| 4285 | } |
| 4286 | |
| 4287 | case Primitive::kPrimInt: |
| 4288 | case Primitive::kPrimNot: { |
| 4289 | if (kPoisonHeapReferences && needs_write_barrier) { |
| 4290 | // Note that in the case where `value` is a null reference, |
| 4291 | // we do not enter this block, as a null reference does not |
| 4292 | // need poisoning. |
| 4293 | DCHECK_EQ(field_type, Primitive::kPrimNot); |
| 4294 | vixl32::Register temp = RegisterFrom(locations->GetTemp(0)); |
| 4295 | __ Mov(temp, RegisterFrom(value)); |
| 4296 | GetAssembler()->PoisonHeapReference(temp); |
| 4297 | GetAssembler()->StoreToOffset(kStoreWord, temp, base, offset); |
| 4298 | } else { |
| 4299 | GetAssembler()->StoreToOffset(kStoreWord, RegisterFrom(value), base, offset); |
| 4300 | } |
| 4301 | break; |
| 4302 | } |
| 4303 | |
| 4304 | case Primitive::kPrimLong: { |
| 4305 | if (is_volatile && !atomic_ldrd_strd) { |
| 4306 | GenerateWideAtomicStore(base, |
| 4307 | offset, |
| 4308 | LowRegisterFrom(value), |
| 4309 | HighRegisterFrom(value), |
| 4310 | RegisterFrom(locations->GetTemp(0)), |
| 4311 | RegisterFrom(locations->GetTemp(1)), |
| 4312 | instruction); |
| 4313 | } else { |
| 4314 | GetAssembler()->StoreToOffset(kStoreWordPair, LowRegisterFrom(value), base, offset); |
| 4315 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4316 | } |
| 4317 | break; |
| 4318 | } |
| 4319 | |
| 4320 | case Primitive::kPrimFloat: { |
| 4321 | GetAssembler()->StoreSToOffset(SRegisterFrom(value), base, offset); |
| 4322 | break; |
| 4323 | } |
| 4324 | |
| 4325 | case Primitive::kPrimDouble: { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 4326 | vixl32::DRegister value_reg = DRegisterFrom(value); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4327 | if (is_volatile && !atomic_ldrd_strd) { |
| 4328 | vixl32::Register value_reg_lo = RegisterFrom(locations->GetTemp(0)); |
| 4329 | vixl32::Register value_reg_hi = RegisterFrom(locations->GetTemp(1)); |
| 4330 | |
| 4331 | __ Vmov(value_reg_lo, value_reg_hi, value_reg); |
| 4332 | |
| 4333 | GenerateWideAtomicStore(base, |
| 4334 | offset, |
| 4335 | value_reg_lo, |
| 4336 | value_reg_hi, |
| 4337 | RegisterFrom(locations->GetTemp(2)), |
| 4338 | RegisterFrom(locations->GetTemp(3)), |
| 4339 | instruction); |
| 4340 | } else { |
| 4341 | GetAssembler()->StoreDToOffset(value_reg, base, offset); |
| 4342 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4343 | } |
| 4344 | break; |
| 4345 | } |
| 4346 | |
| 4347 | case Primitive::kPrimVoid: |
| 4348 | LOG(FATAL) << "Unreachable type " << field_type; |
| 4349 | UNREACHABLE(); |
| 4350 | } |
| 4351 | |
| 4352 | // Longs and doubles are handled in the switch. |
| 4353 | if (field_type != Primitive::kPrimLong && field_type != Primitive::kPrimDouble) { |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 4354 | // TODO(VIXL): Here and for other calls to `MaybeRecordImplicitNullCheck` in this method, we |
| 4355 | // should use a scope and the assembler to emit the store instruction to guarantee that we |
| 4356 | // record the pc at the correct position. But the `Assembler` does not automatically handle |
| 4357 | // unencodable offsets. Practically, everything is fine because the helper and VIXL, at the time |
| 4358 | // of writing, do generate the store instruction last. |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4359 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4360 | } |
| 4361 | |
| 4362 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 4363 | vixl32::Register temp = RegisterFrom(locations->GetTemp(0)); |
| 4364 | vixl32::Register card = RegisterFrom(locations->GetTemp(1)); |
| 4365 | codegen_->MarkGCCard(temp, card, base, RegisterFrom(value), value_can_be_null); |
| 4366 | } |
| 4367 | |
| 4368 | if (is_volatile) { |
| 4369 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
| 4370 | } |
| 4371 | } |
| 4372 | |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4373 | void LocationsBuilderARMVIXL::HandleFieldGet(HInstruction* instruction, |
| 4374 | const FieldInfo& field_info) { |
| 4375 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 4376 | |
| 4377 | bool object_field_get_with_read_barrier = |
| 4378 | kEmitCompilerReadBarrier && (field_info.GetFieldType() == Primitive::kPrimNot); |
| 4379 | LocationSummary* locations = |
| 4380 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 4381 | object_field_get_with_read_barrier ? |
| 4382 | LocationSummary::kCallOnSlowPath : |
| 4383 | LocationSummary::kNoCall); |
| 4384 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| 4385 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| 4386 | } |
| 4387 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4388 | |
| 4389 | bool volatile_for_double = field_info.IsVolatile() |
| 4390 | && (field_info.GetFieldType() == Primitive::kPrimDouble) |
| 4391 | && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
| 4392 | // The output overlaps in case of volatile long: we don't want the |
| 4393 | // code generated by GenerateWideAtomicLoad to overwrite the |
| 4394 | // object's location. Likewise, in the case of an object field get |
| 4395 | // with read barriers enabled, we do not want the load to overwrite |
| 4396 | // the object's location, as we need it to emit the read barrier. |
| 4397 | bool overlap = (field_info.IsVolatile() && (field_info.GetFieldType() == Primitive::kPrimLong)) || |
| 4398 | object_field_get_with_read_barrier; |
| 4399 | |
| 4400 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 4401 | locations->SetOut(Location::RequiresFpuRegister()); |
| 4402 | } else { |
| 4403 | locations->SetOut(Location::RequiresRegister(), |
| 4404 | (overlap ? Location::kOutputOverlap : Location::kNoOutputOverlap)); |
| 4405 | } |
| 4406 | if (volatile_for_double) { |
| 4407 | // ARM encoding have some additional constraints for ldrexd/strexd: |
| 4408 | // - registers need to be consecutive |
| 4409 | // - the first register should be even but not R14. |
| 4410 | // We don't test for ARM yet, and the assertion makes sure that we |
| 4411 | // revisit this if we ever enable ARM encoding. |
| 4412 | DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet()); |
| 4413 | locations->AddTemp(Location::RequiresRegister()); |
| 4414 | locations->AddTemp(Location::RequiresRegister()); |
| 4415 | } else if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| 4416 | // We need a temporary register for the read barrier marking slow |
| 4417 | // path in CodeGeneratorARM::GenerateFieldLoadWithBakerReadBarrier. |
| 4418 | locations->AddTemp(Location::RequiresRegister()); |
| 4419 | } |
| 4420 | } |
| 4421 | |
| 4422 | Location LocationsBuilderARMVIXL::ArithmeticZeroOrFpuRegister(HInstruction* input) { |
| 4423 | DCHECK(Primitive::IsFloatingPointType(input->GetType())) << input->GetType(); |
| 4424 | if ((input->IsFloatConstant() && (input->AsFloatConstant()->IsArithmeticZero())) || |
| 4425 | (input->IsDoubleConstant() && (input->AsDoubleConstant()->IsArithmeticZero()))) { |
| 4426 | return Location::ConstantLocation(input->AsConstant()); |
| 4427 | } else { |
| 4428 | return Location::RequiresFpuRegister(); |
| 4429 | } |
| 4430 | } |
| 4431 | |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 4432 | Location LocationsBuilderARMVIXL::ArmEncodableConstantOrRegister(HInstruction* constant, |
| 4433 | Opcode opcode) { |
| 4434 | DCHECK(!Primitive::IsFloatingPointType(constant->GetType())); |
| 4435 | if (constant->IsConstant() && |
| 4436 | CanEncodeConstantAsImmediate(constant->AsConstant(), opcode)) { |
| 4437 | return Location::ConstantLocation(constant->AsConstant()); |
| 4438 | } |
| 4439 | return Location::RequiresRegister(); |
| 4440 | } |
| 4441 | |
| 4442 | bool LocationsBuilderARMVIXL::CanEncodeConstantAsImmediate(HConstant* input_cst, |
| 4443 | Opcode opcode) { |
| 4444 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(input_cst)); |
| 4445 | if (Primitive::Is64BitType(input_cst->GetType())) { |
| 4446 | Opcode high_opcode = opcode; |
| 4447 | SetCc low_set_cc = kCcDontCare; |
| 4448 | switch (opcode) { |
| 4449 | case SUB: |
| 4450 | // Flip the operation to an ADD. |
| 4451 | value = -value; |
| 4452 | opcode = ADD; |
| 4453 | FALLTHROUGH_INTENDED; |
| 4454 | case ADD: |
| 4455 | if (Low32Bits(value) == 0u) { |
| 4456 | return CanEncodeConstantAsImmediate(High32Bits(value), opcode, kCcDontCare); |
| 4457 | } |
| 4458 | high_opcode = ADC; |
| 4459 | low_set_cc = kCcSet; |
| 4460 | break; |
| 4461 | default: |
| 4462 | break; |
| 4463 | } |
| 4464 | return CanEncodeConstantAsImmediate(Low32Bits(value), opcode, low_set_cc) && |
| 4465 | CanEncodeConstantAsImmediate(High32Bits(value), high_opcode, kCcDontCare); |
| 4466 | } else { |
| 4467 | return CanEncodeConstantAsImmediate(Low32Bits(value), opcode); |
| 4468 | } |
| 4469 | } |
| 4470 | |
| 4471 | // TODO(VIXL): Replace art::arm::SetCc` with `vixl32::FlagsUpdate after flags set optimization |
| 4472 | // enabled. |
| 4473 | bool LocationsBuilderARMVIXL::CanEncodeConstantAsImmediate(uint32_t value, |
| 4474 | Opcode opcode, |
| 4475 | SetCc set_cc) { |
| 4476 | ArmVIXLAssembler* assembler = codegen_->GetAssembler(); |
| 4477 | if (assembler->ShifterOperandCanHold(opcode, value, set_cc)) { |
| 4478 | return true; |
| 4479 | } |
| 4480 | Opcode neg_opcode = kNoOperand; |
| 4481 | switch (opcode) { |
| 4482 | case AND: neg_opcode = BIC; value = ~value; break; |
| 4483 | case ORR: neg_opcode = ORN; value = ~value; break; |
| 4484 | case ADD: neg_opcode = SUB; value = -value; break; |
| 4485 | case ADC: neg_opcode = SBC; value = ~value; break; |
| 4486 | case SUB: neg_opcode = ADD; value = -value; break; |
| 4487 | case SBC: neg_opcode = ADC; value = ~value; break; |
| 4488 | default: |
| 4489 | return false; |
| 4490 | } |
| 4491 | return assembler->ShifterOperandCanHold(neg_opcode, value, set_cc); |
| 4492 | } |
| 4493 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4494 | void InstructionCodeGeneratorARMVIXL::HandleFieldGet(HInstruction* instruction, |
| 4495 | const FieldInfo& field_info) { |
| 4496 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 4497 | |
| 4498 | LocationSummary* locations = instruction->GetLocations(); |
| 4499 | vixl32::Register base = InputRegisterAt(instruction, 0); |
| 4500 | Location out = locations->Out(); |
| 4501 | bool is_volatile = field_info.IsVolatile(); |
| 4502 | bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
| 4503 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4504 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 4505 | |
| 4506 | switch (field_type) { |
| 4507 | case Primitive::kPrimBoolean: |
| 4508 | GetAssembler()->LoadFromOffset(kLoadUnsignedByte, RegisterFrom(out), base, offset); |
| 4509 | break; |
| 4510 | |
| 4511 | case Primitive::kPrimByte: |
| 4512 | GetAssembler()->LoadFromOffset(kLoadSignedByte, RegisterFrom(out), base, offset); |
| 4513 | break; |
| 4514 | |
| 4515 | case Primitive::kPrimShort: |
| 4516 | GetAssembler()->LoadFromOffset(kLoadSignedHalfword, RegisterFrom(out), base, offset); |
| 4517 | break; |
| 4518 | |
| 4519 | case Primitive::kPrimChar: |
| 4520 | GetAssembler()->LoadFromOffset(kLoadUnsignedHalfword, RegisterFrom(out), base, offset); |
| 4521 | break; |
| 4522 | |
| 4523 | case Primitive::kPrimInt: |
| 4524 | GetAssembler()->LoadFromOffset(kLoadWord, RegisterFrom(out), base, offset); |
| 4525 | break; |
| 4526 | |
| 4527 | case Primitive::kPrimNot: { |
| 4528 | // /* HeapReference<Object> */ out = *(base + offset) |
| 4529 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 4530 | Location temp_loc = locations->GetTemp(0); |
| 4531 | // Note that a potential implicit null check is handled in this |
| 4532 | // CodeGeneratorARMVIXL::GenerateFieldLoadWithBakerReadBarrier call. |
| 4533 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 4534 | instruction, out, base, offset, temp_loc, /* needs_null_check */ true); |
| 4535 | if (is_volatile) { |
| 4536 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4537 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4538 | } else { |
| 4539 | GetAssembler()->LoadFromOffset(kLoadWord, RegisterFrom(out), base, offset); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4540 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4541 | if (is_volatile) { |
| 4542 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4543 | } |
| 4544 | // If read barriers are enabled, emit read barriers other than |
| 4545 | // Baker's using a slow path (and also unpoison the loaded |
| 4546 | // reference, if heap poisoning is enabled). |
| 4547 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, locations->InAt(0), offset); |
| 4548 | } |
| 4549 | break; |
| 4550 | } |
| 4551 | |
| 4552 | case Primitive::kPrimLong: |
| 4553 | if (is_volatile && !atomic_ldrd_strd) { |
| 4554 | GenerateWideAtomicLoad(base, offset, LowRegisterFrom(out), HighRegisterFrom(out)); |
| 4555 | } else { |
| 4556 | GetAssembler()->LoadFromOffset(kLoadWordPair, LowRegisterFrom(out), base, offset); |
| 4557 | } |
| 4558 | break; |
| 4559 | |
| 4560 | case Primitive::kPrimFloat: |
| 4561 | GetAssembler()->LoadSFromOffset(SRegisterFrom(out), base, offset); |
| 4562 | break; |
| 4563 | |
| 4564 | case Primitive::kPrimDouble: { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 4565 | vixl32::DRegister out_dreg = DRegisterFrom(out); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4566 | if (is_volatile && !atomic_ldrd_strd) { |
| 4567 | vixl32::Register lo = RegisterFrom(locations->GetTemp(0)); |
| 4568 | vixl32::Register hi = RegisterFrom(locations->GetTemp(1)); |
| 4569 | GenerateWideAtomicLoad(base, offset, lo, hi); |
| 4570 | // TODO(VIXL): Do we need to be immediately after the ldrexd instruction? If so we need a |
| 4571 | // scope. |
| 4572 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4573 | __ Vmov(out_dreg, lo, hi); |
| 4574 | } else { |
| 4575 | GetAssembler()->LoadDFromOffset(out_dreg, base, offset); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4576 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4577 | } |
| 4578 | break; |
| 4579 | } |
| 4580 | |
| 4581 | case Primitive::kPrimVoid: |
| 4582 | LOG(FATAL) << "Unreachable type " << field_type; |
| 4583 | UNREACHABLE(); |
| 4584 | } |
| 4585 | |
| 4586 | if (field_type == Primitive::kPrimNot || field_type == Primitive::kPrimDouble) { |
| 4587 | // Potential implicit null checks, in the case of reference or |
| 4588 | // double fields, are handled in the previous switch statement. |
| 4589 | } else { |
| 4590 | // 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] | 4591 | // TODO(VIXL): Here and for other calls to `MaybeRecordImplicitNullCheck` in this method, we |
| 4592 | // should use a scope and the assembler to emit the load instruction to guarantee that we |
| 4593 | // record the pc at the correct position. But the `Assembler` does not automatically handle |
| 4594 | // unencodable offsets. Practically, everything is fine because the helper and VIXL, at the time |
| 4595 | // of writing, do generate the store instruction last. |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4596 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4597 | } |
| 4598 | |
| 4599 | if (is_volatile) { |
| 4600 | if (field_type == Primitive::kPrimNot) { |
| 4601 | // Memory barriers, in the case of references, are also handled |
| 4602 | // in the previous switch statement. |
| 4603 | } else { |
| 4604 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4605 | } |
| 4606 | } |
| 4607 | } |
| 4608 | |
| 4609 | void LocationsBuilderARMVIXL::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 4610 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4611 | } |
| 4612 | |
| 4613 | void InstructionCodeGeneratorARMVIXL::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 4614 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
| 4615 | } |
| 4616 | |
| 4617 | void LocationsBuilderARMVIXL::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 4618 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4619 | } |
| 4620 | |
| 4621 | void InstructionCodeGeneratorARMVIXL::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 4622 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4623 | } |
| 4624 | |
| 4625 | void LocationsBuilderARMVIXL::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4626 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4627 | } |
| 4628 | |
| 4629 | void InstructionCodeGeneratorARMVIXL::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4630 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4631 | } |
| 4632 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 4633 | void LocationsBuilderARMVIXL::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 4634 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4635 | } |
| 4636 | |
| 4637 | void InstructionCodeGeneratorARMVIXL::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 4638 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
| 4639 | } |
| 4640 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 4641 | void LocationsBuilderARMVIXL::VisitUnresolvedInstanceFieldGet( |
| 4642 | HUnresolvedInstanceFieldGet* instruction) { |
| 4643 | FieldAccessCallingConventionARMVIXL calling_convention; |
| 4644 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4645 | instruction, instruction->GetFieldType(), calling_convention); |
| 4646 | } |
| 4647 | |
| 4648 | void InstructionCodeGeneratorARMVIXL::VisitUnresolvedInstanceFieldGet( |
| 4649 | HUnresolvedInstanceFieldGet* instruction) { |
| 4650 | FieldAccessCallingConventionARMVIXL calling_convention; |
| 4651 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4652 | instruction->GetFieldType(), |
| 4653 | instruction->GetFieldIndex(), |
| 4654 | instruction->GetDexPc(), |
| 4655 | calling_convention); |
| 4656 | } |
| 4657 | |
| 4658 | void LocationsBuilderARMVIXL::VisitUnresolvedInstanceFieldSet( |
| 4659 | HUnresolvedInstanceFieldSet* instruction) { |
| 4660 | FieldAccessCallingConventionARMVIXL calling_convention; |
| 4661 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4662 | instruction, instruction->GetFieldType(), calling_convention); |
| 4663 | } |
| 4664 | |
| 4665 | void InstructionCodeGeneratorARMVIXL::VisitUnresolvedInstanceFieldSet( |
| 4666 | HUnresolvedInstanceFieldSet* instruction) { |
| 4667 | FieldAccessCallingConventionARMVIXL calling_convention; |
| 4668 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4669 | instruction->GetFieldType(), |
| 4670 | instruction->GetFieldIndex(), |
| 4671 | instruction->GetDexPc(), |
| 4672 | calling_convention); |
| 4673 | } |
| 4674 | |
| 4675 | void LocationsBuilderARMVIXL::VisitUnresolvedStaticFieldGet( |
| 4676 | HUnresolvedStaticFieldGet* instruction) { |
| 4677 | FieldAccessCallingConventionARMVIXL calling_convention; |
| 4678 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4679 | instruction, instruction->GetFieldType(), calling_convention); |
| 4680 | } |
| 4681 | |
| 4682 | void InstructionCodeGeneratorARMVIXL::VisitUnresolvedStaticFieldGet( |
| 4683 | HUnresolvedStaticFieldGet* instruction) { |
| 4684 | FieldAccessCallingConventionARMVIXL calling_convention; |
| 4685 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4686 | instruction->GetFieldType(), |
| 4687 | instruction->GetFieldIndex(), |
| 4688 | instruction->GetDexPc(), |
| 4689 | calling_convention); |
| 4690 | } |
| 4691 | |
| 4692 | void LocationsBuilderARMVIXL::VisitUnresolvedStaticFieldSet( |
| 4693 | HUnresolvedStaticFieldSet* instruction) { |
| 4694 | FieldAccessCallingConventionARMVIXL calling_convention; |
| 4695 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4696 | instruction, instruction->GetFieldType(), calling_convention); |
| 4697 | } |
| 4698 | |
| 4699 | void InstructionCodeGeneratorARMVIXL::VisitUnresolvedStaticFieldSet( |
| 4700 | HUnresolvedStaticFieldSet* instruction) { |
| 4701 | FieldAccessCallingConventionARMVIXL calling_convention; |
| 4702 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4703 | instruction->GetFieldType(), |
| 4704 | instruction->GetFieldIndex(), |
| 4705 | instruction->GetDexPc(), |
| 4706 | calling_convention); |
| 4707 | } |
| 4708 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4709 | void LocationsBuilderARMVIXL::VisitNullCheck(HNullCheck* instruction) { |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 4710 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4711 | locations->SetInAt(0, Location::RequiresRegister()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4712 | } |
| 4713 | |
| 4714 | void CodeGeneratorARMVIXL::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 4715 | if (CanMoveNullCheckToUser(instruction)) { |
| 4716 | return; |
| 4717 | } |
| 4718 | |
| 4719 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 4720 | // Ensure the pc position is recorded immediately after the `ldr` instruction. |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 4721 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 4722 | vixl32::kMaxInstructionSizeInBytes, |
| 4723 | CodeBufferCheckScope::kMaximumSize); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4724 | __ ldr(temps.Acquire(), MemOperand(InputRegisterAt(instruction, 0))); |
| 4725 | RecordPcInfo(instruction, instruction->GetDexPc()); |
| 4726 | } |
| 4727 | |
| 4728 | void CodeGeneratorARMVIXL::GenerateExplicitNullCheck(HNullCheck* instruction) { |
| 4729 | NullCheckSlowPathARMVIXL* slow_path = |
| 4730 | new (GetGraph()->GetArena()) NullCheckSlowPathARMVIXL(instruction); |
| 4731 | AddSlowPath(slow_path); |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 4732 | __ CompareAndBranchIfZero(InputRegisterAt(instruction, 0), slow_path->GetEntryLabel()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4733 | } |
| 4734 | |
| 4735 | void InstructionCodeGeneratorARMVIXL::VisitNullCheck(HNullCheck* instruction) { |
| 4736 | codegen_->GenerateNullCheck(instruction); |
| 4737 | } |
| 4738 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 4739 | static LoadOperandType GetLoadOperandType(Primitive::Type type) { |
| 4740 | switch (type) { |
| 4741 | case Primitive::kPrimNot: |
| 4742 | return kLoadWord; |
| 4743 | case Primitive::kPrimBoolean: |
| 4744 | return kLoadUnsignedByte; |
| 4745 | case Primitive::kPrimByte: |
| 4746 | return kLoadSignedByte; |
| 4747 | case Primitive::kPrimChar: |
| 4748 | return kLoadUnsignedHalfword; |
| 4749 | case Primitive::kPrimShort: |
| 4750 | return kLoadSignedHalfword; |
| 4751 | case Primitive::kPrimInt: |
| 4752 | return kLoadWord; |
| 4753 | case Primitive::kPrimLong: |
| 4754 | return kLoadWordPair; |
| 4755 | case Primitive::kPrimFloat: |
| 4756 | return kLoadSWord; |
| 4757 | case Primitive::kPrimDouble: |
| 4758 | return kLoadDWord; |
| 4759 | default: |
| 4760 | LOG(FATAL) << "Unreachable type " << type; |
| 4761 | UNREACHABLE(); |
| 4762 | } |
| 4763 | } |
| 4764 | |
| 4765 | static StoreOperandType GetStoreOperandType(Primitive::Type type) { |
| 4766 | switch (type) { |
| 4767 | case Primitive::kPrimNot: |
| 4768 | return kStoreWord; |
| 4769 | case Primitive::kPrimBoolean: |
| 4770 | case Primitive::kPrimByte: |
| 4771 | return kStoreByte; |
| 4772 | case Primitive::kPrimChar: |
| 4773 | case Primitive::kPrimShort: |
| 4774 | return kStoreHalfword; |
| 4775 | case Primitive::kPrimInt: |
| 4776 | return kStoreWord; |
| 4777 | case Primitive::kPrimLong: |
| 4778 | return kStoreWordPair; |
| 4779 | case Primitive::kPrimFloat: |
| 4780 | return kStoreSWord; |
| 4781 | case Primitive::kPrimDouble: |
| 4782 | return kStoreDWord; |
| 4783 | default: |
| 4784 | LOG(FATAL) << "Unreachable type " << type; |
| 4785 | UNREACHABLE(); |
| 4786 | } |
| 4787 | } |
| 4788 | |
| 4789 | void CodeGeneratorARMVIXL::LoadFromShiftedRegOffset(Primitive::Type type, |
| 4790 | Location out_loc, |
| 4791 | vixl32::Register base, |
| 4792 | vixl32::Register reg_index, |
| 4793 | vixl32::Condition cond) { |
| 4794 | uint32_t shift_count = Primitive::ComponentSizeShift(type); |
| 4795 | MemOperand mem_address(base, reg_index, vixl32::LSL, shift_count); |
| 4796 | |
| 4797 | switch (type) { |
| 4798 | case Primitive::kPrimByte: |
| 4799 | __ Ldrsb(cond, RegisterFrom(out_loc), mem_address); |
| 4800 | break; |
| 4801 | case Primitive::kPrimBoolean: |
| 4802 | __ Ldrb(cond, RegisterFrom(out_loc), mem_address); |
| 4803 | break; |
| 4804 | case Primitive::kPrimShort: |
| 4805 | __ Ldrsh(cond, RegisterFrom(out_loc), mem_address); |
| 4806 | break; |
| 4807 | case Primitive::kPrimChar: |
| 4808 | __ Ldrh(cond, RegisterFrom(out_loc), mem_address); |
| 4809 | break; |
| 4810 | case Primitive::kPrimNot: |
| 4811 | case Primitive::kPrimInt: |
| 4812 | __ Ldr(cond, RegisterFrom(out_loc), mem_address); |
| 4813 | break; |
| 4814 | // T32 doesn't support LoadFromShiftedRegOffset mem address mode for these types. |
| 4815 | case Primitive::kPrimLong: |
| 4816 | case Primitive::kPrimFloat: |
| 4817 | case Primitive::kPrimDouble: |
| 4818 | default: |
| 4819 | LOG(FATAL) << "Unreachable type " << type; |
| 4820 | UNREACHABLE(); |
| 4821 | } |
| 4822 | } |
| 4823 | |
| 4824 | void CodeGeneratorARMVIXL::StoreToShiftedRegOffset(Primitive::Type type, |
| 4825 | Location loc, |
| 4826 | vixl32::Register base, |
| 4827 | vixl32::Register reg_index, |
| 4828 | vixl32::Condition cond) { |
| 4829 | uint32_t shift_count = Primitive::ComponentSizeShift(type); |
| 4830 | MemOperand mem_address(base, reg_index, vixl32::LSL, shift_count); |
| 4831 | |
| 4832 | switch (type) { |
| 4833 | case Primitive::kPrimByte: |
| 4834 | case Primitive::kPrimBoolean: |
| 4835 | __ Strb(cond, RegisterFrom(loc), mem_address); |
| 4836 | break; |
| 4837 | case Primitive::kPrimShort: |
| 4838 | case Primitive::kPrimChar: |
| 4839 | __ Strh(cond, RegisterFrom(loc), mem_address); |
| 4840 | break; |
| 4841 | case Primitive::kPrimNot: |
| 4842 | case Primitive::kPrimInt: |
| 4843 | __ Str(cond, RegisterFrom(loc), mem_address); |
| 4844 | break; |
| 4845 | // T32 doesn't support StoreToShiftedRegOffset mem address mode for these types. |
| 4846 | case Primitive::kPrimLong: |
| 4847 | case Primitive::kPrimFloat: |
| 4848 | case Primitive::kPrimDouble: |
| 4849 | default: |
| 4850 | LOG(FATAL) << "Unreachable type " << type; |
| 4851 | UNREACHABLE(); |
| 4852 | } |
| 4853 | } |
| 4854 | |
| 4855 | void LocationsBuilderARMVIXL::VisitArrayGet(HArrayGet* instruction) { |
| 4856 | bool object_array_get_with_read_barrier = |
| 4857 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
| 4858 | LocationSummary* locations = |
| 4859 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 4860 | object_array_get_with_read_barrier ? |
| 4861 | LocationSummary::kCallOnSlowPath : |
| 4862 | LocationSummary::kNoCall); |
| 4863 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 4864 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 4865 | } |
| 4866 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4867 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 4868 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 4869 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4870 | } else { |
| 4871 | // The output overlaps in the case of an object array get with |
| 4872 | // read barriers enabled: we do not want the move to overwrite the |
| 4873 | // array's location, as we need it to emit the read barrier. |
| 4874 | locations->SetOut( |
| 4875 | Location::RequiresRegister(), |
| 4876 | object_array_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
| 4877 | } |
| 4878 | // We need a temporary register for the read barrier marking slow |
| 4879 | // path in CodeGeneratorARM::GenerateArrayLoadWithBakerReadBarrier. |
| 4880 | // Also need for String compression feature. |
| 4881 | if ((object_array_get_with_read_barrier && kUseBakerReadBarrier) |
| 4882 | || (mirror::kUseStringCompression && instruction->IsStringCharAt())) { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 4883 | locations->AddTemp(Location::RequiresRegister()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 4884 | } |
| 4885 | } |
| 4886 | |
| 4887 | void InstructionCodeGeneratorARMVIXL::VisitArrayGet(HArrayGet* instruction) { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 4888 | LocationSummary* locations = instruction->GetLocations(); |
| 4889 | Location obj_loc = locations->InAt(0); |
| 4890 | vixl32::Register obj = InputRegisterAt(instruction, 0); |
| 4891 | Location index = locations->InAt(1); |
| 4892 | Location out_loc = locations->Out(); |
| 4893 | uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction); |
| 4894 | Primitive::Type type = instruction->GetType(); |
| 4895 | const bool maybe_compressed_char_at = mirror::kUseStringCompression && |
| 4896 | instruction->IsStringCharAt(); |
| 4897 | HInstruction* array_instr = instruction->GetArray(); |
| 4898 | bool has_intermediate_address = array_instr->IsIntermediateAddress(); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 4899 | |
| 4900 | switch (type) { |
| 4901 | case Primitive::kPrimBoolean: |
| 4902 | case Primitive::kPrimByte: |
| 4903 | case Primitive::kPrimShort: |
| 4904 | case Primitive::kPrimChar: |
| 4905 | case Primitive::kPrimInt: { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 4906 | vixl32::Register length; |
| 4907 | if (maybe_compressed_char_at) { |
| 4908 | length = RegisterFrom(locations->GetTemp(0)); |
| 4909 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| 4910 | GetAssembler()->LoadFromOffset(kLoadWord, length, obj, count_offset); |
| 4911 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4912 | } |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 4913 | if (index.IsConstant()) { |
| 4914 | int32_t const_index = index.GetConstant()->AsIntConstant()->GetValue(); |
| 4915 | if (maybe_compressed_char_at) { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 4916 | vixl32::Label uncompressed_load, done; |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 4917 | __ Lsrs(length, length, 1u); // LSRS has a 16-bit encoding, TST (immediate) does not. |
| 4918 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 4919 | "Expecting 0=compressed, 1=uncompressed"); |
| 4920 | __ B(cs, &uncompressed_load); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 4921 | GetAssembler()->LoadFromOffset(kLoadUnsignedByte, |
| 4922 | RegisterFrom(out_loc), |
| 4923 | obj, |
| 4924 | data_offset + const_index); |
| 4925 | __ B(&done); |
| 4926 | __ Bind(&uncompressed_load); |
| 4927 | GetAssembler()->LoadFromOffset(GetLoadOperandType(Primitive::kPrimChar), |
| 4928 | RegisterFrom(out_loc), |
| 4929 | obj, |
| 4930 | data_offset + (const_index << 1)); |
| 4931 | __ Bind(&done); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 4932 | } else { |
| 4933 | uint32_t full_offset = data_offset + (const_index << Primitive::ComponentSizeShift(type)); |
| 4934 | |
| 4935 | LoadOperandType load_type = GetLoadOperandType(type); |
| 4936 | GetAssembler()->LoadFromOffset(load_type, RegisterFrom(out_loc), obj, full_offset); |
| 4937 | } |
| 4938 | } else { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 4939 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 4940 | vixl32::Register temp = temps.Acquire(); |
| 4941 | |
| 4942 | if (has_intermediate_address) { |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 4943 | // We do not need to compute the intermediate address from the array: the |
| 4944 | // input instruction has done it already. See the comment in |
| 4945 | // `TryExtractArrayAccessAddress()`. |
| 4946 | if (kIsDebugBuild) { |
| 4947 | HIntermediateAddress* tmp = array_instr->AsIntermediateAddress(); |
| 4948 | DCHECK_EQ(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64(), data_offset); |
| 4949 | } |
| 4950 | temp = obj; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 4951 | } else { |
| 4952 | __ Add(temp, obj, data_offset); |
| 4953 | } |
| 4954 | if (maybe_compressed_char_at) { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 4955 | vixl32::Label uncompressed_load, done; |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 4956 | __ Lsrs(length, length, 1u); // LSRS has a 16-bit encoding, TST (immediate) does not. |
| 4957 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 4958 | "Expecting 0=compressed, 1=uncompressed"); |
| 4959 | __ B(cs, &uncompressed_load); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 4960 | __ Ldrb(RegisterFrom(out_loc), MemOperand(temp, RegisterFrom(index), vixl32::LSL, 0)); |
| 4961 | __ B(&done); |
| 4962 | __ Bind(&uncompressed_load); |
| 4963 | __ Ldrh(RegisterFrom(out_loc), MemOperand(temp, RegisterFrom(index), vixl32::LSL, 1)); |
| 4964 | __ Bind(&done); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 4965 | } else { |
| 4966 | codegen_->LoadFromShiftedRegOffset(type, out_loc, temp, RegisterFrom(index)); |
| 4967 | } |
| 4968 | } |
| 4969 | break; |
| 4970 | } |
| 4971 | |
| 4972 | case Primitive::kPrimNot: { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 4973 | // The read barrier instrumentation of object ArrayGet |
| 4974 | // instructions does not support the HIntermediateAddress |
| 4975 | // instruction. |
| 4976 | DCHECK(!(has_intermediate_address && kEmitCompilerReadBarrier)); |
| 4977 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 4978 | static_assert( |
| 4979 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 4980 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 4981 | // /* HeapReference<Object> */ out = |
| 4982 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 4983 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 4984 | Location temp = locations->GetTemp(0); |
| 4985 | // Note that a potential implicit null check is handled in this |
| 4986 | // CodeGeneratorARMVIXL::GenerateArrayLoadWithBakerReadBarrier call. |
| 4987 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
| 4988 | instruction, out_loc, obj, data_offset, index, temp, /* needs_null_check */ true); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 4989 | } else { |
| 4990 | vixl32::Register out = OutputRegister(instruction); |
| 4991 | if (index.IsConstant()) { |
| 4992 | size_t offset = |
| 4993 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 4994 | GetAssembler()->LoadFromOffset(kLoadWord, out, obj, offset); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 4995 | // TODO(VIXL): Here and for other calls to `MaybeRecordImplicitNullCheck` in this method, |
| 4996 | // we should use a scope and the assembler to emit the load instruction to guarantee that |
| 4997 | // we record the pc at the correct position. But the `Assembler` does not automatically |
| 4998 | // handle unencodable offsets. Practically, everything is fine because the helper and |
| 4999 | // VIXL, at the time of writing, do generate the store instruction last. |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5000 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5001 | // If read barriers are enabled, emit read barriers other than |
| 5002 | // Baker's using a slow path (and also unpoison the loaded |
| 5003 | // reference, if heap poisoning is enabled). |
| 5004 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 5005 | } else { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 5006 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5007 | vixl32::Register temp = temps.Acquire(); |
| 5008 | |
| 5009 | if (has_intermediate_address) { |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 5010 | // We do not need to compute the intermediate address from the array: the |
| 5011 | // input instruction has done it already. See the comment in |
| 5012 | // `TryExtractArrayAccessAddress()`. |
| 5013 | if (kIsDebugBuild) { |
| 5014 | HIntermediateAddress* tmp = array_instr->AsIntermediateAddress(); |
| 5015 | DCHECK_EQ(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64(), data_offset); |
| 5016 | } |
| 5017 | temp = obj; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5018 | } else { |
| 5019 | __ Add(temp, obj, data_offset); |
| 5020 | } |
| 5021 | codegen_->LoadFromShiftedRegOffset(type, out_loc, temp, RegisterFrom(index)); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 5022 | temps.Close(); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 5023 | // TODO(VIXL): Use a scope to ensure that we record the pc position immediately after the |
| 5024 | // load instruction. Practically, everything is fine because the helper and VIXL, at the |
| 5025 | // time of writing, do generate the store instruction last. |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5026 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5027 | // If read barriers are enabled, emit read barriers other than |
| 5028 | // Baker's using a slow path (and also unpoison the loaded |
| 5029 | // reference, if heap poisoning is enabled). |
| 5030 | codegen_->MaybeGenerateReadBarrierSlow( |
| 5031 | instruction, out_loc, out_loc, obj_loc, data_offset, index); |
| 5032 | } |
| 5033 | } |
| 5034 | break; |
| 5035 | } |
| 5036 | |
| 5037 | case Primitive::kPrimLong: { |
| 5038 | if (index.IsConstant()) { |
| 5039 | size_t offset = |
| 5040 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
| 5041 | GetAssembler()->LoadFromOffset(kLoadWordPair, LowRegisterFrom(out_loc), obj, offset); |
| 5042 | } else { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 5043 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5044 | vixl32::Register temp = temps.Acquire(); |
| 5045 | __ Add(temp, obj, Operand(RegisterFrom(index), vixl32::LSL, TIMES_8)); |
| 5046 | GetAssembler()->LoadFromOffset(kLoadWordPair, LowRegisterFrom(out_loc), temp, data_offset); |
| 5047 | } |
| 5048 | break; |
| 5049 | } |
| 5050 | |
| 5051 | case Primitive::kPrimFloat: { |
| 5052 | vixl32::SRegister out = SRegisterFrom(out_loc); |
| 5053 | if (index.IsConstant()) { |
| 5054 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 5055 | GetAssembler()->LoadSFromOffset(out, obj, offset); |
| 5056 | } else { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 5057 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5058 | vixl32::Register temp = temps.Acquire(); |
| 5059 | __ Add(temp, obj, Operand(RegisterFrom(index), vixl32::LSL, TIMES_4)); |
| 5060 | GetAssembler()->LoadSFromOffset(out, temp, data_offset); |
| 5061 | } |
| 5062 | break; |
| 5063 | } |
| 5064 | |
| 5065 | case Primitive::kPrimDouble: { |
| 5066 | if (index.IsConstant()) { |
| 5067 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
| 5068 | GetAssembler()->LoadDFromOffset(DRegisterFrom(out_loc), obj, offset); |
| 5069 | } else { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 5070 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5071 | vixl32::Register temp = temps.Acquire(); |
| 5072 | __ Add(temp, obj, Operand(RegisterFrom(index), vixl32::LSL, TIMES_8)); |
| 5073 | GetAssembler()->LoadDFromOffset(DRegisterFrom(out_loc), temp, data_offset); |
| 5074 | } |
| 5075 | break; |
| 5076 | } |
| 5077 | |
| 5078 | case Primitive::kPrimVoid: |
| 5079 | LOG(FATAL) << "Unreachable type " << type; |
| 5080 | UNREACHABLE(); |
| 5081 | } |
| 5082 | |
| 5083 | if (type == Primitive::kPrimNot) { |
| 5084 | // Potential implicit null checks, in the case of reference |
| 5085 | // arrays, are handled in the previous switch statement. |
| 5086 | } else if (!maybe_compressed_char_at) { |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 5087 | // TODO(VIXL): Use a scope to ensure we record the pc info immediately after |
| 5088 | // the preceding load instruction. |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5089 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5090 | } |
| 5091 | } |
| 5092 | |
| 5093 | void LocationsBuilderARMVIXL::VisitArraySet(HArraySet* instruction) { |
| 5094 | Primitive::Type value_type = instruction->GetComponentType(); |
| 5095 | |
| 5096 | bool needs_write_barrier = |
| 5097 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
| 5098 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
| 5099 | |
| 5100 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 5101 | instruction, |
| 5102 | may_need_runtime_call_for_type_check ? |
| 5103 | LocationSummary::kCallOnSlowPath : |
| 5104 | LocationSummary::kNoCall); |
| 5105 | |
| 5106 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5107 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 5108 | if (Primitive::IsFloatingPointType(value_type)) { |
| 5109 | locations->SetInAt(2, Location::RequiresFpuRegister()); |
| 5110 | } else { |
| 5111 | locations->SetInAt(2, Location::RequiresRegister()); |
| 5112 | } |
| 5113 | if (needs_write_barrier) { |
| 5114 | // Temporary registers for the write barrier. |
| 5115 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
| 5116 | locations->AddTemp(Location::RequiresRegister()); |
| 5117 | } |
| 5118 | } |
| 5119 | |
| 5120 | void InstructionCodeGeneratorARMVIXL::VisitArraySet(HArraySet* instruction) { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5121 | LocationSummary* locations = instruction->GetLocations(); |
| 5122 | vixl32::Register array = InputRegisterAt(instruction, 0); |
| 5123 | Location index = locations->InAt(1); |
| 5124 | Primitive::Type value_type = instruction->GetComponentType(); |
| 5125 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
| 5126 | bool needs_write_barrier = |
| 5127 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
| 5128 | uint32_t data_offset = |
| 5129 | mirror::Array::DataOffset(Primitive::ComponentSize(value_type)).Uint32Value(); |
| 5130 | Location value_loc = locations->InAt(2); |
| 5131 | HInstruction* array_instr = instruction->GetArray(); |
| 5132 | bool has_intermediate_address = array_instr->IsIntermediateAddress(); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5133 | |
| 5134 | switch (value_type) { |
| 5135 | case Primitive::kPrimBoolean: |
| 5136 | case Primitive::kPrimByte: |
| 5137 | case Primitive::kPrimShort: |
| 5138 | case Primitive::kPrimChar: |
| 5139 | case Primitive::kPrimInt: { |
| 5140 | if (index.IsConstant()) { |
| 5141 | int32_t const_index = index.GetConstant()->AsIntConstant()->GetValue(); |
| 5142 | uint32_t full_offset = |
| 5143 | data_offset + (const_index << Primitive::ComponentSizeShift(value_type)); |
| 5144 | StoreOperandType store_type = GetStoreOperandType(value_type); |
| 5145 | GetAssembler()->StoreToOffset(store_type, RegisterFrom(value_loc), array, full_offset); |
| 5146 | } else { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 5147 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5148 | vixl32::Register temp = temps.Acquire(); |
| 5149 | |
| 5150 | if (has_intermediate_address) { |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 5151 | // We do not need to compute the intermediate address from the array: the |
| 5152 | // input instruction has done it already. See the comment in |
| 5153 | // `TryExtractArrayAccessAddress()`. |
| 5154 | if (kIsDebugBuild) { |
| 5155 | HIntermediateAddress* tmp = array_instr->AsIntermediateAddress(); |
| 5156 | DCHECK(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64() == data_offset); |
| 5157 | } |
| 5158 | temp = array; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5159 | } else { |
| 5160 | __ Add(temp, array, data_offset); |
| 5161 | } |
| 5162 | codegen_->StoreToShiftedRegOffset(value_type, value_loc, temp, RegisterFrom(index)); |
| 5163 | } |
| 5164 | break; |
| 5165 | } |
| 5166 | |
| 5167 | case Primitive::kPrimNot: { |
| 5168 | vixl32::Register value = RegisterFrom(value_loc); |
| 5169 | // TryExtractArrayAccessAddress optimization is never applied for non-primitive ArraySet. |
| 5170 | // See the comment in instruction_simplifier_shared.cc. |
| 5171 | DCHECK(!has_intermediate_address); |
| 5172 | |
| 5173 | if (instruction->InputAt(2)->IsNullConstant()) { |
| 5174 | // Just setting null. |
| 5175 | if (index.IsConstant()) { |
| 5176 | size_t offset = |
| 5177 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 5178 | GetAssembler()->StoreToOffset(kStoreWord, value, array, offset); |
| 5179 | } else { |
| 5180 | DCHECK(index.IsRegister()) << index; |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 5181 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5182 | vixl32::Register temp = temps.Acquire(); |
| 5183 | __ Add(temp, array, data_offset); |
| 5184 | codegen_->StoreToShiftedRegOffset(value_type, value_loc, temp, RegisterFrom(index)); |
| 5185 | } |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 5186 | // TODO(VIXL): Use a scope to ensure we record the pc info immediately after the preceding |
| 5187 | // store instruction. |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5188 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5189 | DCHECK(!needs_write_barrier); |
| 5190 | DCHECK(!may_need_runtime_call_for_type_check); |
| 5191 | break; |
| 5192 | } |
| 5193 | |
| 5194 | DCHECK(needs_write_barrier); |
| 5195 | Location temp1_loc = locations->GetTemp(0); |
| 5196 | vixl32::Register temp1 = RegisterFrom(temp1_loc); |
| 5197 | Location temp2_loc = locations->GetTemp(1); |
| 5198 | vixl32::Register temp2 = RegisterFrom(temp2_loc); |
| 5199 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 5200 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5201 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 5202 | vixl32::Label done; |
| 5203 | SlowPathCodeARMVIXL* slow_path = nullptr; |
| 5204 | |
| 5205 | if (may_need_runtime_call_for_type_check) { |
| 5206 | slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathARMVIXL(instruction); |
| 5207 | codegen_->AddSlowPath(slow_path); |
| 5208 | if (instruction->GetValueCanBeNull()) { |
| 5209 | vixl32::Label non_zero; |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 5210 | __ CompareAndBranchIfNonZero(value, &non_zero); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5211 | if (index.IsConstant()) { |
| 5212 | size_t offset = |
| 5213 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 5214 | GetAssembler()->StoreToOffset(kStoreWord, value, array, offset); |
| 5215 | } else { |
| 5216 | DCHECK(index.IsRegister()) << index; |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 5217 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5218 | vixl32::Register temp = temps.Acquire(); |
| 5219 | __ Add(temp, array, data_offset); |
| 5220 | codegen_->StoreToShiftedRegOffset(value_type, value_loc, temp, RegisterFrom(index)); |
| 5221 | } |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 5222 | // TODO(VIXL): Use a scope to ensure we record the pc info immediately after the preceding |
| 5223 | // store instruction. |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5224 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5225 | __ B(&done); |
| 5226 | __ Bind(&non_zero); |
| 5227 | } |
| 5228 | |
| 5229 | // Note that when read barriers are enabled, the type checks |
| 5230 | // are performed without read barriers. This is fine, even in |
| 5231 | // the case where a class object is in the from-space after |
| 5232 | // the flip, as a comparison involving such a type would not |
| 5233 | // produce a false positive; it may of course produce a false |
| 5234 | // negative, in which case we would take the ArraySet slow |
| 5235 | // path. |
| 5236 | |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 5237 | { |
| 5238 | // Ensure we record the pc position immediately after the `ldr` instruction. |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 5239 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 5240 | vixl32::kMaxInstructionSizeInBytes, |
| 5241 | CodeBufferCheckScope::kMaximumSize); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 5242 | // /* HeapReference<Class> */ temp1 = array->klass_ |
| 5243 | __ ldr(temp1, MemOperand(array, class_offset)); |
| 5244 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5245 | } |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5246 | GetAssembler()->MaybeUnpoisonHeapReference(temp1); |
| 5247 | |
| 5248 | // /* HeapReference<Class> */ temp1 = temp1->component_type_ |
| 5249 | GetAssembler()->LoadFromOffset(kLoadWord, temp1, temp1, component_offset); |
| 5250 | // /* HeapReference<Class> */ temp2 = value->klass_ |
| 5251 | GetAssembler()->LoadFromOffset(kLoadWord, temp2, value, class_offset); |
| 5252 | // If heap poisoning is enabled, no need to unpoison `temp1` |
| 5253 | // nor `temp2`, as we are comparing two poisoned references. |
| 5254 | __ Cmp(temp1, temp2); |
| 5255 | |
| 5256 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 5257 | vixl32::Label do_put; |
| 5258 | __ B(eq, &do_put); |
| 5259 | // If heap poisoning is enabled, the `temp1` reference has |
| 5260 | // not been unpoisoned yet; unpoison it now. |
| 5261 | GetAssembler()->MaybeUnpoisonHeapReference(temp1); |
| 5262 | |
| 5263 | // /* HeapReference<Class> */ temp1 = temp1->super_class_ |
| 5264 | GetAssembler()->LoadFromOffset(kLoadWord, temp1, temp1, super_offset); |
| 5265 | // If heap poisoning is enabled, no need to unpoison |
| 5266 | // `temp1`, as we are comparing against null below. |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 5267 | __ CompareAndBranchIfNonZero(temp1, slow_path->GetEntryLabel()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5268 | __ Bind(&do_put); |
| 5269 | } else { |
| 5270 | __ B(ne, slow_path->GetEntryLabel()); |
| 5271 | } |
| 5272 | } |
| 5273 | |
| 5274 | vixl32::Register source = value; |
| 5275 | if (kPoisonHeapReferences) { |
| 5276 | // Note that in the case where `value` is a null reference, |
| 5277 | // we do not enter this block, as a null reference does not |
| 5278 | // need poisoning. |
| 5279 | DCHECK_EQ(value_type, Primitive::kPrimNot); |
| 5280 | __ Mov(temp1, value); |
| 5281 | GetAssembler()->PoisonHeapReference(temp1); |
| 5282 | source = temp1; |
| 5283 | } |
| 5284 | |
| 5285 | if (index.IsConstant()) { |
| 5286 | size_t offset = |
| 5287 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 5288 | GetAssembler()->StoreToOffset(kStoreWord, source, array, offset); |
| 5289 | } else { |
| 5290 | DCHECK(index.IsRegister()) << index; |
| 5291 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 5292 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5293 | vixl32::Register temp = temps.Acquire(); |
| 5294 | __ Add(temp, array, data_offset); |
| 5295 | codegen_->StoreToShiftedRegOffset(value_type, |
| 5296 | LocationFrom(source), |
| 5297 | temp, |
| 5298 | RegisterFrom(index)); |
| 5299 | } |
| 5300 | |
| 5301 | if (!may_need_runtime_call_for_type_check) { |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 5302 | // TODO(VIXL): Ensure we record the pc position immediately after the preceding store |
| 5303 | // instruction. |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5304 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5305 | } |
| 5306 | |
| 5307 | codegen_->MarkGCCard(temp1, temp2, array, value, instruction->GetValueCanBeNull()); |
| 5308 | |
| 5309 | if (done.IsReferenced()) { |
| 5310 | __ Bind(&done); |
| 5311 | } |
| 5312 | |
| 5313 | if (slow_path != nullptr) { |
| 5314 | __ Bind(slow_path->GetExitLabel()); |
| 5315 | } |
| 5316 | |
| 5317 | break; |
| 5318 | } |
| 5319 | |
| 5320 | case Primitive::kPrimLong: { |
| 5321 | Location value = locations->InAt(2); |
| 5322 | if (index.IsConstant()) { |
| 5323 | size_t offset = |
| 5324 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
| 5325 | GetAssembler()->StoreToOffset(kStoreWordPair, LowRegisterFrom(value), array, offset); |
| 5326 | } else { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 5327 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5328 | vixl32::Register temp = temps.Acquire(); |
| 5329 | __ Add(temp, array, Operand(RegisterFrom(index), vixl32::LSL, TIMES_8)); |
| 5330 | GetAssembler()->StoreToOffset(kStoreWordPair, LowRegisterFrom(value), temp, data_offset); |
| 5331 | } |
| 5332 | break; |
| 5333 | } |
| 5334 | |
| 5335 | case Primitive::kPrimFloat: { |
| 5336 | Location value = locations->InAt(2); |
| 5337 | DCHECK(value.IsFpuRegister()); |
| 5338 | if (index.IsConstant()) { |
| 5339 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 5340 | GetAssembler()->StoreSToOffset(SRegisterFrom(value), array, offset); |
| 5341 | } else { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 5342 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5343 | vixl32::Register temp = temps.Acquire(); |
| 5344 | __ Add(temp, array, Operand(RegisterFrom(index), vixl32::LSL, TIMES_4)); |
| 5345 | GetAssembler()->StoreSToOffset(SRegisterFrom(value), temp, data_offset); |
| 5346 | } |
| 5347 | break; |
| 5348 | } |
| 5349 | |
| 5350 | case Primitive::kPrimDouble: { |
| 5351 | Location value = locations->InAt(2); |
| 5352 | DCHECK(value.IsFpuRegisterPair()); |
| 5353 | if (index.IsConstant()) { |
| 5354 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
| 5355 | GetAssembler()->StoreDToOffset(DRegisterFrom(value), array, offset); |
| 5356 | } else { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 5357 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5358 | vixl32::Register temp = temps.Acquire(); |
| 5359 | __ Add(temp, array, Operand(RegisterFrom(index), vixl32::LSL, TIMES_8)); |
| 5360 | GetAssembler()->StoreDToOffset(DRegisterFrom(value), temp, data_offset); |
| 5361 | } |
| 5362 | break; |
| 5363 | } |
| 5364 | |
| 5365 | case Primitive::kPrimVoid: |
| 5366 | LOG(FATAL) << "Unreachable type " << value_type; |
| 5367 | UNREACHABLE(); |
| 5368 | } |
| 5369 | |
| 5370 | // Objects are handled in the switch. |
| 5371 | if (value_type != Primitive::kPrimNot) { |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 5372 | // TODO(VIXL): Ensure we record the pc position immediately after the preceding store |
| 5373 | // instruction. |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5374 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5375 | } |
| 5376 | } |
| 5377 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5378 | void LocationsBuilderARMVIXL::VisitArrayLength(HArrayLength* instruction) { |
| 5379 | LocationSummary* locations = |
| 5380 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 5381 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5382 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5383 | } |
| 5384 | |
| 5385 | void InstructionCodeGeneratorARMVIXL::VisitArrayLength(HArrayLength* instruction) { |
| 5386 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
| 5387 | vixl32::Register obj = InputRegisterAt(instruction, 0); |
| 5388 | vixl32::Register out = OutputRegister(instruction); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 5389 | { |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 5390 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 5391 | vixl32::kMaxInstructionSizeInBytes, |
| 5392 | CodeBufferCheckScope::kMaximumSize); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 5393 | __ ldr(out, MemOperand(obj, offset)); |
| 5394 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5395 | } |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 5396 | // Mask out compression flag from String's array length. |
| 5397 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5398 | __ Lsr(out, out, 1u); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 5399 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5400 | } |
| 5401 | |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 5402 | void LocationsBuilderARMVIXL::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 5403 | LocationSummary* locations = |
| 5404 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 5405 | |
| 5406 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5407 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->GetOffset())); |
| 5408 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5409 | } |
| 5410 | |
| 5411 | void InstructionCodeGeneratorARMVIXL::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
| 5412 | vixl32::Register out = OutputRegister(instruction); |
| 5413 | vixl32::Register first = InputRegisterAt(instruction, 0); |
| 5414 | Location second = instruction->GetLocations()->InAt(1); |
| 5415 | |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 5416 | if (second.IsRegister()) { |
| 5417 | __ Add(out, first, RegisterFrom(second)); |
| 5418 | } else { |
| 5419 | __ Add(out, first, second.GetConstant()->AsIntConstant()->GetValue()); |
| 5420 | } |
| 5421 | } |
| 5422 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5423 | void LocationsBuilderARMVIXL::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 5424 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 5425 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 5426 | caller_saves.Add(LocationFrom(calling_convention.GetRegisterAt(0))); |
| 5427 | caller_saves.Add(LocationFrom(calling_convention.GetRegisterAt(1))); |
| 5428 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
| 5429 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5430 | locations->SetInAt(1, Location::RequiresRegister()); |
| 5431 | } |
| 5432 | |
| 5433 | void InstructionCodeGeneratorARMVIXL::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 5434 | SlowPathCodeARMVIXL* slow_path = |
| 5435 | new (GetGraph()->GetArena()) BoundsCheckSlowPathARMVIXL(instruction); |
| 5436 | codegen_->AddSlowPath(slow_path); |
| 5437 | |
| 5438 | vixl32::Register index = InputRegisterAt(instruction, 0); |
| 5439 | vixl32::Register length = InputRegisterAt(instruction, 1); |
| 5440 | |
| 5441 | __ Cmp(index, length); |
| 5442 | __ B(hs, slow_path->GetEntryLabel()); |
| 5443 | } |
| 5444 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5445 | void CodeGeneratorARMVIXL::MarkGCCard(vixl32::Register temp, |
| 5446 | vixl32::Register card, |
| 5447 | vixl32::Register object, |
| 5448 | vixl32::Register value, |
| 5449 | bool can_be_null) { |
| 5450 | vixl32::Label is_null; |
| 5451 | if (can_be_null) { |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 5452 | __ CompareAndBranchIfZero(value, &is_null); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5453 | } |
| 5454 | GetAssembler()->LoadFromOffset( |
| 5455 | kLoadWord, card, tr, Thread::CardTableOffset<kArmPointerSize>().Int32Value()); |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 5456 | __ Lsr(temp, object, Operand::From(gc::accounting::CardTable::kCardShift)); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5457 | __ Strb(card, MemOperand(card, temp)); |
| 5458 | if (can_be_null) { |
| 5459 | __ Bind(&is_null); |
| 5460 | } |
| 5461 | } |
| 5462 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 5463 | void LocationsBuilderARMVIXL::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
| 5464 | LOG(FATAL) << "Unreachable"; |
| 5465 | } |
| 5466 | |
| 5467 | void InstructionCodeGeneratorARMVIXL::VisitParallelMove(HParallelMove* instruction) { |
| 5468 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 5469 | } |
| 5470 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5471 | void LocationsBuilderARMVIXL::VisitSuspendCheck(HSuspendCheck* instruction) { |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 5472 | LocationSummary* locations = |
| 5473 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
| 5474 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5475 | } |
| 5476 | |
| 5477 | void InstructionCodeGeneratorARMVIXL::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 5478 | HBasicBlock* block = instruction->GetBlock(); |
| 5479 | if (block->GetLoopInformation() != nullptr) { |
| 5480 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 5481 | // The back edge will generate the suspend check. |
| 5482 | return; |
| 5483 | } |
| 5484 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 5485 | // The goto will generate the suspend check. |
| 5486 | return; |
| 5487 | } |
| 5488 | GenerateSuspendCheck(instruction, nullptr); |
| 5489 | } |
| 5490 | |
| 5491 | void InstructionCodeGeneratorARMVIXL::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 5492 | HBasicBlock* successor) { |
| 5493 | SuspendCheckSlowPathARMVIXL* slow_path = |
| 5494 | down_cast<SuspendCheckSlowPathARMVIXL*>(instruction->GetSlowPath()); |
| 5495 | if (slow_path == nullptr) { |
| 5496 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathARMVIXL(instruction, successor); |
| 5497 | instruction->SetSlowPath(slow_path); |
| 5498 | codegen_->AddSlowPath(slow_path); |
| 5499 | if (successor != nullptr) { |
| 5500 | DCHECK(successor->IsLoopHeader()); |
| 5501 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 5502 | } |
| 5503 | } else { |
| 5504 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 5505 | } |
| 5506 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 5507 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5508 | vixl32::Register temp = temps.Acquire(); |
| 5509 | GetAssembler()->LoadFromOffset( |
| 5510 | kLoadUnsignedHalfword, temp, tr, Thread::ThreadFlagsOffset<kArmPointerSize>().Int32Value()); |
| 5511 | if (successor == nullptr) { |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 5512 | __ CompareAndBranchIfNonZero(temp, slow_path->GetEntryLabel()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5513 | __ Bind(slow_path->GetReturnLabel()); |
| 5514 | } else { |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 5515 | __ CompareAndBranchIfZero(temp, codegen_->GetLabelOf(successor)); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5516 | __ B(slow_path->GetEntryLabel()); |
| 5517 | } |
| 5518 | } |
| 5519 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 5520 | ArmVIXLAssembler* ParallelMoveResolverARMVIXL::GetAssembler() const { |
| 5521 | return codegen_->GetAssembler(); |
| 5522 | } |
| 5523 | |
| 5524 | void ParallelMoveResolverARMVIXL::EmitMove(size_t index) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5525 | UseScratchRegisterScope temps(GetAssembler()->GetVIXLAssembler()); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 5526 | MoveOperands* move = moves_[index]; |
| 5527 | Location source = move->GetSource(); |
| 5528 | Location destination = move->GetDestination(); |
| 5529 | |
| 5530 | if (source.IsRegister()) { |
| 5531 | if (destination.IsRegister()) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5532 | __ Mov(RegisterFrom(destination), RegisterFrom(source)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 5533 | } else if (destination.IsFpuRegister()) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5534 | __ Vmov(SRegisterFrom(destination), RegisterFrom(source)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 5535 | } else { |
| 5536 | DCHECK(destination.IsStackSlot()); |
| 5537 | GetAssembler()->StoreToOffset(kStoreWord, |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5538 | RegisterFrom(source), |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 5539 | sp, |
| 5540 | destination.GetStackIndex()); |
| 5541 | } |
| 5542 | } else if (source.IsStackSlot()) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5543 | if (destination.IsRegister()) { |
| 5544 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 5545 | RegisterFrom(destination), |
| 5546 | sp, |
| 5547 | source.GetStackIndex()); |
| 5548 | } else if (destination.IsFpuRegister()) { |
| 5549 | GetAssembler()->LoadSFromOffset(SRegisterFrom(destination), sp, source.GetStackIndex()); |
| 5550 | } else { |
| 5551 | DCHECK(destination.IsStackSlot()); |
| 5552 | vixl32::Register temp = temps.Acquire(); |
| 5553 | GetAssembler()->LoadFromOffset(kLoadWord, temp, sp, source.GetStackIndex()); |
| 5554 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, destination.GetStackIndex()); |
| 5555 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 5556 | } else if (source.IsFpuRegister()) { |
Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 5557 | if (destination.IsRegister()) { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5558 | __ Vmov(RegisterFrom(destination), SRegisterFrom(source)); |
Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 5559 | } else if (destination.IsFpuRegister()) { |
| 5560 | __ Vmov(SRegisterFrom(destination), SRegisterFrom(source)); |
| 5561 | } else { |
| 5562 | DCHECK(destination.IsStackSlot()); |
| 5563 | GetAssembler()->StoreSToOffset(SRegisterFrom(source), sp, destination.GetStackIndex()); |
| 5564 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 5565 | } else if (source.IsDoubleStackSlot()) { |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 5566 | if (destination.IsDoubleStackSlot()) { |
| 5567 | vixl32::DRegister temp = temps.AcquireD(); |
| 5568 | GetAssembler()->LoadDFromOffset(temp, sp, source.GetStackIndex()); |
| 5569 | GetAssembler()->StoreDToOffset(temp, sp, destination.GetStackIndex()); |
| 5570 | } else if (destination.IsRegisterPair()) { |
| 5571 | DCHECK(ExpectedPairLayout(destination)); |
| 5572 | GetAssembler()->LoadFromOffset( |
| 5573 | kLoadWordPair, LowRegisterFrom(destination), sp, source.GetStackIndex()); |
| 5574 | } else { |
Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 5575 | DCHECK(destination.IsFpuRegisterPair()) << destination; |
| 5576 | GetAssembler()->LoadDFromOffset(DRegisterFrom(destination), sp, source.GetStackIndex()); |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 5577 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 5578 | } else if (source.IsRegisterPair()) { |
| 5579 | if (destination.IsRegisterPair()) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5580 | __ Mov(LowRegisterFrom(destination), LowRegisterFrom(source)); |
| 5581 | __ Mov(HighRegisterFrom(destination), HighRegisterFrom(source)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 5582 | } else if (destination.IsFpuRegisterPair()) { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5583 | __ Vmov(DRegisterFrom(destination), LowRegisterFrom(source), HighRegisterFrom(source)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 5584 | } else { |
| 5585 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 5586 | DCHECK(ExpectedPairLayout(source)); |
| 5587 | GetAssembler()->StoreToOffset(kStoreWordPair, |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5588 | LowRegisterFrom(source), |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 5589 | sp, |
| 5590 | destination.GetStackIndex()); |
| 5591 | } |
| 5592 | } else if (source.IsFpuRegisterPair()) { |
Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 5593 | if (destination.IsRegisterPair()) { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5594 | __ Vmov(LowRegisterFrom(destination), HighRegisterFrom(destination), DRegisterFrom(source)); |
Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 5595 | } else if (destination.IsFpuRegisterPair()) { |
| 5596 | __ Vmov(DRegisterFrom(destination), DRegisterFrom(source)); |
| 5597 | } else { |
| 5598 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 5599 | GetAssembler()->StoreDToOffset(DRegisterFrom(source), sp, destination.GetStackIndex()); |
| 5600 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 5601 | } else { |
| 5602 | DCHECK(source.IsConstant()) << source; |
| 5603 | HConstant* constant = source.GetConstant(); |
| 5604 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
| 5605 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
| 5606 | if (destination.IsRegister()) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5607 | __ Mov(RegisterFrom(destination), value); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 5608 | } else { |
| 5609 | DCHECK(destination.IsStackSlot()); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 5610 | vixl32::Register temp = temps.Acquire(); |
| 5611 | __ Mov(temp, value); |
| 5612 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, destination.GetStackIndex()); |
| 5613 | } |
| 5614 | } else if (constant->IsLongConstant()) { |
| 5615 | int64_t value = constant->AsLongConstant()->GetValue(); |
| 5616 | if (destination.IsRegisterPair()) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5617 | __ Mov(LowRegisterFrom(destination), Low32Bits(value)); |
| 5618 | __ Mov(HighRegisterFrom(destination), High32Bits(value)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 5619 | } else { |
| 5620 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 5621 | vixl32::Register temp = temps.Acquire(); |
| 5622 | __ Mov(temp, Low32Bits(value)); |
| 5623 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, destination.GetStackIndex()); |
| 5624 | __ Mov(temp, High32Bits(value)); |
| 5625 | GetAssembler()->StoreToOffset(kStoreWord, |
| 5626 | temp, |
| 5627 | sp, |
| 5628 | destination.GetHighStackIndex(kArmWordSize)); |
| 5629 | } |
| 5630 | } else if (constant->IsDoubleConstant()) { |
| 5631 | double value = constant->AsDoubleConstant()->GetValue(); |
| 5632 | if (destination.IsFpuRegisterPair()) { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5633 | __ Vmov(DRegisterFrom(destination), value); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 5634 | } else { |
| 5635 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 5636 | uint64_t int_value = bit_cast<uint64_t, double>(value); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 5637 | vixl32::Register temp = temps.Acquire(); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5638 | __ Mov(temp, Low32Bits(int_value)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 5639 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, destination.GetStackIndex()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5640 | __ Mov(temp, High32Bits(int_value)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 5641 | GetAssembler()->StoreToOffset(kStoreWord, |
| 5642 | temp, |
| 5643 | sp, |
| 5644 | destination.GetHighStackIndex(kArmWordSize)); |
| 5645 | } |
| 5646 | } else { |
| 5647 | DCHECK(constant->IsFloatConstant()) << constant->DebugName(); |
| 5648 | float value = constant->AsFloatConstant()->GetValue(); |
| 5649 | if (destination.IsFpuRegister()) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5650 | __ Vmov(SRegisterFrom(destination), value); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 5651 | } else { |
| 5652 | DCHECK(destination.IsStackSlot()); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 5653 | vixl32::Register temp = temps.Acquire(); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5654 | __ Mov(temp, bit_cast<int32_t, float>(value)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 5655 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, destination.GetStackIndex()); |
| 5656 | } |
| 5657 | } |
| 5658 | } |
| 5659 | } |
| 5660 | |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 5661 | void ParallelMoveResolverARMVIXL::Exchange(vixl32::Register reg, int mem) { |
| 5662 | UseScratchRegisterScope temps(GetAssembler()->GetVIXLAssembler()); |
| 5663 | vixl32::Register temp = temps.Acquire(); |
| 5664 | __ Mov(temp, reg); |
| 5665 | GetAssembler()->LoadFromOffset(kLoadWord, reg, sp, mem); |
| 5666 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, mem); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 5667 | } |
| 5668 | |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 5669 | void ParallelMoveResolverARMVIXL::Exchange(int mem1, int mem2) { |
| 5670 | // TODO(VIXL32): Double check the performance of this implementation. |
| 5671 | UseScratchRegisterScope temps(GetAssembler()->GetVIXLAssembler()); |
| 5672 | vixl32::Register temp = temps.Acquire(); |
| 5673 | vixl32::SRegister temp_s = temps.AcquireS(); |
| 5674 | |
| 5675 | __ Ldr(temp, MemOperand(sp, mem1)); |
| 5676 | __ Vldr(temp_s, MemOperand(sp, mem2)); |
| 5677 | __ Str(temp, MemOperand(sp, mem2)); |
| 5678 | __ Vstr(temp_s, MemOperand(sp, mem1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 5679 | } |
| 5680 | |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 5681 | void ParallelMoveResolverARMVIXL::EmitSwap(size_t index) { |
| 5682 | MoveOperands* move = moves_[index]; |
| 5683 | Location source = move->GetSource(); |
| 5684 | Location destination = move->GetDestination(); |
| 5685 | UseScratchRegisterScope temps(GetAssembler()->GetVIXLAssembler()); |
| 5686 | |
| 5687 | if (source.IsRegister() && destination.IsRegister()) { |
| 5688 | vixl32::Register temp = temps.Acquire(); |
| 5689 | DCHECK(!RegisterFrom(source).Is(temp)); |
| 5690 | DCHECK(!RegisterFrom(destination).Is(temp)); |
| 5691 | __ Mov(temp, RegisterFrom(destination)); |
| 5692 | __ Mov(RegisterFrom(destination), RegisterFrom(source)); |
| 5693 | __ Mov(RegisterFrom(source), temp); |
| 5694 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
| 5695 | Exchange(RegisterFrom(source), destination.GetStackIndex()); |
| 5696 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
| 5697 | Exchange(RegisterFrom(destination), source.GetStackIndex()); |
| 5698 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 5699 | Exchange(source.GetStackIndex(), destination.GetStackIndex()); |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 5700 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 5701 | vixl32::SRegister temp = temps.AcquireS(); |
| 5702 | __ Vmov(temp, SRegisterFrom(source)); |
| 5703 | __ Vmov(SRegisterFrom(source), SRegisterFrom(destination)); |
| 5704 | __ Vmov(SRegisterFrom(destination), temp); |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 5705 | } else if (source.IsRegisterPair() && destination.IsRegisterPair()) { |
| 5706 | vixl32::DRegister temp = temps.AcquireD(); |
| 5707 | __ Vmov(temp, LowRegisterFrom(source), HighRegisterFrom(source)); |
| 5708 | __ Mov(LowRegisterFrom(source), LowRegisterFrom(destination)); |
| 5709 | __ Mov(HighRegisterFrom(source), HighRegisterFrom(destination)); |
| 5710 | __ Vmov(LowRegisterFrom(destination), HighRegisterFrom(destination), temp); |
| 5711 | } else if (source.IsRegisterPair() || destination.IsRegisterPair()) { |
| 5712 | vixl32::Register low_reg = LowRegisterFrom(source.IsRegisterPair() ? source : destination); |
| 5713 | int mem = source.IsRegisterPair() ? destination.GetStackIndex() : source.GetStackIndex(); |
| 5714 | DCHECK(ExpectedPairLayout(source.IsRegisterPair() ? source : destination)); |
| 5715 | vixl32::DRegister temp = temps.AcquireD(); |
| 5716 | __ Vmov(temp, low_reg, vixl32::Register(low_reg.GetCode() + 1)); |
| 5717 | GetAssembler()->LoadFromOffset(kLoadWordPair, low_reg, sp, mem); |
| 5718 | GetAssembler()->StoreDToOffset(temp, sp, mem); |
| 5719 | } else if (source.IsFpuRegisterPair() && destination.IsFpuRegisterPair()) { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 5720 | vixl32::DRegister first = DRegisterFrom(source); |
| 5721 | vixl32::DRegister second = DRegisterFrom(destination); |
| 5722 | vixl32::DRegister temp = temps.AcquireD(); |
| 5723 | __ Vmov(temp, first); |
| 5724 | __ Vmov(first, second); |
| 5725 | __ Vmov(second, temp); |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 5726 | } else if (source.IsFpuRegisterPair() || destination.IsFpuRegisterPair()) { |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 5727 | vixl32::DRegister reg = source.IsFpuRegisterPair() |
| 5728 | ? DRegisterFrom(source) |
| 5729 | : DRegisterFrom(destination); |
| 5730 | int mem = source.IsFpuRegisterPair() |
| 5731 | ? destination.GetStackIndex() |
| 5732 | : source.GetStackIndex(); |
| 5733 | vixl32::DRegister temp = temps.AcquireD(); |
| 5734 | __ Vmov(temp, reg); |
| 5735 | GetAssembler()->LoadDFromOffset(reg, sp, mem); |
| 5736 | GetAssembler()->StoreDToOffset(temp, sp, mem); |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 5737 | } else if (source.IsFpuRegister() || destination.IsFpuRegister()) { |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 5738 | vixl32::SRegister reg = source.IsFpuRegister() |
| 5739 | ? SRegisterFrom(source) |
| 5740 | : SRegisterFrom(destination); |
| 5741 | int mem = source.IsFpuRegister() |
| 5742 | ? destination.GetStackIndex() |
| 5743 | : source.GetStackIndex(); |
| 5744 | vixl32::Register temp = temps.Acquire(); |
| 5745 | __ Vmov(temp, reg); |
| 5746 | GetAssembler()->LoadSFromOffset(reg, sp, mem); |
| 5747 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, mem); |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 5748 | } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) { |
| 5749 | vixl32::DRegister temp1 = temps.AcquireD(); |
| 5750 | vixl32::DRegister temp2 = temps.AcquireD(); |
| 5751 | __ Vldr(temp1, MemOperand(sp, source.GetStackIndex())); |
| 5752 | __ Vldr(temp2, MemOperand(sp, destination.GetStackIndex())); |
| 5753 | __ Vstr(temp1, MemOperand(sp, destination.GetStackIndex())); |
| 5754 | __ Vstr(temp2, MemOperand(sp, source.GetStackIndex())); |
| 5755 | } else { |
| 5756 | LOG(FATAL) << "Unimplemented" << source << " <-> " << destination; |
| 5757 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 5758 | } |
| 5759 | |
| 5760 | void ParallelMoveResolverARMVIXL::SpillScratch(int reg ATTRIBUTE_UNUSED) { |
| 5761 | TODO_VIXL32(FATAL); |
| 5762 | } |
| 5763 | |
| 5764 | void ParallelMoveResolverARMVIXL::RestoreScratch(int reg ATTRIBUTE_UNUSED) { |
| 5765 | TODO_VIXL32(FATAL); |
| 5766 | } |
| 5767 | |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5768 | HLoadClass::LoadKind CodeGeneratorARMVIXL::GetSupportedLoadClassKind( |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 5769 | HLoadClass::LoadKind desired_class_load_kind) { |
| 5770 | switch (desired_class_load_kind) { |
| 5771 | case HLoadClass::LoadKind::kReferrersClass: |
| 5772 | break; |
| 5773 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: |
| 5774 | // TODO(VIXL): Enable it back when literal pools are fixed in VIXL. |
| 5775 | return HLoadClass::LoadKind::kDexCacheViaMethod; |
| 5776 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
| 5777 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 5778 | break; |
| 5779 | case HLoadClass::LoadKind::kBootImageAddress: |
| 5780 | // TODO(VIXL): Enable it back when literal pools are fixed in VIXL. |
| 5781 | return HLoadClass::LoadKind::kDexCacheViaMethod; |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5782 | case HLoadClass::LoadKind::kJitTableAddress: |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 5783 | // TODO(VIXL): Enable it back when literal pools are fixed in VIXL. |
| 5784 | return HLoadClass::LoadKind::kDexCacheViaMethod; |
| 5785 | case HLoadClass::LoadKind::kDexCachePcRelative: |
| 5786 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| 5787 | // We disable pc-relative load when there is an irreducible loop, as the optimization |
| 5788 | // is incompatible with it. |
| 5789 | // TODO: Create as many ArmDexCacheArraysBase instructions as needed for methods |
| 5790 | // with irreducible loops. |
| 5791 | if (GetGraph()->HasIrreducibleLoops()) { |
| 5792 | return HLoadClass::LoadKind::kDexCacheViaMethod; |
| 5793 | } |
| 5794 | break; |
| 5795 | case HLoadClass::LoadKind::kDexCacheViaMethod: |
| 5796 | break; |
| 5797 | } |
| 5798 | return desired_class_load_kind; |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5799 | } |
| 5800 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5801 | void LocationsBuilderARMVIXL::VisitLoadClass(HLoadClass* cls) { |
| 5802 | if (cls->NeedsAccessCheck()) { |
| 5803 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 5804 | CodeGenerator::CreateLoadClassLocationSummary( |
| 5805 | cls, |
| 5806 | LocationFrom(calling_convention.GetRegisterAt(0)), |
| 5807 | LocationFrom(r0), |
| 5808 | /* code_generator_supports_read_barrier */ true); |
| 5809 | return; |
| 5810 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 5811 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 5812 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
| 5813 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5814 | ? LocationSummary::kCallOnSlowPath |
| 5815 | : LocationSummary::kNoCall; |
| 5816 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(cls, call_kind); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 5817 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 5818 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 5819 | } |
| 5820 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5821 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
| 5822 | if (load_kind == HLoadClass::LoadKind::kReferrersClass || |
| 5823 | load_kind == HLoadClass::LoadKind::kDexCacheViaMethod || |
| 5824 | load_kind == HLoadClass::LoadKind::kDexCachePcRelative) { |
| 5825 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5826 | } |
| 5827 | locations->SetOut(Location::RequiresRegister()); |
| 5828 | } |
| 5829 | |
| 5830 | void InstructionCodeGeneratorARMVIXL::VisitLoadClass(HLoadClass* cls) { |
| 5831 | LocationSummary* locations = cls->GetLocations(); |
| 5832 | if (cls->NeedsAccessCheck()) { |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 5833 | codegen_->MoveConstant(locations->GetTemp(0), cls->GetTypeIndex().index_); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5834 | codegen_->InvokeRuntime(kQuickInitializeTypeAndVerifyAccess, cls, cls->GetDexPc()); |
| 5835 | CheckEntrypointTypes<kQuickInitializeTypeAndVerifyAccess, void*, uint32_t>(); |
| 5836 | return; |
| 5837 | } |
| 5838 | |
| 5839 | Location out_loc = locations->Out(); |
| 5840 | vixl32::Register out = OutputRegister(cls); |
| 5841 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 5842 | const ReadBarrierOption read_barrier_option = cls->IsInBootImage() |
| 5843 | ? kWithoutReadBarrier |
| 5844 | : kCompilerReadBarrierOption; |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5845 | bool generate_null_check = false; |
| 5846 | switch (cls->GetLoadKind()) { |
| 5847 | case HLoadClass::LoadKind::kReferrersClass: { |
| 5848 | DCHECK(!cls->CanCallRuntime()); |
| 5849 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 5850 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 5851 | vixl32::Register current_method = InputRegisterAt(cls, 0); |
| 5852 | GenerateGcRootFieldLoad(cls, |
| 5853 | out_loc, |
| 5854 | current_method, |
Roland Levillain | 00468f3 | 2016-10-27 18:02:48 +0100 | [diff] [blame] | 5855 | ArtMethod::DeclaringClassOffset().Int32Value(), |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 5856 | read_barrier_option); |
| 5857 | break; |
| 5858 | } |
| 5859 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: { |
| 5860 | TODO_VIXL32(FATAL); |
| 5861 | break; |
| 5862 | } |
| 5863 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { |
| 5864 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
| 5865 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels = |
| 5866 | codegen_->NewPcRelativeTypePatch(cls->GetDexFile(), cls->GetTypeIndex()); |
| 5867 | codegen_->EmitMovwMovtPlaceholder(labels, out); |
| 5868 | break; |
| 5869 | } |
| 5870 | case HLoadClass::LoadKind::kBootImageAddress: { |
| 5871 | TODO_VIXL32(FATAL); |
| 5872 | break; |
| 5873 | } |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5874 | case HLoadClass::LoadKind::kJitTableAddress: { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 5875 | TODO_VIXL32(FATAL); |
| 5876 | break; |
| 5877 | } |
| 5878 | case HLoadClass::LoadKind::kDexCachePcRelative: { |
| 5879 | vixl32::Register base_reg = InputRegisterAt(cls, 0); |
| 5880 | HArmDexCacheArraysBase* base = cls->InputAt(0)->AsArmDexCacheArraysBase(); |
| 5881 | int32_t offset = cls->GetDexCacheElementOffset() - base->GetElementOffset(); |
| 5882 | // /* GcRoot<mirror::Class> */ out = *(dex_cache_arrays_base + offset) |
| 5883 | GenerateGcRootFieldLoad(cls, out_loc, base_reg, offset, read_barrier_option); |
| 5884 | generate_null_check = !cls->IsInDexCache(); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5885 | break; |
| 5886 | } |
| 5887 | case HLoadClass::LoadKind::kDexCacheViaMethod: { |
| 5888 | // /* GcRoot<mirror::Class>[] */ out = |
| 5889 | // current_method.ptr_sized_fields_->dex_cache_resolved_types_ |
| 5890 | vixl32::Register current_method = InputRegisterAt(cls, 0); |
| 5891 | const int32_t resolved_types_offset = |
| 5892 | ArtMethod::DexCacheResolvedTypesOffset(kArmPointerSize).Int32Value(); |
| 5893 | GetAssembler()->LoadFromOffset(kLoadWord, out, current_method, resolved_types_offset); |
| 5894 | // /* GcRoot<mirror::Class> */ out = out[type_index] |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 5895 | size_t offset = CodeGenerator::GetCacheOffset(cls->GetTypeIndex().index_); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 5896 | GenerateGcRootFieldLoad(cls, out_loc, out, offset, read_barrier_option); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5897 | generate_null_check = !cls->IsInDexCache(); |
| 5898 | break; |
| 5899 | } |
| 5900 | default: |
| 5901 | TODO_VIXL32(FATAL); |
| 5902 | } |
| 5903 | |
| 5904 | if (generate_null_check || cls->MustGenerateClinitCheck()) { |
| 5905 | DCHECK(cls->CanCallRuntime()); |
| 5906 | LoadClassSlowPathARMVIXL* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARMVIXL( |
| 5907 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 5908 | codegen_->AddSlowPath(slow_path); |
| 5909 | if (generate_null_check) { |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 5910 | __ CompareAndBranchIfZero(out, slow_path->GetEntryLabel()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5911 | } |
| 5912 | if (cls->MustGenerateClinitCheck()) { |
| 5913 | GenerateClassInitializationCheck(slow_path, out); |
| 5914 | } else { |
| 5915 | __ Bind(slow_path->GetExitLabel()); |
| 5916 | } |
| 5917 | } |
| 5918 | } |
| 5919 | |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5920 | void LocationsBuilderARMVIXL::VisitClinitCheck(HClinitCheck* check) { |
| 5921 | LocationSummary* locations = |
| 5922 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 5923 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5924 | if (check->HasUses()) { |
| 5925 | locations->SetOut(Location::SameAsFirstInput()); |
| 5926 | } |
| 5927 | } |
| 5928 | |
| 5929 | void InstructionCodeGeneratorARMVIXL::VisitClinitCheck(HClinitCheck* check) { |
| 5930 | // We assume the class is not null. |
| 5931 | LoadClassSlowPathARMVIXL* slow_path = |
| 5932 | new (GetGraph()->GetArena()) LoadClassSlowPathARMVIXL(check->GetLoadClass(), |
| 5933 | check, |
| 5934 | check->GetDexPc(), |
| 5935 | /* do_clinit */ true); |
| 5936 | codegen_->AddSlowPath(slow_path); |
| 5937 | GenerateClassInitializationCheck(slow_path, InputRegisterAt(check, 0)); |
| 5938 | } |
| 5939 | |
| 5940 | void InstructionCodeGeneratorARMVIXL::GenerateClassInitializationCheck( |
| 5941 | LoadClassSlowPathARMVIXL* slow_path, vixl32::Register class_reg) { |
| 5942 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 5943 | vixl32::Register temp = temps.Acquire(); |
| 5944 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 5945 | temp, |
| 5946 | class_reg, |
| 5947 | mirror::Class::StatusOffset().Int32Value()); |
| 5948 | __ Cmp(temp, mirror::Class::kStatusInitialized); |
| 5949 | __ B(lt, slow_path->GetEntryLabel()); |
| 5950 | // Even if the initialized flag is set, we may be in a situation where caches are not synced |
| 5951 | // properly. Therefore, we do a memory fence. |
| 5952 | __ Dmb(ISH); |
| 5953 | __ Bind(slow_path->GetExitLabel()); |
| 5954 | } |
| 5955 | |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5956 | HLoadString::LoadKind CodeGeneratorARMVIXL::GetSupportedLoadStringKind( |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 5957 | HLoadString::LoadKind desired_string_load_kind) { |
| 5958 | switch (desired_string_load_kind) { |
| 5959 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: |
| 5960 | // TODO(VIXL): Implement missing optimization. |
| 5961 | return HLoadString::LoadKind::kDexCacheViaMethod; |
| 5962 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
| 5963 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 5964 | break; |
| 5965 | case HLoadString::LoadKind::kBootImageAddress: |
| 5966 | // TODO(VIXL): Implement missing optimization. |
| 5967 | return HLoadString::LoadKind::kDexCacheViaMethod; |
| 5968 | case HLoadString::LoadKind::kBssEntry: |
| 5969 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| 5970 | break; |
| 5971 | case HLoadString::LoadKind::kJitTableAddress: |
| 5972 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 5973 | // TODO(VIXL): Implement missing optimization. |
| 5974 | return HLoadString::LoadKind::kDexCacheViaMethod; |
| 5975 | case HLoadString::LoadKind::kDexCacheViaMethod: |
| 5976 | break; |
| 5977 | } |
| 5978 | return desired_string_load_kind; |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5979 | } |
| 5980 | |
| 5981 | void LocationsBuilderARMVIXL::VisitLoadString(HLoadString* load) { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 5982 | LocationSummary::CallKind call_kind = CodeGenerator::GetLoadStringCallKind(load); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5983 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5984 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
| 5985 | if (load_kind == HLoadString::LoadKind::kDexCacheViaMethod) { |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5986 | locations->SetOut(LocationFrom(r0)); |
| 5987 | } else { |
| 5988 | locations->SetOut(Location::RequiresRegister()); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 5989 | if (load_kind == HLoadString::LoadKind::kBssEntry) { |
| 5990 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 5991 | // Rely on the pResolveString and/or marking to save everything, including temps. |
| 5992 | // Note that IP may theoretically be clobbered by saving/restoring the live register |
| 5993 | // (only one thanks to the custom calling convention), so we request a different temp. |
| 5994 | locations->AddTemp(Location::RequiresRegister()); |
| 5995 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 5996 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 5997 | caller_saves.Add(LocationFrom(calling_convention.GetRegisterAt(0))); |
| 5998 | // TODO: Add GetReturnLocation() to the calling convention so that we can DCHECK() |
| 5999 | // that the the kPrimNot result register is the same as the first argument register. |
| 6000 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 6001 | } else { |
| 6002 | // For non-Baker read barrier we have a temp-clobbering call. |
| 6003 | } |
| 6004 | } |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 6005 | } |
| 6006 | } |
| 6007 | |
| 6008 | void InstructionCodeGeneratorARMVIXL::VisitLoadString(HLoadString* load) { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 6009 | LocationSummary* locations = load->GetLocations(); |
| 6010 | Location out_loc = locations->Out(); |
| 6011 | vixl32::Register out = OutputRegister(load); |
| 6012 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
| 6013 | |
| 6014 | switch (load_kind) { |
| 6015 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: { |
| 6016 | TODO_VIXL32(FATAL); |
| 6017 | break; |
| 6018 | } |
| 6019 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
| 6020 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
| 6021 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels = |
| 6022 | codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex().index_); |
| 6023 | codegen_->EmitMovwMovtPlaceholder(labels, out); |
| 6024 | return; // No dex cache slow path. |
| 6025 | } |
| 6026 | case HLoadString::LoadKind::kBootImageAddress: { |
| 6027 | TODO_VIXL32(FATAL); |
| 6028 | break; |
| 6029 | } |
| 6030 | case HLoadString::LoadKind::kBssEntry: { |
| 6031 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
| 6032 | vixl32::Register temp = RegisterFrom(locations->GetTemp(0)); |
| 6033 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels = |
| 6034 | codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex().index_); |
| 6035 | codegen_->EmitMovwMovtPlaceholder(labels, temp); |
| 6036 | GenerateGcRootFieldLoad(load, out_loc, temp, /* offset */ 0, kCompilerReadBarrierOption); |
| 6037 | LoadStringSlowPathARMVIXL* slow_path = |
| 6038 | new (GetGraph()->GetArena()) LoadStringSlowPathARMVIXL(load); |
| 6039 | codegen_->AddSlowPath(slow_path); |
| 6040 | __ CompareAndBranchIfZero(out, slow_path->GetEntryLabel()); |
| 6041 | __ Bind(slow_path->GetExitLabel()); |
| 6042 | return; |
| 6043 | } |
| 6044 | case HLoadString::LoadKind::kJitTableAddress: { |
| 6045 | TODO_VIXL32(FATAL); |
| 6046 | break; |
| 6047 | } |
| 6048 | default: |
| 6049 | break; |
| 6050 | } |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 6051 | |
| 6052 | // TODO: Re-add the compiler code to do string dex cache lookup again. |
| 6053 | DCHECK_EQ(load->GetLoadKind(), HLoadString::LoadKind::kDexCacheViaMethod); |
| 6054 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 6055 | __ Mov(calling_convention.GetRegisterAt(0), load->GetStringIndex().index_); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 6056 | codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc()); |
| 6057 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
| 6058 | } |
| 6059 | |
| 6060 | static int32_t GetExceptionTlsOffset() { |
| 6061 | return Thread::ExceptionOffset<kArmPointerSize>().Int32Value(); |
| 6062 | } |
| 6063 | |
| 6064 | void LocationsBuilderARMVIXL::VisitLoadException(HLoadException* load) { |
| 6065 | LocationSummary* locations = |
| 6066 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 6067 | locations->SetOut(Location::RequiresRegister()); |
| 6068 | } |
| 6069 | |
| 6070 | void InstructionCodeGeneratorARMVIXL::VisitLoadException(HLoadException* load) { |
| 6071 | vixl32::Register out = OutputRegister(load); |
| 6072 | GetAssembler()->LoadFromOffset(kLoadWord, out, tr, GetExceptionTlsOffset()); |
| 6073 | } |
| 6074 | |
| 6075 | |
| 6076 | void LocationsBuilderARMVIXL::VisitClearException(HClearException* clear) { |
| 6077 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 6078 | } |
| 6079 | |
| 6080 | void InstructionCodeGeneratorARMVIXL::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 6081 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 6082 | vixl32::Register temp = temps.Acquire(); |
| 6083 | __ Mov(temp, 0); |
| 6084 | GetAssembler()->StoreToOffset(kStoreWord, temp, tr, GetExceptionTlsOffset()); |
| 6085 | } |
| 6086 | |
| 6087 | void LocationsBuilderARMVIXL::VisitThrow(HThrow* instruction) { |
| 6088 | LocationSummary* locations = |
| 6089 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
| 6090 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 6091 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 6092 | } |
| 6093 | |
| 6094 | void InstructionCodeGeneratorARMVIXL::VisitThrow(HThrow* instruction) { |
| 6095 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
| 6096 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
| 6097 | } |
| 6098 | |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 6099 | // Temp is used for read barrier. |
| 6100 | static size_t NumberOfInstanceOfTemps(TypeCheckKind type_check_kind) { |
| 6101 | if (kEmitCompilerReadBarrier && |
| 6102 | (kUseBakerReadBarrier || |
| 6103 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 6104 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 6105 | type_check_kind == TypeCheckKind::kArrayObjectCheck)) { |
| 6106 | return 1; |
| 6107 | } |
| 6108 | return 0; |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6109 | } |
| 6110 | |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 6111 | // Interface case has 3 temps, one for holding the number of interfaces, one for the current |
| 6112 | // interface pointer, one for loading the current interface. |
| 6113 | // The other checks have one temp for loading the object's class. |
| 6114 | static size_t NumberOfCheckCastTemps(TypeCheckKind type_check_kind) { |
| 6115 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { |
| 6116 | return 3; |
| 6117 | } |
| 6118 | return 1 + NumberOfInstanceOfTemps(type_check_kind); |
| 6119 | } |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 6120 | |
| 6121 | void LocationsBuilderARMVIXL::VisitInstanceOf(HInstanceOf* instruction) { |
| 6122 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 6123 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 6124 | bool baker_read_barrier_slow_path = false; |
| 6125 | switch (type_check_kind) { |
| 6126 | case TypeCheckKind::kExactCheck: |
| 6127 | case TypeCheckKind::kAbstractClassCheck: |
| 6128 | case TypeCheckKind::kClassHierarchyCheck: |
| 6129 | case TypeCheckKind::kArrayObjectCheck: |
| 6130 | call_kind = |
| 6131 | kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
| 6132 | baker_read_barrier_slow_path = kUseBakerReadBarrier; |
| 6133 | break; |
| 6134 | case TypeCheckKind::kArrayCheck: |
| 6135 | case TypeCheckKind::kUnresolvedCheck: |
| 6136 | case TypeCheckKind::kInterfaceCheck: |
| 6137 | call_kind = LocationSummary::kCallOnSlowPath; |
| 6138 | break; |
| 6139 | } |
| 6140 | |
| 6141 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 6142 | if (baker_read_barrier_slow_path) { |
| 6143 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| 6144 | } |
| 6145 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6146 | locations->SetInAt(1, Location::RequiresRegister()); |
| 6147 | // The "out" register is used as a temporary, so it overlaps with the inputs. |
| 6148 | // Note that TypeCheckSlowPathARM uses this register too. |
| 6149 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 6150 | locations->AddRegisterTemps(NumberOfInstanceOfTemps(type_check_kind)); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 6151 | } |
| 6152 | |
| 6153 | void InstructionCodeGeneratorARMVIXL::VisitInstanceOf(HInstanceOf* instruction) { |
| 6154 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 6155 | LocationSummary* locations = instruction->GetLocations(); |
| 6156 | Location obj_loc = locations->InAt(0); |
| 6157 | vixl32::Register obj = InputRegisterAt(instruction, 0); |
| 6158 | vixl32::Register cls = InputRegisterAt(instruction, 1); |
| 6159 | Location out_loc = locations->Out(); |
| 6160 | vixl32::Register out = OutputRegister(instruction); |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 6161 | const size_t num_temps = NumberOfInstanceOfTemps(type_check_kind); |
| 6162 | DCHECK_LE(num_temps, 1u); |
| 6163 | Location maybe_temp_loc = (num_temps >= 1) ? locations->GetTemp(0) : Location::NoLocation(); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 6164 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 6165 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6166 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6167 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 6168 | vixl32::Label done, zero; |
| 6169 | SlowPathCodeARMVIXL* slow_path = nullptr; |
| 6170 | |
| 6171 | // Return 0 if `obj` is null. |
| 6172 | // avoid null check if we know obj is not null. |
| 6173 | if (instruction->MustDoNullCheck()) { |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 6174 | __ CompareAndBranchIfZero(obj, &zero, /* far_target */ false); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 6175 | } |
| 6176 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 6177 | switch (type_check_kind) { |
| 6178 | case TypeCheckKind::kExactCheck: { |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 6179 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6180 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6181 | out_loc, |
| 6182 | obj_loc, |
| 6183 | class_offset, |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 6184 | maybe_temp_loc, |
| 6185 | kCompilerReadBarrierOption); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 6186 | __ Cmp(out, cls); |
| 6187 | // Classes must be equal for the instanceof to succeed. |
| 6188 | __ B(ne, &zero); |
| 6189 | __ Mov(out, 1); |
| 6190 | __ B(&done); |
| 6191 | break; |
| 6192 | } |
| 6193 | |
| 6194 | case TypeCheckKind::kAbstractClassCheck: { |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 6195 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6196 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6197 | out_loc, |
| 6198 | obj_loc, |
| 6199 | class_offset, |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 6200 | maybe_temp_loc, |
| 6201 | kCompilerReadBarrierOption); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 6202 | // If the class is abstract, we eagerly fetch the super class of the |
| 6203 | // object to avoid doing a comparison we know will fail. |
| 6204 | vixl32::Label loop; |
| 6205 | __ Bind(&loop); |
| 6206 | // /* HeapReference<Class> */ out = out->super_class_ |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 6207 | GenerateReferenceLoadOneRegister(instruction, |
| 6208 | out_loc, |
| 6209 | super_offset, |
| 6210 | maybe_temp_loc, |
| 6211 | kCompilerReadBarrierOption); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 6212 | // 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] | 6213 | __ CompareAndBranchIfZero(out, &done, /* far_target */ false); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 6214 | __ Cmp(out, cls); |
| 6215 | __ B(ne, &loop); |
| 6216 | __ Mov(out, 1); |
| 6217 | if (zero.IsReferenced()) { |
| 6218 | __ B(&done); |
| 6219 | } |
| 6220 | break; |
| 6221 | } |
| 6222 | |
| 6223 | case TypeCheckKind::kClassHierarchyCheck: { |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 6224 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6225 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6226 | out_loc, |
| 6227 | obj_loc, |
| 6228 | class_offset, |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 6229 | maybe_temp_loc, |
| 6230 | kCompilerReadBarrierOption); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 6231 | // Walk over the class hierarchy to find a match. |
| 6232 | vixl32::Label loop, success; |
| 6233 | __ Bind(&loop); |
| 6234 | __ Cmp(out, cls); |
| 6235 | __ B(eq, &success); |
| 6236 | // /* HeapReference<Class> */ out = out->super_class_ |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 6237 | GenerateReferenceLoadOneRegister(instruction, |
| 6238 | out_loc, |
| 6239 | super_offset, |
| 6240 | maybe_temp_loc, |
| 6241 | kCompilerReadBarrierOption); |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 6242 | __ CompareAndBranchIfNonZero(out, &loop); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 6243 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6244 | __ B(&done); |
| 6245 | __ Bind(&success); |
| 6246 | __ Mov(out, 1); |
| 6247 | if (zero.IsReferenced()) { |
| 6248 | __ B(&done); |
| 6249 | } |
| 6250 | break; |
| 6251 | } |
| 6252 | |
| 6253 | case TypeCheckKind::kArrayObjectCheck: { |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 6254 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6255 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6256 | out_loc, |
| 6257 | obj_loc, |
| 6258 | class_offset, |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 6259 | maybe_temp_loc, |
| 6260 | kCompilerReadBarrierOption); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 6261 | // Do an exact check. |
| 6262 | vixl32::Label exact_check; |
| 6263 | __ Cmp(out, cls); |
| 6264 | __ B(eq, &exact_check); |
| 6265 | // Otherwise, we need to check that the object's class is a non-primitive array. |
| 6266 | // /* HeapReference<Class> */ out = out->component_type_ |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 6267 | GenerateReferenceLoadOneRegister(instruction, |
| 6268 | out_loc, |
| 6269 | component_offset, |
| 6270 | maybe_temp_loc, |
| 6271 | kCompilerReadBarrierOption); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 6272 | // 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] | 6273 | __ CompareAndBranchIfZero(out, &done, /* far_target */ false); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 6274 | GetAssembler()->LoadFromOffset(kLoadUnsignedHalfword, out, out, primitive_offset); |
| 6275 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 6276 | __ CompareAndBranchIfNonZero(out, &zero, /* far_target */ false); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 6277 | __ Bind(&exact_check); |
| 6278 | __ Mov(out, 1); |
| 6279 | __ B(&done); |
| 6280 | break; |
| 6281 | } |
| 6282 | |
| 6283 | case TypeCheckKind::kArrayCheck: { |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 6284 | // No read barrier since the slow path will retry upon failure. |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 6285 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6286 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6287 | out_loc, |
| 6288 | obj_loc, |
| 6289 | class_offset, |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 6290 | maybe_temp_loc, |
| 6291 | kWithoutReadBarrier); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 6292 | __ Cmp(out, cls); |
| 6293 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 6294 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARMVIXL(instruction, |
| 6295 | /* is_fatal */ false); |
| 6296 | codegen_->AddSlowPath(slow_path); |
| 6297 | __ B(ne, slow_path->GetEntryLabel()); |
| 6298 | __ Mov(out, 1); |
| 6299 | if (zero.IsReferenced()) { |
| 6300 | __ B(&done); |
| 6301 | } |
| 6302 | break; |
| 6303 | } |
| 6304 | |
| 6305 | case TypeCheckKind::kUnresolvedCheck: |
| 6306 | case TypeCheckKind::kInterfaceCheck: { |
| 6307 | // Note that we indeed only call on slow path, but we always go |
| 6308 | // into the slow path for the unresolved and interface check |
| 6309 | // cases. |
| 6310 | // |
| 6311 | // We cannot directly call the InstanceofNonTrivial runtime |
| 6312 | // entry point without resorting to a type checking slow path |
| 6313 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 6314 | // require to assign fixed registers for the inputs of this |
| 6315 | // HInstanceOf instruction (following the runtime calling |
| 6316 | // convention), which might be cluttered by the potential first |
| 6317 | // read barrier emission at the beginning of this method. |
| 6318 | // |
| 6319 | // TODO: Introduce a new runtime entry point taking the object |
| 6320 | // to test (instead of its class) as argument, and let it deal |
| 6321 | // with the read barrier issues. This will let us refactor this |
| 6322 | // case of the `switch` code as it was previously (with a direct |
| 6323 | // call to the runtime not using a type checking slow path). |
| 6324 | // This should also be beneficial for the other cases above. |
| 6325 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 6326 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARMVIXL(instruction, |
| 6327 | /* is_fatal */ false); |
| 6328 | codegen_->AddSlowPath(slow_path); |
| 6329 | __ B(slow_path->GetEntryLabel()); |
| 6330 | if (zero.IsReferenced()) { |
| 6331 | __ B(&done); |
| 6332 | } |
| 6333 | break; |
| 6334 | } |
| 6335 | } |
| 6336 | |
| 6337 | if (zero.IsReferenced()) { |
| 6338 | __ Bind(&zero); |
| 6339 | __ Mov(out, 0); |
| 6340 | } |
| 6341 | |
| 6342 | if (done.IsReferenced()) { |
| 6343 | __ Bind(&done); |
| 6344 | } |
| 6345 | |
| 6346 | if (slow_path != nullptr) { |
| 6347 | __ Bind(slow_path->GetExitLabel()); |
| 6348 | } |
| 6349 | } |
| 6350 | |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6351 | void LocationsBuilderARMVIXL::VisitCheckCast(HCheckCast* instruction) { |
| 6352 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 6353 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
| 6354 | |
| 6355 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 6356 | switch (type_check_kind) { |
| 6357 | case TypeCheckKind::kExactCheck: |
| 6358 | case TypeCheckKind::kAbstractClassCheck: |
| 6359 | case TypeCheckKind::kClassHierarchyCheck: |
| 6360 | case TypeCheckKind::kArrayObjectCheck: |
| 6361 | call_kind = (throws_into_catch || kEmitCompilerReadBarrier) ? |
| 6362 | LocationSummary::kCallOnSlowPath : |
| 6363 | LocationSummary::kNoCall; // In fact, call on a fatal (non-returning) slow path. |
| 6364 | break; |
| 6365 | case TypeCheckKind::kArrayCheck: |
| 6366 | case TypeCheckKind::kUnresolvedCheck: |
| 6367 | case TypeCheckKind::kInterfaceCheck: |
| 6368 | call_kind = LocationSummary::kCallOnSlowPath; |
| 6369 | break; |
| 6370 | } |
| 6371 | |
| 6372 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 6373 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6374 | locations->SetInAt(1, Location::RequiresRegister()); |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 6375 | locations->AddRegisterTemps(NumberOfCheckCastTemps(type_check_kind)); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6376 | } |
| 6377 | |
| 6378 | void InstructionCodeGeneratorARMVIXL::VisitCheckCast(HCheckCast* instruction) { |
| 6379 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 6380 | LocationSummary* locations = instruction->GetLocations(); |
| 6381 | Location obj_loc = locations->InAt(0); |
| 6382 | vixl32::Register obj = InputRegisterAt(instruction, 0); |
| 6383 | vixl32::Register cls = InputRegisterAt(instruction, 1); |
| 6384 | Location temp_loc = locations->GetTemp(0); |
| 6385 | vixl32::Register temp = RegisterFrom(temp_loc); |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 6386 | const size_t num_temps = NumberOfCheckCastTemps(type_check_kind); |
| 6387 | DCHECK_LE(num_temps, 3u); |
| 6388 | Location maybe_temp2_loc = (num_temps >= 2) ? locations->GetTemp(1) : Location::NoLocation(); |
| 6389 | Location maybe_temp3_loc = (num_temps >= 3) ? locations->GetTemp(2) : Location::NoLocation(); |
| 6390 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 6391 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6392 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6393 | const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 6394 | const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value(); |
| 6395 | const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value(); |
| 6396 | const uint32_t object_array_data_offset = |
| 6397 | mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value(); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6398 | |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 6399 | // Always false for read barriers since we may need to go to the entrypoint for non-fatal cases |
| 6400 | // from false negatives. The false negatives may come from avoiding read barriers below. Avoiding |
| 6401 | // read barriers is done for performance and code size reasons. |
| 6402 | bool is_type_check_slow_path_fatal = false; |
| 6403 | if (!kEmitCompilerReadBarrier) { |
| 6404 | is_type_check_slow_path_fatal = |
| 6405 | (type_check_kind == TypeCheckKind::kExactCheck || |
| 6406 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 6407 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 6408 | type_check_kind == TypeCheckKind::kArrayObjectCheck) && |
| 6409 | !instruction->CanThrowIntoCatchBlock(); |
| 6410 | } |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6411 | SlowPathCodeARMVIXL* type_check_slow_path = |
| 6412 | new (GetGraph()->GetArena()) TypeCheckSlowPathARMVIXL(instruction, |
| 6413 | is_type_check_slow_path_fatal); |
| 6414 | codegen_->AddSlowPath(type_check_slow_path); |
| 6415 | |
| 6416 | vixl32::Label done; |
| 6417 | // Avoid null check if we know obj is not null. |
| 6418 | if (instruction->MustDoNullCheck()) { |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 6419 | __ CompareAndBranchIfZero(obj, &done, /* far_target */ false); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6420 | } |
| 6421 | |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6422 | switch (type_check_kind) { |
| 6423 | case TypeCheckKind::kExactCheck: |
| 6424 | case TypeCheckKind::kArrayCheck: { |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 6425 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6426 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6427 | temp_loc, |
| 6428 | obj_loc, |
| 6429 | class_offset, |
| 6430 | maybe_temp2_loc, |
| 6431 | kWithoutReadBarrier); |
| 6432 | |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6433 | __ Cmp(temp, cls); |
| 6434 | // Jump to slow path for throwing the exception or doing a |
| 6435 | // more involved array check. |
| 6436 | __ B(ne, type_check_slow_path->GetEntryLabel()); |
| 6437 | break; |
| 6438 | } |
| 6439 | |
| 6440 | case TypeCheckKind::kAbstractClassCheck: { |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 6441 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6442 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6443 | temp_loc, |
| 6444 | obj_loc, |
| 6445 | class_offset, |
| 6446 | maybe_temp2_loc, |
| 6447 | kWithoutReadBarrier); |
| 6448 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 6449 | // If the class is abstract, we eagerly fetch the super class of the |
| 6450 | // object to avoid doing a comparison we know will fail. |
| 6451 | vixl32::Label loop; |
| 6452 | __ Bind(&loop); |
| 6453 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 6454 | GenerateReferenceLoadOneRegister(instruction, |
| 6455 | temp_loc, |
| 6456 | super_offset, |
| 6457 | maybe_temp2_loc, |
| 6458 | kWithoutReadBarrier); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 6459 | |
| 6460 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 6461 | // exception. |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 6462 | __ CompareAndBranchIfZero(temp, type_check_slow_path->GetEntryLabel()); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 6463 | |
| 6464 | // Otherwise, compare the classes. |
| 6465 | __ Cmp(temp, cls); |
| 6466 | __ B(ne, &loop); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6467 | break; |
| 6468 | } |
| 6469 | |
| 6470 | case TypeCheckKind::kClassHierarchyCheck: { |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 6471 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6472 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6473 | temp_loc, |
| 6474 | obj_loc, |
| 6475 | class_offset, |
| 6476 | maybe_temp2_loc, |
| 6477 | kWithoutReadBarrier); |
| 6478 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 6479 | // Walk over the class hierarchy to find a match. |
| 6480 | vixl32::Label loop; |
| 6481 | __ Bind(&loop); |
| 6482 | __ Cmp(temp, cls); |
| 6483 | __ B(eq, &done); |
| 6484 | |
| 6485 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 6486 | GenerateReferenceLoadOneRegister(instruction, |
| 6487 | temp_loc, |
| 6488 | super_offset, |
| 6489 | maybe_temp2_loc, |
| 6490 | kWithoutReadBarrier); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 6491 | |
| 6492 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 6493 | // exception. |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 6494 | __ CompareAndBranchIfZero(temp, type_check_slow_path->GetEntryLabel()); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 6495 | // Otherwise, jump to the beginning of the loop. |
| 6496 | __ B(&loop); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6497 | break; |
| 6498 | } |
| 6499 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 6500 | case TypeCheckKind::kArrayObjectCheck: { |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 6501 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6502 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6503 | temp_loc, |
| 6504 | obj_loc, |
| 6505 | class_offset, |
| 6506 | maybe_temp2_loc, |
| 6507 | kWithoutReadBarrier); |
| 6508 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 6509 | // Do an exact check. |
| 6510 | __ Cmp(temp, cls); |
| 6511 | __ B(eq, &done); |
| 6512 | |
| 6513 | // Otherwise, we need to check that the object's class is a non-primitive array. |
| 6514 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 6515 | GenerateReferenceLoadOneRegister(instruction, |
| 6516 | temp_loc, |
| 6517 | component_offset, |
| 6518 | maybe_temp2_loc, |
| 6519 | kWithoutReadBarrier); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 6520 | // 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] | 6521 | __ CompareAndBranchIfZero(temp, type_check_slow_path->GetEntryLabel()); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 6522 | // Otherwise,the object is indeed an array, jump to label `check_non_primitive_component_type` |
| 6523 | // to further check that this component type is not a primitive type. |
| 6524 | GetAssembler()->LoadFromOffset(kLoadUnsignedHalfword, temp, temp, primitive_offset); |
| 6525 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for art::Primitive::kPrimNot"); |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 6526 | __ CompareAndBranchIfNonZero(temp, type_check_slow_path->GetEntryLabel()); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6527 | break; |
| 6528 | } |
| 6529 | |
| 6530 | case TypeCheckKind::kUnresolvedCheck: |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 6531 | // 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] | 6532 | // We cannot directly call the CheckCast runtime entry point |
| 6533 | // without resorting to a type checking slow path here (i.e. by |
| 6534 | // calling InvokeRuntime directly), as it would require to |
| 6535 | // assign fixed registers for the inputs of this HInstanceOf |
| 6536 | // instruction (following the runtime calling convention), which |
| 6537 | // might be cluttered by the potential first read barrier |
| 6538 | // emission at the beginning of this method. |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 6539 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 6540 | __ B(type_check_slow_path->GetEntryLabel()); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6541 | break; |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 6542 | |
| 6543 | case TypeCheckKind::kInterfaceCheck: { |
| 6544 | // Avoid read barriers to improve performance of the fast path. We can not get false |
| 6545 | // positives by doing this. |
| 6546 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6547 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6548 | temp_loc, |
| 6549 | obj_loc, |
| 6550 | class_offset, |
| 6551 | maybe_temp2_loc, |
| 6552 | kWithoutReadBarrier); |
| 6553 | |
| 6554 | // /* HeapReference<Class> */ temp = temp->iftable_ |
| 6555 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6556 | temp_loc, |
| 6557 | temp_loc, |
| 6558 | iftable_offset, |
| 6559 | maybe_temp2_loc, |
| 6560 | kWithoutReadBarrier); |
| 6561 | // Iftable is never null. |
| 6562 | __ Ldr(RegisterFrom(maybe_temp2_loc), MemOperand(temp, array_length_offset)); |
| 6563 | // Loop through the iftable and check if any class matches. |
| 6564 | vixl32::Label start_loop; |
| 6565 | __ Bind(&start_loop); |
| 6566 | __ CompareAndBranchIfZero(RegisterFrom(maybe_temp2_loc), |
| 6567 | type_check_slow_path->GetEntryLabel()); |
| 6568 | __ Ldr(RegisterFrom(maybe_temp3_loc), MemOperand(temp, object_array_data_offset)); |
| 6569 | GetAssembler()->MaybeUnpoisonHeapReference(RegisterFrom(maybe_temp3_loc)); |
| 6570 | // Go to next interface. |
| 6571 | __ Add(temp, temp, Operand::From(2 * kHeapReferenceSize)); |
| 6572 | __ Sub(RegisterFrom(maybe_temp2_loc), RegisterFrom(maybe_temp2_loc), 2); |
| 6573 | // Compare the classes and continue the loop if they do not match. |
| 6574 | __ Cmp(cls, RegisterFrom(maybe_temp3_loc)); |
| 6575 | __ B(ne, &start_loop); |
| 6576 | break; |
| 6577 | } |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6578 | } |
| 6579 | __ Bind(&done); |
| 6580 | |
| 6581 | __ Bind(type_check_slow_path->GetExitLabel()); |
| 6582 | } |
| 6583 | |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 6584 | void LocationsBuilderARMVIXL::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 6585 | LocationSummary* locations = |
| 6586 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
| 6587 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 6588 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 6589 | } |
| 6590 | |
| 6591 | void InstructionCodeGeneratorARMVIXL::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 6592 | codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject : kQuickUnlockObject, |
| 6593 | instruction, |
| 6594 | instruction->GetDexPc()); |
| 6595 | if (instruction->IsEnter()) { |
| 6596 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 6597 | } else { |
| 6598 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 6599 | } |
| 6600 | } |
| 6601 | |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 6602 | void LocationsBuilderARMVIXL::VisitAnd(HAnd* instruction) { |
| 6603 | HandleBitwiseOperation(instruction, AND); |
| 6604 | } |
| 6605 | |
| 6606 | void LocationsBuilderARMVIXL::VisitOr(HOr* instruction) { |
| 6607 | HandleBitwiseOperation(instruction, ORR); |
| 6608 | } |
| 6609 | |
| 6610 | void LocationsBuilderARMVIXL::VisitXor(HXor* instruction) { |
| 6611 | HandleBitwiseOperation(instruction, EOR); |
| 6612 | } |
| 6613 | |
| 6614 | void LocationsBuilderARMVIXL::HandleBitwiseOperation(HBinaryOperation* instruction, Opcode opcode) { |
| 6615 | LocationSummary* locations = |
| 6616 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 6617 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 6618 | || instruction->GetResultType() == Primitive::kPrimLong); |
| 6619 | // Note: GVN reorders commutative operations to have the constant on the right hand side. |
| 6620 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6621 | locations->SetInAt(1, ArmEncodableConstantOrRegister(instruction->InputAt(1), opcode)); |
| 6622 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6623 | } |
| 6624 | |
| 6625 | void InstructionCodeGeneratorARMVIXL::VisitAnd(HAnd* instruction) { |
| 6626 | HandleBitwiseOperation(instruction); |
| 6627 | } |
| 6628 | |
| 6629 | void InstructionCodeGeneratorARMVIXL::VisitOr(HOr* instruction) { |
| 6630 | HandleBitwiseOperation(instruction); |
| 6631 | } |
| 6632 | |
| 6633 | void InstructionCodeGeneratorARMVIXL::VisitXor(HXor* instruction) { |
| 6634 | HandleBitwiseOperation(instruction); |
| 6635 | } |
| 6636 | |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6637 | void LocationsBuilderARMVIXL::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instruction) { |
| 6638 | LocationSummary* locations = |
| 6639 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 6640 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 6641 | || instruction->GetResultType() == Primitive::kPrimLong); |
| 6642 | |
| 6643 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6644 | locations->SetInAt(1, Location::RequiresRegister()); |
| 6645 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6646 | } |
| 6647 | |
| 6648 | void InstructionCodeGeneratorARMVIXL::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instruction) { |
| 6649 | LocationSummary* locations = instruction->GetLocations(); |
| 6650 | Location first = locations->InAt(0); |
| 6651 | Location second = locations->InAt(1); |
| 6652 | Location out = locations->Out(); |
| 6653 | |
| 6654 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 6655 | vixl32::Register first_reg = RegisterFrom(first); |
| 6656 | vixl32::Register second_reg = RegisterFrom(second); |
| 6657 | vixl32::Register out_reg = RegisterFrom(out); |
| 6658 | |
| 6659 | switch (instruction->GetOpKind()) { |
| 6660 | case HInstruction::kAnd: |
| 6661 | __ Bic(out_reg, first_reg, second_reg); |
| 6662 | break; |
| 6663 | case HInstruction::kOr: |
| 6664 | __ Orn(out_reg, first_reg, second_reg); |
| 6665 | break; |
| 6666 | // There is no EON on arm. |
| 6667 | case HInstruction::kXor: |
| 6668 | default: |
| 6669 | LOG(FATAL) << "Unexpected instruction " << instruction->DebugName(); |
| 6670 | UNREACHABLE(); |
| 6671 | } |
| 6672 | return; |
| 6673 | |
| 6674 | } else { |
| 6675 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 6676 | vixl32::Register first_low = LowRegisterFrom(first); |
| 6677 | vixl32::Register first_high = HighRegisterFrom(first); |
| 6678 | vixl32::Register second_low = LowRegisterFrom(second); |
| 6679 | vixl32::Register second_high = HighRegisterFrom(second); |
| 6680 | vixl32::Register out_low = LowRegisterFrom(out); |
| 6681 | vixl32::Register out_high = HighRegisterFrom(out); |
| 6682 | |
| 6683 | switch (instruction->GetOpKind()) { |
| 6684 | case HInstruction::kAnd: |
| 6685 | __ Bic(out_low, first_low, second_low); |
| 6686 | __ Bic(out_high, first_high, second_high); |
| 6687 | break; |
| 6688 | case HInstruction::kOr: |
| 6689 | __ Orn(out_low, first_low, second_low); |
| 6690 | __ Orn(out_high, first_high, second_high); |
| 6691 | break; |
| 6692 | // There is no EON on arm. |
| 6693 | case HInstruction::kXor: |
| 6694 | default: |
| 6695 | LOG(FATAL) << "Unexpected instruction " << instruction->DebugName(); |
| 6696 | UNREACHABLE(); |
| 6697 | } |
| 6698 | } |
| 6699 | } |
| 6700 | |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 6701 | // TODO(VIXL): Remove optimizations in the helper when they are implemented in vixl. |
| 6702 | void InstructionCodeGeneratorARMVIXL::GenerateAndConst(vixl32::Register out, |
| 6703 | vixl32::Register first, |
| 6704 | uint32_t value) { |
| 6705 | // Optimize special cases for individual halfs of `and-long` (`and` is simplified earlier). |
| 6706 | if (value == 0xffffffffu) { |
| 6707 | if (!out.Is(first)) { |
| 6708 | __ Mov(out, first); |
| 6709 | } |
| 6710 | return; |
| 6711 | } |
| 6712 | if (value == 0u) { |
| 6713 | __ Mov(out, 0); |
| 6714 | return; |
| 6715 | } |
| 6716 | if (GetAssembler()->ShifterOperandCanHold(AND, value)) { |
| 6717 | __ And(out, first, value); |
| 6718 | } else { |
| 6719 | DCHECK(GetAssembler()->ShifterOperandCanHold(BIC, ~value)); |
| 6720 | __ Bic(out, first, ~value); |
| 6721 | } |
| 6722 | } |
| 6723 | |
| 6724 | // TODO(VIXL): Remove optimizations in the helper when they are implemented in vixl. |
| 6725 | void InstructionCodeGeneratorARMVIXL::GenerateOrrConst(vixl32::Register out, |
| 6726 | vixl32::Register first, |
| 6727 | uint32_t value) { |
| 6728 | // Optimize special cases for individual halfs of `or-long` (`or` is simplified earlier). |
| 6729 | if (value == 0u) { |
| 6730 | if (!out.Is(first)) { |
| 6731 | __ Mov(out, first); |
| 6732 | } |
| 6733 | return; |
| 6734 | } |
| 6735 | if (value == 0xffffffffu) { |
| 6736 | __ Mvn(out, 0); |
| 6737 | return; |
| 6738 | } |
| 6739 | if (GetAssembler()->ShifterOperandCanHold(ORR, value)) { |
| 6740 | __ Orr(out, first, value); |
| 6741 | } else { |
| 6742 | DCHECK(GetAssembler()->ShifterOperandCanHold(ORN, ~value)); |
| 6743 | __ Orn(out, first, ~value); |
| 6744 | } |
| 6745 | } |
| 6746 | |
| 6747 | // TODO(VIXL): Remove optimizations in the helper when they are implemented in vixl. |
| 6748 | void InstructionCodeGeneratorARMVIXL::GenerateEorConst(vixl32::Register out, |
| 6749 | vixl32::Register first, |
| 6750 | uint32_t value) { |
| 6751 | // Optimize special case for individual halfs of `xor-long` (`xor` is simplified earlier). |
| 6752 | if (value == 0u) { |
| 6753 | if (!out.Is(first)) { |
| 6754 | __ Mov(out, first); |
| 6755 | } |
| 6756 | return; |
| 6757 | } |
| 6758 | __ Eor(out, first, value); |
| 6759 | } |
| 6760 | |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 6761 | void InstructionCodeGeneratorARMVIXL::GenerateAddLongConst(Location out, |
| 6762 | Location first, |
| 6763 | uint64_t value) { |
| 6764 | vixl32::Register out_low = LowRegisterFrom(out); |
| 6765 | vixl32::Register out_high = HighRegisterFrom(out); |
| 6766 | vixl32::Register first_low = LowRegisterFrom(first); |
| 6767 | vixl32::Register first_high = HighRegisterFrom(first); |
| 6768 | uint32_t value_low = Low32Bits(value); |
| 6769 | uint32_t value_high = High32Bits(value); |
| 6770 | if (value_low == 0u) { |
| 6771 | if (!out_low.Is(first_low)) { |
| 6772 | __ Mov(out_low, first_low); |
| 6773 | } |
| 6774 | __ Add(out_high, first_high, value_high); |
| 6775 | return; |
| 6776 | } |
| 6777 | __ Adds(out_low, first_low, value_low); |
Scott Wakeling | bffdc70 | 2016-12-07 17:46:03 +0000 | [diff] [blame] | 6778 | if (GetAssembler()->ShifterOperandCanHold(ADC, value_high, kCcDontCare)) { |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 6779 | __ Adc(out_high, first_high, value_high); |
Scott Wakeling | bffdc70 | 2016-12-07 17:46:03 +0000 | [diff] [blame] | 6780 | } else if (GetAssembler()->ShifterOperandCanHold(SBC, ~value_high, kCcDontCare)) { |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 6781 | __ Sbc(out_high, first_high, ~value_high); |
| 6782 | } else { |
| 6783 | LOG(FATAL) << "Unexpected constant " << value_high; |
| 6784 | UNREACHABLE(); |
| 6785 | } |
| 6786 | } |
| 6787 | |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 6788 | void InstructionCodeGeneratorARMVIXL::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 6789 | LocationSummary* locations = instruction->GetLocations(); |
| 6790 | Location first = locations->InAt(0); |
| 6791 | Location second = locations->InAt(1); |
| 6792 | Location out = locations->Out(); |
| 6793 | |
| 6794 | if (second.IsConstant()) { |
| 6795 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant())); |
| 6796 | uint32_t value_low = Low32Bits(value); |
| 6797 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 6798 | vixl32::Register first_reg = InputRegisterAt(instruction, 0); |
| 6799 | vixl32::Register out_reg = OutputRegister(instruction); |
| 6800 | if (instruction->IsAnd()) { |
| 6801 | GenerateAndConst(out_reg, first_reg, value_low); |
| 6802 | } else if (instruction->IsOr()) { |
| 6803 | GenerateOrrConst(out_reg, first_reg, value_low); |
| 6804 | } else { |
| 6805 | DCHECK(instruction->IsXor()); |
| 6806 | GenerateEorConst(out_reg, first_reg, value_low); |
| 6807 | } |
| 6808 | } else { |
| 6809 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 6810 | uint32_t value_high = High32Bits(value); |
| 6811 | vixl32::Register first_low = LowRegisterFrom(first); |
| 6812 | vixl32::Register first_high = HighRegisterFrom(first); |
| 6813 | vixl32::Register out_low = LowRegisterFrom(out); |
| 6814 | vixl32::Register out_high = HighRegisterFrom(out); |
| 6815 | if (instruction->IsAnd()) { |
| 6816 | GenerateAndConst(out_low, first_low, value_low); |
| 6817 | GenerateAndConst(out_high, first_high, value_high); |
| 6818 | } else if (instruction->IsOr()) { |
| 6819 | GenerateOrrConst(out_low, first_low, value_low); |
| 6820 | GenerateOrrConst(out_high, first_high, value_high); |
| 6821 | } else { |
| 6822 | DCHECK(instruction->IsXor()); |
| 6823 | GenerateEorConst(out_low, first_low, value_low); |
| 6824 | GenerateEorConst(out_high, first_high, value_high); |
| 6825 | } |
| 6826 | } |
| 6827 | return; |
| 6828 | } |
| 6829 | |
| 6830 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 6831 | vixl32::Register first_reg = InputRegisterAt(instruction, 0); |
| 6832 | vixl32::Register second_reg = InputRegisterAt(instruction, 1); |
| 6833 | vixl32::Register out_reg = OutputRegister(instruction); |
| 6834 | if (instruction->IsAnd()) { |
| 6835 | __ And(out_reg, first_reg, second_reg); |
| 6836 | } else if (instruction->IsOr()) { |
| 6837 | __ Orr(out_reg, first_reg, second_reg); |
| 6838 | } else { |
| 6839 | DCHECK(instruction->IsXor()); |
| 6840 | __ Eor(out_reg, first_reg, second_reg); |
| 6841 | } |
| 6842 | } else { |
| 6843 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 6844 | vixl32::Register first_low = LowRegisterFrom(first); |
| 6845 | vixl32::Register first_high = HighRegisterFrom(first); |
| 6846 | vixl32::Register second_low = LowRegisterFrom(second); |
| 6847 | vixl32::Register second_high = HighRegisterFrom(second); |
| 6848 | vixl32::Register out_low = LowRegisterFrom(out); |
| 6849 | vixl32::Register out_high = HighRegisterFrom(out); |
| 6850 | if (instruction->IsAnd()) { |
| 6851 | __ And(out_low, first_low, second_low); |
| 6852 | __ And(out_high, first_high, second_high); |
| 6853 | } else if (instruction->IsOr()) { |
| 6854 | __ Orr(out_low, first_low, second_low); |
| 6855 | __ Orr(out_high, first_high, second_high); |
| 6856 | } else { |
| 6857 | DCHECK(instruction->IsXor()); |
| 6858 | __ Eor(out_low, first_low, second_low); |
| 6859 | __ Eor(out_high, first_high, second_high); |
| 6860 | } |
| 6861 | } |
| 6862 | } |
| 6863 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 6864 | void InstructionCodeGeneratorARMVIXL::GenerateReferenceLoadOneRegister( |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6865 | HInstruction* instruction, |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 6866 | Location out, |
| 6867 | uint32_t offset, |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6868 | Location maybe_temp, |
| 6869 | ReadBarrierOption read_barrier_option) { |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 6870 | vixl32::Register out_reg = RegisterFrom(out); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6871 | if (read_barrier_option == kWithReadBarrier) { |
| 6872 | CHECK(kEmitCompilerReadBarrier); |
| 6873 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
| 6874 | if (kUseBakerReadBarrier) { |
| 6875 | // Load with fast path based Baker's read barrier. |
| 6876 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6877 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 6878 | instruction, out, out_reg, offset, maybe_temp, /* needs_null_check */ false); |
| 6879 | } else { |
| 6880 | // Load with slow path based read barrier. |
| 6881 | // Save the value of `out` into `maybe_temp` before overwriting it |
| 6882 | // in the following move operation, as we will need it for the |
| 6883 | // read barrier below. |
| 6884 | __ Mov(RegisterFrom(maybe_temp), out_reg); |
| 6885 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6886 | GetAssembler()->LoadFromOffset(kLoadWord, out_reg, out_reg, offset); |
| 6887 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
| 6888 | } |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 6889 | } else { |
| 6890 | // Plain load with no read barrier. |
| 6891 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6892 | GetAssembler()->LoadFromOffset(kLoadWord, out_reg, out_reg, offset); |
| 6893 | GetAssembler()->MaybeUnpoisonHeapReference(out_reg); |
| 6894 | } |
| 6895 | } |
| 6896 | |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6897 | void InstructionCodeGeneratorARMVIXL::GenerateReferenceLoadTwoRegisters( |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6898 | HInstruction* instruction, |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6899 | Location out, |
| 6900 | Location obj, |
| 6901 | uint32_t offset, |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6902 | Location maybe_temp, |
| 6903 | ReadBarrierOption read_barrier_option) { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6904 | vixl32::Register out_reg = RegisterFrom(out); |
| 6905 | vixl32::Register obj_reg = RegisterFrom(obj); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6906 | if (read_barrier_option == kWithReadBarrier) { |
| 6907 | CHECK(kEmitCompilerReadBarrier); |
| 6908 | if (kUseBakerReadBarrier) { |
| 6909 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
| 6910 | // Load with fast path based Baker's read barrier. |
| 6911 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6912 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 6913 | instruction, out, obj_reg, offset, maybe_temp, /* needs_null_check */ false); |
| 6914 | } else { |
| 6915 | // Load with slow path based read barrier. |
| 6916 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6917 | GetAssembler()->LoadFromOffset(kLoadWord, out_reg, obj_reg, offset); |
| 6918 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 6919 | } |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6920 | } else { |
| 6921 | // Plain load with no read barrier. |
| 6922 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6923 | GetAssembler()->LoadFromOffset(kLoadWord, out_reg, obj_reg, offset); |
| 6924 | GetAssembler()->MaybeUnpoisonHeapReference(out_reg); |
| 6925 | } |
| 6926 | } |
| 6927 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6928 | void InstructionCodeGeneratorARMVIXL::GenerateGcRootFieldLoad( |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6929 | HInstruction* instruction, |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6930 | Location root, |
| 6931 | vixl32::Register obj, |
| 6932 | uint32_t offset, |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 6933 | ReadBarrierOption read_barrier_option) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6934 | vixl32::Register root_reg = RegisterFrom(root); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 6935 | if (read_barrier_option == kWithReadBarrier) { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6936 | DCHECK(kEmitCompilerReadBarrier); |
| 6937 | if (kUseBakerReadBarrier) { |
| 6938 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
| 6939 | // Baker's read barrier are used: |
| 6940 | // |
| 6941 | // root = obj.field; |
| 6942 | // temp = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 6943 | // if (temp != null) { |
| 6944 | // root = temp(root) |
| 6945 | // } |
| 6946 | |
| 6947 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 6948 | GetAssembler()->LoadFromOffset(kLoadWord, root_reg, obj, offset); |
| 6949 | static_assert( |
| 6950 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 6951 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 6952 | "have different sizes."); |
| 6953 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 6954 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 6955 | "have different sizes."); |
| 6956 | |
| 6957 | // Slow path marking the GC root `root`. |
| 6958 | Location temp = LocationFrom(lr); |
| 6959 | SlowPathCodeARMVIXL* slow_path = |
| 6960 | new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathARMVIXL( |
| 6961 | instruction, |
| 6962 | root, |
| 6963 | /*entrypoint*/ temp); |
| 6964 | codegen_->AddSlowPath(slow_path); |
| 6965 | |
| 6966 | // temp = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 6967 | const int32_t entry_point_offset = |
| 6968 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArmPointerSize>(root.reg()); |
| 6969 | // Loading the entrypoint does not require a load acquire since it is only changed when |
| 6970 | // threads are suspended or running a checkpoint. |
| 6971 | GetAssembler()->LoadFromOffset(kLoadWord, RegisterFrom(temp), tr, entry_point_offset); |
| 6972 | // The entrypoint is null when the GC is not marking, this prevents one load compared to |
| 6973 | // checking GetIsGcMarking. |
| 6974 | __ CompareAndBranchIfNonZero(RegisterFrom(temp), slow_path->GetEntryLabel()); |
| 6975 | __ Bind(slow_path->GetExitLabel()); |
| 6976 | } else { |
| 6977 | // GC root loaded through a slow path for read barriers other |
| 6978 | // than Baker's. |
| 6979 | // /* GcRoot<mirror::Object>* */ root = obj + offset |
| 6980 | __ Add(root_reg, obj, offset); |
| 6981 | // /* mirror::Object* */ root = root->Read() |
| 6982 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 6983 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6984 | } else { |
| 6985 | // Plain GC root load with no read barrier. |
| 6986 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 6987 | GetAssembler()->LoadFromOffset(kLoadWord, root_reg, obj, offset); |
| 6988 | // Note that GC roots are not affected by heap poisoning, thus we |
| 6989 | // do not have to unpoison `root_reg` here. |
| 6990 | } |
| 6991 | } |
| 6992 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6993 | void CodeGeneratorARMVIXL::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6994 | Location ref, |
| 6995 | vixl32::Register obj, |
| 6996 | uint32_t offset, |
| 6997 | Location temp, |
| 6998 | bool needs_null_check) { |
| 6999 | DCHECK(kEmitCompilerReadBarrier); |
| 7000 | DCHECK(kUseBakerReadBarrier); |
| 7001 | |
| 7002 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 7003 | Location no_index = Location::NoLocation(); |
| 7004 | ScaleFactor no_scale_factor = TIMES_1; |
| 7005 | GenerateReferenceLoadWithBakerReadBarrier( |
| 7006 | 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] | 7007 | } |
| 7008 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 7009 | void CodeGeneratorARMVIXL::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7010 | Location ref, |
| 7011 | vixl32::Register obj, |
| 7012 | uint32_t data_offset, |
| 7013 | Location index, |
| 7014 | Location temp, |
| 7015 | bool needs_null_check) { |
| 7016 | DCHECK(kEmitCompilerReadBarrier); |
| 7017 | DCHECK(kUseBakerReadBarrier); |
| 7018 | |
| 7019 | static_assert( |
| 7020 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 7021 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 7022 | // /* HeapReference<Object> */ ref = |
| 7023 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 7024 | ScaleFactor scale_factor = TIMES_4; |
| 7025 | GenerateReferenceLoadWithBakerReadBarrier( |
| 7026 | instruction, ref, obj, data_offset, index, scale_factor, temp, needs_null_check); |
Roland Levillain | 6070e88 | 2016-11-03 17:51:58 +0000 | [diff] [blame] | 7027 | } |
| 7028 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 7029 | void CodeGeneratorARMVIXL::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7030 | Location ref, |
| 7031 | vixl32::Register obj, |
| 7032 | uint32_t offset, |
| 7033 | Location index, |
| 7034 | ScaleFactor scale_factor, |
| 7035 | Location temp, |
| 7036 | bool needs_null_check, |
| 7037 | bool always_update_field, |
| 7038 | vixl32::Register* temp2) { |
| 7039 | DCHECK(kEmitCompilerReadBarrier); |
| 7040 | DCHECK(kUseBakerReadBarrier); |
| 7041 | |
| 7042 | // In slow path based read barriers, the read barrier call is |
| 7043 | // inserted after the original load. However, in fast path based |
| 7044 | // Baker's read barriers, we need to perform the load of |
| 7045 | // mirror::Object::monitor_ *before* the original reference load. |
| 7046 | // This load-load ordering is required by the read barrier. |
| 7047 | // The fast path/slow path (for Baker's algorithm) should look like: |
| 7048 | // |
| 7049 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 7050 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 7051 | // HeapReference<Object> ref = *src; // Original reference load. |
| 7052 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 7053 | // if (is_gray) { |
| 7054 | // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path. |
| 7055 | // } |
| 7056 | // |
| 7057 | // Note: the original implementation in ReadBarrier::Barrier is |
| 7058 | // slightly more complex as it performs additional checks that we do |
| 7059 | // not do here for performance reasons. |
| 7060 | |
| 7061 | vixl32::Register ref_reg = RegisterFrom(ref); |
| 7062 | vixl32::Register temp_reg = RegisterFrom(temp); |
| 7063 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 7064 | |
| 7065 | // /* int32_t */ monitor = obj->monitor_ |
| 7066 | GetAssembler()->LoadFromOffset(kLoadWord, temp_reg, obj, monitor_offset); |
| 7067 | if (needs_null_check) { |
| 7068 | MaybeRecordImplicitNullCheck(instruction); |
| 7069 | } |
| 7070 | // /* LockWord */ lock_word = LockWord(monitor) |
| 7071 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 7072 | "art::LockWord and int32_t have different sizes."); |
| 7073 | |
| 7074 | // Introduce a dependency on the lock_word including the rb_state, |
| 7075 | // which shall prevent load-load reordering without using |
| 7076 | // a memory barrier (which would be more expensive). |
| 7077 | // `obj` is unchanged by this operation, but its value now depends |
| 7078 | // on `temp_reg`. |
| 7079 | __ Add(obj, obj, Operand(temp_reg, ShiftType::LSR, 32)); |
| 7080 | |
| 7081 | // The actual reference load. |
| 7082 | if (index.IsValid()) { |
| 7083 | // Load types involving an "index": ArrayGet, |
| 7084 | // UnsafeGetObject/UnsafeGetObjectVolatile and UnsafeCASObject |
| 7085 | // intrinsics. |
| 7086 | // /* HeapReference<Object> */ ref = *(obj + offset + (index << scale_factor)) |
| 7087 | if (index.IsConstant()) { |
| 7088 | size_t computed_offset = |
| 7089 | (Int32ConstantFrom(index) << scale_factor) + offset; |
| 7090 | GetAssembler()->LoadFromOffset(kLoadWord, ref_reg, obj, computed_offset); |
| 7091 | } else { |
| 7092 | // Handle the special case of the |
| 7093 | // UnsafeGetObject/UnsafeGetObjectVolatile and UnsafeCASObject |
| 7094 | // intrinsics, which use a register pair as index ("long |
| 7095 | // offset"), of which only the low part contains data. |
| 7096 | vixl32::Register index_reg = index.IsRegisterPair() |
| 7097 | ? LowRegisterFrom(index) |
| 7098 | : RegisterFrom(index); |
| 7099 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 7100 | const vixl32::Register temp3 = temps.Acquire(); |
| 7101 | __ Add(temp3, obj, Operand(index_reg, ShiftType::LSL, scale_factor)); |
| 7102 | GetAssembler()->LoadFromOffset(kLoadWord, ref_reg, temp3, offset); |
| 7103 | } |
| 7104 | } else { |
| 7105 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 7106 | GetAssembler()->LoadFromOffset(kLoadWord, ref_reg, obj, offset); |
| 7107 | } |
| 7108 | |
| 7109 | // Object* ref = ref_addr->AsMirrorPtr() |
| 7110 | GetAssembler()->MaybeUnpoisonHeapReference(ref_reg); |
| 7111 | |
| 7112 | // Slow path marking the object `ref` when it is gray. |
| 7113 | SlowPathCodeARMVIXL* slow_path; |
| 7114 | if (always_update_field) { |
| 7115 | DCHECK(temp2 != nullptr); |
| 7116 | // ReadBarrierMarkAndUpdateFieldSlowPathARMVIXL only supports address |
| 7117 | // of the form `obj + field_offset`, where `obj` is a register and |
| 7118 | // `field_offset` is a register pair (of which only the lower half |
| 7119 | // is used). Thus `offset` and `scale_factor` above are expected |
| 7120 | // to be null in this code path. |
| 7121 | DCHECK_EQ(offset, 0u); |
| 7122 | DCHECK_EQ(scale_factor, ScaleFactor::TIMES_1); |
| 7123 | slow_path = new (GetGraph()->GetArena()) ReadBarrierMarkAndUpdateFieldSlowPathARMVIXL( |
| 7124 | instruction, ref, obj, /* field_offset */ index, temp_reg, *temp2); |
| 7125 | } else { |
| 7126 | slow_path = new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathARMVIXL(instruction, ref); |
| 7127 | } |
| 7128 | AddSlowPath(slow_path); |
| 7129 | |
| 7130 | // if (rb_state == ReadBarrier::GrayState()) |
| 7131 | // ref = ReadBarrier::Mark(ref); |
| 7132 | // Given the numeric representation, it's enough to check the low bit of the |
| 7133 | // rb_state. We do that by shifting the bit out of the lock word with LSRS |
| 7134 | // which can be a 16-bit instruction unlike the TST immediate. |
| 7135 | static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0"); |
| 7136 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
| 7137 | __ Lsrs(temp_reg, temp_reg, LockWord::kReadBarrierStateShift + 1); |
| 7138 | __ B(cs, slow_path->GetEntryLabel()); // Carry flag is the last bit shifted out by LSRS. |
| 7139 | __ Bind(slow_path->GetExitLabel()); |
Roland Levillain | 844e653 | 2016-11-03 16:09:47 +0000 | [diff] [blame] | 7140 | } |
| 7141 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 7142 | void CodeGeneratorARMVIXL::GenerateReadBarrierSlow(HInstruction* instruction, |
| 7143 | Location out, |
| 7144 | Location ref, |
| 7145 | Location obj, |
| 7146 | uint32_t offset, |
| 7147 | Location index) { |
| 7148 | DCHECK(kEmitCompilerReadBarrier); |
| 7149 | |
| 7150 | // Insert a slow path based read barrier *after* the reference load. |
| 7151 | // |
| 7152 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 7153 | // reference will be carried out by the runtime within the slow |
| 7154 | // path. |
| 7155 | // |
| 7156 | // Note that `ref` currently does not get unpoisoned (when heap |
| 7157 | // poisoning is enabled), which is alright as the `ref` argument is |
| 7158 | // not used by the artReadBarrierSlow entry point. |
| 7159 | // |
| 7160 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
| 7161 | SlowPathCodeARMVIXL* slow_path = new (GetGraph()->GetArena()) |
| 7162 | ReadBarrierForHeapReferenceSlowPathARMVIXL(instruction, out, ref, obj, offset, index); |
| 7163 | AddSlowPath(slow_path); |
| 7164 | |
| 7165 | __ B(slow_path->GetEntryLabel()); |
| 7166 | __ Bind(slow_path->GetExitLabel()); |
| 7167 | } |
| 7168 | |
| 7169 | void CodeGeneratorARMVIXL::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7170 | Location out, |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 7171 | Location ref, |
| 7172 | Location obj, |
| 7173 | uint32_t offset, |
| 7174 | Location index) { |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7175 | if (kEmitCompilerReadBarrier) { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 7176 | // Baker's read barriers shall be handled by the fast path |
| 7177 | // (CodeGeneratorARM::GenerateReferenceLoadWithBakerReadBarrier). |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7178 | DCHECK(!kUseBakerReadBarrier); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 7179 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 7180 | // by the runtime within the slow path. |
| 7181 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7182 | } else if (kPoisonHeapReferences) { |
| 7183 | GetAssembler()->UnpoisonHeapReference(RegisterFrom(out)); |
| 7184 | } |
| 7185 | } |
| 7186 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 7187 | void CodeGeneratorARMVIXL::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 7188 | Location out, |
| 7189 | Location root) { |
| 7190 | DCHECK(kEmitCompilerReadBarrier); |
| 7191 | |
| 7192 | // Insert a slow path based read barrier *after* the GC root load. |
| 7193 | // |
| 7194 | // Note that GC roots are not affected by heap poisoning, so we do |
| 7195 | // not need to do anything special for this here. |
| 7196 | SlowPathCodeARMVIXL* slow_path = |
| 7197 | new (GetGraph()->GetArena()) ReadBarrierForRootSlowPathARMVIXL(instruction, out, root); |
| 7198 | AddSlowPath(slow_path); |
| 7199 | |
| 7200 | __ B(slow_path->GetEntryLabel()); |
| 7201 | __ Bind(slow_path->GetExitLabel()); |
| 7202 | } |
| 7203 | |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7204 | // Check if the desired_dispatch_info is supported. If it is, return it, |
| 7205 | // otherwise return a fall-back info that should be used instead. |
| 7206 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorARMVIXL::GetSupportedInvokeStaticOrDirectDispatch( |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7207 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
| 7208 | HInvokeStaticOrDirect* invoke) { |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7209 | // TODO(VIXL): Implement optimized code paths. |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7210 | if (desired_dispatch_info.method_load_kind == |
| 7211 | HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup || |
| 7212 | desired_dispatch_info.code_ptr_location == |
| 7213 | HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup) { |
| 7214 | return { |
| 7215 | HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod, |
| 7216 | HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod, |
| 7217 | 0u, |
| 7218 | 0u |
| 7219 | }; |
| 7220 | } |
| 7221 | |
| 7222 | HInvokeStaticOrDirect::DispatchInfo dispatch_info = desired_dispatch_info; |
| 7223 | // We disable pc-relative load when there is an irreducible loop, as the optimization |
| 7224 | // is incompatible with it. |
| 7225 | // TODO: Create as many ArmDexCacheArraysBase instructions as needed for methods |
| 7226 | // with irreducible loops. |
| 7227 | if (GetGraph()->HasIrreducibleLoops() && |
| 7228 | (dispatch_info.method_load_kind == |
| 7229 | HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative)) { |
| 7230 | dispatch_info.method_load_kind = HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod; |
| 7231 | } |
| 7232 | |
| 7233 | if (dispatch_info.code_ptr_location == HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative) { |
| 7234 | const DexFile& outer_dex_file = GetGraph()->GetDexFile(); |
| 7235 | if (&outer_dex_file != invoke->GetTargetMethod().dex_file) { |
| 7236 | // Calls across dex files are more likely to exceed the available BL range, |
| 7237 | // so use absolute patch with fixup if available and kCallArtMethod otherwise. |
| 7238 | HInvokeStaticOrDirect::CodePtrLocation code_ptr_location = |
| 7239 | (desired_dispatch_info.method_load_kind == |
| 7240 | HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup) |
| 7241 | ? HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup |
| 7242 | : HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod; |
| 7243 | return HInvokeStaticOrDirect::DispatchInfo { |
| 7244 | dispatch_info.method_load_kind, |
| 7245 | code_ptr_location, |
| 7246 | dispatch_info.method_load_data, |
| 7247 | 0u |
| 7248 | }; |
| 7249 | } |
| 7250 | } |
| 7251 | return dispatch_info; |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7252 | } |
| 7253 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7254 | vixl32::Register CodeGeneratorARMVIXL::GetInvokeStaticOrDirectExtraParameter( |
| 7255 | HInvokeStaticOrDirect* invoke, vixl32::Register temp) { |
| 7256 | DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
| 7257 | Location location = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
| 7258 | if (!invoke->GetLocations()->Intrinsified()) { |
| 7259 | return RegisterFrom(location); |
| 7260 | } |
| 7261 | // For intrinsics we allow any location, so it may be on the stack. |
| 7262 | if (!location.IsRegister()) { |
| 7263 | GetAssembler()->LoadFromOffset(kLoadWord, temp, sp, location.GetStackIndex()); |
| 7264 | return temp; |
| 7265 | } |
| 7266 | // For register locations, check if the register was saved. If so, get it from the stack. |
| 7267 | // Note: There is a chance that the register was saved but not overwritten, so we could |
| 7268 | // save one load. However, since this is just an intrinsic slow path we prefer this |
| 7269 | // simple and more robust approach rather that trying to determine if that's the case. |
| 7270 | SlowPathCode* slow_path = GetCurrentSlowPath(); |
| 7271 | DCHECK(slow_path != nullptr); // For intrinsified invokes the call is emitted on the slow path. |
| 7272 | if (slow_path->IsCoreRegisterSaved(RegisterFrom(location).GetCode())) { |
| 7273 | int stack_offset = slow_path->GetStackOffsetOfCoreRegister(RegisterFrom(location).GetCode()); |
| 7274 | GetAssembler()->LoadFromOffset(kLoadWord, temp, sp, stack_offset); |
| 7275 | return temp; |
| 7276 | } |
| 7277 | return RegisterFrom(location); |
| 7278 | } |
| 7279 | |
| 7280 | void CodeGeneratorARMVIXL::GenerateStaticOrDirectCall( |
| 7281 | HInvokeStaticOrDirect* invoke, Location temp) { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7282 | // For better instruction scheduling we load the direct code pointer before the method pointer. |
| 7283 | switch (invoke->GetCodePtrLocation()) { |
| 7284 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 7285 | // LR = code address from literal pool with link-time patch. |
| 7286 | TODO_VIXL32(FATAL); |
| 7287 | break; |
| 7288 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
| 7289 | // LR = invoke->GetDirectCodePtr(); |
| 7290 | __ Mov(lr, Operand::From(invoke->GetDirectCodePtr())); |
| 7291 | break; |
| 7292 | default: |
| 7293 | break; |
| 7294 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7295 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7296 | 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] | 7297 | switch (invoke->GetMethodLoadKind()) { |
| 7298 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: { |
| 7299 | uint32_t offset = |
| 7300 | GetThreadOffset<kArmPointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
| 7301 | // temp = thread->string_init_entrypoint |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7302 | GetAssembler()->LoadFromOffset(kLoadWord, RegisterFrom(temp), tr, offset); |
| 7303 | break; |
| 7304 | } |
| 7305 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
| 7306 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
| 7307 | break; |
| 7308 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 7309 | __ Mov(RegisterFrom(temp), Operand::From(invoke->GetMethodAddress())); |
| 7310 | break; |
| 7311 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup: |
| 7312 | TODO_VIXL32(FATAL); |
| 7313 | break; |
| 7314 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: { |
| 7315 | HArmDexCacheArraysBase* base = |
| 7316 | invoke->InputAt(invoke->GetSpecialInputIndex())->AsArmDexCacheArraysBase(); |
| 7317 | vixl32::Register base_reg = GetInvokeStaticOrDirectExtraParameter(invoke, RegisterFrom(temp)); |
| 7318 | int32_t offset = invoke->GetDexCacheArrayOffset() - base->GetElementOffset(); |
| 7319 | GetAssembler()->LoadFromOffset(kLoadWord, RegisterFrom(temp), base_reg, offset); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7320 | break; |
| 7321 | } |
| 7322 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: { |
| 7323 | Location current_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
| 7324 | vixl32::Register method_reg; |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7325 | vixl32::Register reg = RegisterFrom(temp); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7326 | if (current_method.IsRegister()) { |
| 7327 | method_reg = RegisterFrom(current_method); |
| 7328 | } else { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7329 | DCHECK(invoke->GetLocations()->Intrinsified()); |
| 7330 | DCHECK(!current_method.IsValid()); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7331 | method_reg = reg; |
| 7332 | GetAssembler()->LoadFromOffset(kLoadWord, reg, sp, kCurrentMethodStackOffset); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7333 | } |
| 7334 | // /* ArtMethod*[] */ temp = temp.ptr_sized_fields_->dex_cache_resolved_methods_; |
| 7335 | GetAssembler()->LoadFromOffset( |
| 7336 | kLoadWord, |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7337 | reg, |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7338 | method_reg, |
| 7339 | ArtMethod::DexCacheResolvedMethodsOffset(kArmPointerSize).Int32Value()); |
| 7340 | // temp = temp[index_in_cache]; |
| 7341 | // Note: Don't use invoke->GetTargetMethod() as it may point to a different dex file. |
| 7342 | uint32_t index_in_cache = invoke->GetDexMethodIndex(); |
| 7343 | GetAssembler()->LoadFromOffset( |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7344 | kLoadWord, reg, reg, CodeGenerator::GetCachePointerOffset(index_in_cache)); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7345 | break; |
| 7346 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7347 | } |
| 7348 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7349 | switch (invoke->GetCodePtrLocation()) { |
| 7350 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 7351 | __ Bl(GetFrameEntryLabel()); |
| 7352 | break; |
| 7353 | case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative: |
| 7354 | relative_call_patches_.emplace_back(*invoke->GetTargetMethod().dex_file, |
| 7355 | invoke->GetTargetMethod().dex_method_index); |
| 7356 | { |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 7357 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 7358 | vixl32::kMaxInstructionSizeInBytes, |
| 7359 | CodeBufferCheckScope::kMaximumSize); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7360 | __ bind(&relative_call_patches_.back().label); |
| 7361 | // Arbitrarily branch to the BL itself, override at link time. |
| 7362 | __ bl(&relative_call_patches_.back().label); |
| 7363 | } |
| 7364 | break; |
| 7365 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 7366 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
| 7367 | // LR prepared above for better instruction scheduling. |
| 7368 | // LR() |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 7369 | { |
| 7370 | // 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] | 7371 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 7372 | vixl32::k16BitT32InstructionSizeInBytes, |
| 7373 | CodeBufferCheckScope::kExactSize); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 7374 | __ blx(lr); |
| 7375 | } |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7376 | break; |
| 7377 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 7378 | // LR = callee_method->entry_point_from_quick_compiled_code_ |
| 7379 | GetAssembler()->LoadFromOffset( |
| 7380 | kLoadWord, |
| 7381 | lr, |
| 7382 | RegisterFrom(callee_method), |
| 7383 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize).Int32Value()); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 7384 | { |
| 7385 | // 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] | 7386 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 7387 | vixl32::k16BitT32InstructionSizeInBytes, |
| 7388 | CodeBufferCheckScope::kExactSize); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 7389 | // LR() |
| 7390 | __ blx(lr); |
| 7391 | } |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7392 | break; |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7393 | } |
| 7394 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7395 | DCHECK(!IsLeafMethod()); |
| 7396 | } |
| 7397 | |
| 7398 | void CodeGeneratorARMVIXL::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_location) { |
| 7399 | vixl32::Register temp = RegisterFrom(temp_location); |
| 7400 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 7401 | invoke->GetVTableIndex(), kArmPointerSize).Uint32Value(); |
| 7402 | |
| 7403 | // Use the calling convention instead of the location of the receiver, as |
| 7404 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 7405 | // slow path, the arguments have been moved to the right place, so here we are |
| 7406 | // guaranteed that the receiver is the first register of the calling convention. |
| 7407 | InvokeDexCallingConventionARMVIXL calling_convention; |
| 7408 | vixl32::Register receiver = calling_convention.GetRegisterAt(0); |
| 7409 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 7410 | { |
| 7411 | // Make sure the pc is recorded immediately after the `ldr` instruction. |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 7412 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 7413 | vixl32::kMaxInstructionSizeInBytes, |
| 7414 | CodeBufferCheckScope::kMaximumSize); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 7415 | // /* HeapReference<Class> */ temp = receiver->klass_ |
| 7416 | __ ldr(temp, MemOperand(receiver, class_offset)); |
| 7417 | MaybeRecordImplicitNullCheck(invoke); |
| 7418 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7419 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 7420 | // emit a read barrier for the previous class reference load. |
| 7421 | // However this is not required in practice, as this is an |
| 7422 | // intermediate/temporary reference and because the current |
| 7423 | // concurrent copying collector keeps the from-space memory |
| 7424 | // intact/accessible until the end of the marking phase (the |
| 7425 | // concurrent copying collector may not in the future). |
| 7426 | GetAssembler()->MaybeUnpoisonHeapReference(temp); |
| 7427 | |
| 7428 | // temp = temp->GetMethodAt(method_offset); |
| 7429 | uint32_t entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
| 7430 | kArmPointerSize).Int32Value(); |
| 7431 | GetAssembler()->LoadFromOffset(kLoadWord, temp, temp, method_offset); |
| 7432 | // LR = temp->GetEntryPoint(); |
| 7433 | GetAssembler()->LoadFromOffset(kLoadWord, lr, temp, entry_point); |
| 7434 | // LR(); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 7435 | // This `blx` *must* be the *last* instruction generated by this stub, so that calls to |
| 7436 | // `RecordPcInfo()` immediately following record the correct pc. Use a scope to help guarantee |
| 7437 | // that. |
| 7438 | // 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] | 7439 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 7440 | vixl32::k16BitT32InstructionSizeInBytes, |
| 7441 | CodeBufferCheckScope::kExactSize); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 7442 | __ blx(lr); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7443 | } |
| 7444 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7445 | CodeGeneratorARMVIXL::PcRelativePatchInfo* CodeGeneratorARMVIXL::NewPcRelativeStringPatch( |
| 7446 | const DexFile& dex_file, uint32_t string_index) { |
| 7447 | return NewPcRelativePatch(dex_file, string_index, &pc_relative_string_patches_); |
| 7448 | } |
| 7449 | |
| 7450 | CodeGeneratorARMVIXL::PcRelativePatchInfo* CodeGeneratorARMVIXL::NewPcRelativeTypePatch( |
| 7451 | const DexFile& dex_file, dex::TypeIndex type_index) { |
| 7452 | return NewPcRelativePatch(dex_file, type_index.index_, &pc_relative_type_patches_); |
| 7453 | } |
| 7454 | |
| 7455 | CodeGeneratorARMVIXL::PcRelativePatchInfo* CodeGeneratorARMVIXL::NewPcRelativeDexCacheArrayPatch( |
| 7456 | const DexFile& dex_file, uint32_t element_offset) { |
| 7457 | return NewPcRelativePatch(dex_file, element_offset, &pc_relative_dex_cache_patches_); |
| 7458 | } |
| 7459 | |
| 7460 | CodeGeneratorARMVIXL::PcRelativePatchInfo* CodeGeneratorARMVIXL::NewPcRelativePatch( |
| 7461 | const DexFile& dex_file, uint32_t offset_or_index, ArenaDeque<PcRelativePatchInfo>* patches) { |
| 7462 | patches->emplace_back(dex_file, offset_or_index); |
| 7463 | return &patches->back(); |
| 7464 | } |
| 7465 | |
| 7466 | template <LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
| 7467 | inline void CodeGeneratorARMVIXL::EmitPcRelativeLinkerPatches( |
| 7468 | const ArenaDeque<PcRelativePatchInfo>& infos, |
| 7469 | ArenaVector<LinkerPatch>* linker_patches) { |
| 7470 | for (const PcRelativePatchInfo& info : infos) { |
| 7471 | const DexFile& dex_file = info.target_dex_file; |
| 7472 | size_t offset_or_index = info.offset_or_index; |
| 7473 | DCHECK(info.add_pc_label.IsBound()); |
| 7474 | uint32_t add_pc_offset = dchecked_integral_cast<uint32_t>(info.add_pc_label.GetLocation()); |
| 7475 | // Add MOVW patch. |
| 7476 | DCHECK(info.movw_label.IsBound()); |
| 7477 | uint32_t movw_offset = dchecked_integral_cast<uint32_t>(info.movw_label.GetLocation()); |
| 7478 | linker_patches->push_back(Factory(movw_offset, &dex_file, add_pc_offset, offset_or_index)); |
| 7479 | // Add MOVT patch. |
| 7480 | DCHECK(info.movt_label.IsBound()); |
| 7481 | uint32_t movt_offset = dchecked_integral_cast<uint32_t>(info.movt_label.GetLocation()); |
| 7482 | linker_patches->push_back(Factory(movt_offset, &dex_file, add_pc_offset, offset_or_index)); |
| 7483 | } |
| 7484 | } |
| 7485 | |
| 7486 | void CodeGeneratorARMVIXL::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) { |
| 7487 | DCHECK(linker_patches->empty()); |
| 7488 | size_t size = |
| 7489 | relative_call_patches_.size() + |
| 7490 | /* MOVW+MOVT for each entry */ 2u * pc_relative_dex_cache_patches_.size() + |
| 7491 | /* MOVW+MOVT for each entry */ 2u * pc_relative_string_patches_.size() + |
| 7492 | /* MOVW+MOVT for each entry */ 2u * pc_relative_type_patches_.size(); |
| 7493 | linker_patches->reserve(size); |
| 7494 | for (const PatchInfo<vixl32::Label>& info : relative_call_patches_) { |
| 7495 | uint32_t literal_offset = info.label.GetLocation(); |
| 7496 | linker_patches->push_back( |
| 7497 | LinkerPatch::RelativeCodePatch(literal_offset, &info.dex_file, info.index)); |
| 7498 | } |
| 7499 | EmitPcRelativeLinkerPatches<LinkerPatch::DexCacheArrayPatch>(pc_relative_dex_cache_patches_, |
| 7500 | linker_patches); |
| 7501 | if (!GetCompilerOptions().IsBootImage()) { |
| 7502 | EmitPcRelativeLinkerPatches<LinkerPatch::StringBssEntryPatch>(pc_relative_string_patches_, |
| 7503 | linker_patches); |
| 7504 | } else { |
| 7505 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeStringPatch>(pc_relative_string_patches_, |
| 7506 | linker_patches); |
| 7507 | } |
| 7508 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeTypePatch>(pc_relative_type_patches_, |
| 7509 | linker_patches); |
| 7510 | } |
| 7511 | |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 7512 | void LocationsBuilderARMVIXL::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
| 7513 | LocationSummary* locations = |
| 7514 | new (GetGraph()->GetArena()) LocationSummary(instr, LocationSummary::kNoCall); |
| 7515 | locations->SetInAt(HMultiplyAccumulate::kInputAccumulatorIndex, |
| 7516 | Location::RequiresRegister()); |
| 7517 | locations->SetInAt(HMultiplyAccumulate::kInputMulLeftIndex, Location::RequiresRegister()); |
| 7518 | locations->SetInAt(HMultiplyAccumulate::kInputMulRightIndex, Location::RequiresRegister()); |
| 7519 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 7520 | } |
| 7521 | |
| 7522 | void InstructionCodeGeneratorARMVIXL::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
| 7523 | vixl32::Register res = OutputRegister(instr); |
| 7524 | vixl32::Register accumulator = |
| 7525 | InputRegisterAt(instr, HMultiplyAccumulate::kInputAccumulatorIndex); |
| 7526 | vixl32::Register mul_left = |
| 7527 | InputRegisterAt(instr, HMultiplyAccumulate::kInputMulLeftIndex); |
| 7528 | vixl32::Register mul_right = |
| 7529 | InputRegisterAt(instr, HMultiplyAccumulate::kInputMulRightIndex); |
| 7530 | |
| 7531 | if (instr->GetOpKind() == HInstruction::kAdd) { |
| 7532 | __ Mla(res, mul_left, mul_right, accumulator); |
| 7533 | } else { |
| 7534 | __ Mls(res, mul_left, mul_right, accumulator); |
| 7535 | } |
| 7536 | } |
| 7537 | |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 7538 | void LocationsBuilderARMVIXL::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
| 7539 | // Nothing to do, this should be removed during prepare for register allocator. |
| 7540 | LOG(FATAL) << "Unreachable"; |
| 7541 | } |
| 7542 | |
| 7543 | void InstructionCodeGeneratorARMVIXL::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
| 7544 | // Nothing to do, this should be removed during prepare for register allocator. |
| 7545 | LOG(FATAL) << "Unreachable"; |
| 7546 | } |
| 7547 | |
| 7548 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 7549 | void LocationsBuilderARMVIXL::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 7550 | LocationSummary* locations = |
| 7551 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 7552 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7553 | if (switch_instr->GetNumEntries() > kPackedSwitchCompareJumpThreshold && |
| 7554 | codegen_->GetAssembler()->GetVIXLAssembler()->IsUsingT32()) { |
| 7555 | locations->AddTemp(Location::RequiresRegister()); // We need a temp for the table base. |
| 7556 | if (switch_instr->GetStartValue() != 0) { |
| 7557 | locations->AddTemp(Location::RequiresRegister()); // We need a temp for the bias. |
| 7558 | } |
| 7559 | } |
| 7560 | } |
| 7561 | |
| 7562 | // TODO(VIXL): Investigate and reach the parity with old arm codegen. |
| 7563 | void InstructionCodeGeneratorARMVIXL::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 7564 | int32_t lower_bound = switch_instr->GetStartValue(); |
| 7565 | uint32_t num_entries = switch_instr->GetNumEntries(); |
| 7566 | LocationSummary* locations = switch_instr->GetLocations(); |
| 7567 | vixl32::Register value_reg = InputRegisterAt(switch_instr, 0); |
| 7568 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 7569 | |
| 7570 | if (num_entries <= kPackedSwitchCompareJumpThreshold || |
| 7571 | !codegen_->GetAssembler()->GetVIXLAssembler()->IsUsingT32()) { |
| 7572 | // Create a series of compare/jumps. |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 7573 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 7574 | vixl32::Register temp_reg = temps.Acquire(); |
| 7575 | // Note: It is fine for the below AddConstantSetFlags() using IP register to temporarily store |
| 7576 | // the immediate, because IP is used as the destination register. For the other |
| 7577 | // AddConstantSetFlags() and GenerateCompareWithImmediate(), the immediate values are constant, |
| 7578 | // and they can be encoded in the instruction without making use of IP register. |
| 7579 | __ Adds(temp_reg, value_reg, -lower_bound); |
| 7580 | |
| 7581 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
| 7582 | // Jump to successors[0] if value == lower_bound. |
| 7583 | __ B(eq, codegen_->GetLabelOf(successors[0])); |
| 7584 | int32_t last_index = 0; |
| 7585 | for (; num_entries - last_index > 2; last_index += 2) { |
| 7586 | __ Adds(temp_reg, temp_reg, -2); |
| 7587 | // Jump to successors[last_index + 1] if value < case_value[last_index + 2]. |
| 7588 | __ B(lo, codegen_->GetLabelOf(successors[last_index + 1])); |
| 7589 | // Jump to successors[last_index + 2] if value == case_value[last_index + 2]. |
| 7590 | __ B(eq, codegen_->GetLabelOf(successors[last_index + 2])); |
| 7591 | } |
| 7592 | if (num_entries - last_index == 2) { |
| 7593 | // The last missing case_value. |
| 7594 | __ Cmp(temp_reg, 1); |
| 7595 | __ B(eq, codegen_->GetLabelOf(successors[last_index + 1])); |
| 7596 | } |
| 7597 | |
| 7598 | // And the default for any other value. |
| 7599 | if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) { |
| 7600 | __ B(codegen_->GetLabelOf(default_block)); |
| 7601 | } |
| 7602 | } else { |
| 7603 | // Create a table lookup. |
| 7604 | vixl32::Register table_base = RegisterFrom(locations->GetTemp(0)); |
| 7605 | |
| 7606 | JumpTableARMVIXL* jump_table = codegen_->CreateJumpTable(switch_instr); |
| 7607 | |
| 7608 | // Remove the bias. |
| 7609 | vixl32::Register key_reg; |
| 7610 | if (lower_bound != 0) { |
| 7611 | key_reg = RegisterFrom(locations->GetTemp(1)); |
| 7612 | __ Sub(key_reg, value_reg, lower_bound); |
| 7613 | } else { |
| 7614 | key_reg = value_reg; |
| 7615 | } |
| 7616 | |
| 7617 | // Check whether the value is in the table, jump to default block if not. |
| 7618 | __ Cmp(key_reg, num_entries - 1); |
| 7619 | __ B(hi, codegen_->GetLabelOf(default_block)); |
| 7620 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 7621 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 7622 | vixl32::Register jump_offset = temps.Acquire(); |
| 7623 | |
| 7624 | // Load jump offset from the table. |
| 7625 | __ Adr(table_base, jump_table->GetTableStartLabel()); |
| 7626 | __ Ldr(jump_offset, MemOperand(table_base, key_reg, vixl32::LSL, 2)); |
| 7627 | |
| 7628 | // Jump to target block by branching to table_base(pc related) + offset. |
| 7629 | vixl32::Register target_address = table_base; |
| 7630 | __ Add(target_address, table_base, jump_offset); |
| 7631 | __ Bx(target_address); |
Artem Serov | 09a940d | 2016-11-11 16:15:11 +0000 | [diff] [blame] | 7632 | |
| 7633 | jump_table->EmitTable(codegen_); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 7634 | } |
| 7635 | } |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7636 | void LocationsBuilderARMVIXL::VisitArmDexCacheArraysBase(HArmDexCacheArraysBase* base) { |
| 7637 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(base); |
| 7638 | locations->SetOut(Location::RequiresRegister()); |
| 7639 | } |
| 7640 | |
| 7641 | void InstructionCodeGeneratorARMVIXL::VisitArmDexCacheArraysBase(HArmDexCacheArraysBase* base) { |
| 7642 | vixl32::Register base_reg = OutputRegister(base); |
| 7643 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels = |
| 7644 | codegen_->NewPcRelativeDexCacheArrayPatch(base->GetDexFile(), base->GetElementOffset()); |
| 7645 | codegen_->EmitMovwMovtPlaceholder(labels, base_reg); |
| 7646 | } |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 7647 | |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7648 | // Copy the result of a call into the given target. |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7649 | void CodeGeneratorARMVIXL::MoveFromReturnRegister(Location trg, Primitive::Type type) { |
| 7650 | if (!trg.IsValid()) { |
| 7651 | DCHECK_EQ(type, Primitive::kPrimVoid); |
| 7652 | return; |
| 7653 | } |
| 7654 | |
| 7655 | DCHECK_NE(type, Primitive::kPrimVoid); |
| 7656 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7657 | Location return_loc = InvokeDexCallingConventionVisitorARMVIXL().GetReturnLocation(type); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7658 | if (return_loc.Equals(trg)) { |
| 7659 | return; |
| 7660 | } |
| 7661 | |
| 7662 | // TODO: Consider pairs in the parallel move resolver, then this could be nicely merged |
| 7663 | // with the last branch. |
| 7664 | if (type == Primitive::kPrimLong) { |
| 7665 | TODO_VIXL32(FATAL); |
| 7666 | } else if (type == Primitive::kPrimDouble) { |
| 7667 | TODO_VIXL32(FATAL); |
| 7668 | } else { |
| 7669 | // Let the parallel move resolver take care of all of this. |
| 7670 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 7671 | parallel_move.AddMove(return_loc, trg, type, nullptr); |
| 7672 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 7673 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7674 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7675 | |
xueliang.zhong | 8d2c459 | 2016-11-23 17:05:25 +0000 | [diff] [blame] | 7676 | void LocationsBuilderARMVIXL::VisitClassTableGet(HClassTableGet* instruction) { |
| 7677 | LocationSummary* locations = |
| 7678 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 7679 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7680 | locations->SetOut(Location::RequiresRegister()); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 7681 | } |
| 7682 | |
xueliang.zhong | 8d2c459 | 2016-11-23 17:05:25 +0000 | [diff] [blame] | 7683 | void InstructionCodeGeneratorARMVIXL::VisitClassTableGet(HClassTableGet* instruction) { |
| 7684 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
| 7685 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 7686 | instruction->GetIndex(), kArmPointerSize).SizeValue(); |
| 7687 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 7688 | OutputRegister(instruction), |
| 7689 | InputRegisterAt(instruction, 0), |
| 7690 | method_offset); |
| 7691 | } else { |
| 7692 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
| 7693 | instruction->GetIndex(), kArmPointerSize)); |
| 7694 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 7695 | OutputRegister(instruction), |
| 7696 | InputRegisterAt(instruction, 0), |
| 7697 | mirror::Class::ImtPtrOffset(kArmPointerSize).Uint32Value()); |
| 7698 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 7699 | OutputRegister(instruction), |
| 7700 | OutputRegister(instruction), |
| 7701 | method_offset); |
| 7702 | } |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 7703 | } |
| 7704 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7705 | void CodeGeneratorARMVIXL::EmitMovwMovtPlaceholder( |
| 7706 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels, |
| 7707 | vixl32::Register out) { |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 7708 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 7709 | 3 * vixl32::kMaxInstructionSizeInBytes, |
| 7710 | CodeBufferCheckScope::kMaximumSize); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7711 | // TODO(VIXL): Think about using mov instead of movw. |
| 7712 | __ bind(&labels->movw_label); |
| 7713 | __ movw(out, /* placeholder */ 0u); |
| 7714 | __ bind(&labels->movt_label); |
| 7715 | __ movt(out, /* placeholder */ 0u); |
| 7716 | __ bind(&labels->add_pc_label); |
| 7717 | __ add(out, out, pc); |
| 7718 | } |
| 7719 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7720 | #undef __ |
| 7721 | #undef QUICK_ENTRY_POINT |
| 7722 | #undef TODO_VIXL32 |
| 7723 | |
| 7724 | } // namespace arm |
| 7725 | } // namespace art |