Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "code_generator_arm_vixl.h" |
| 18 | |
| 19 | #include "arch/arm/instruction_set_features_arm.h" |
| 20 | #include "art_method.h" |
| 21 | #include "code_generator_utils.h" |
| 22 | #include "common_arm.h" |
| 23 | #include "compiled_method.h" |
| 24 | #include "entrypoints/quick/quick_entrypoints.h" |
| 25 | #include "gc/accounting/card_table.h" |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 26 | #include "intrinsics_arm_vixl.h" |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 27 | #include "mirror/array-inl.h" |
| 28 | #include "mirror/class-inl.h" |
| 29 | #include "thread.h" |
| 30 | #include "utils/arm/assembler_arm_vixl.h" |
| 31 | #include "utils/arm/managed_register_arm.h" |
| 32 | #include "utils/assembler.h" |
| 33 | #include "utils/stack_checks.h" |
| 34 | |
| 35 | namespace art { |
| 36 | namespace arm { |
| 37 | |
| 38 | namespace vixl32 = vixl::aarch32; |
| 39 | using namespace vixl32; // NOLINT(build/namespaces) |
| 40 | |
Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 41 | using helpers::DRegisterFrom; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 42 | using helpers::DWARFReg; |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 43 | using helpers::HighDRegisterFrom; |
| 44 | using helpers::HighRegisterFrom; |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 45 | using helpers::InputDRegisterAt; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 46 | using helpers::InputOperandAt; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 47 | using helpers::InputRegister; |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 48 | using helpers::InputRegisterAt; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 49 | using helpers::InputSRegisterAt; |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 50 | using helpers::InputVRegister; |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 51 | using helpers::InputVRegisterAt; |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 52 | using helpers::Int32ConstantFrom; |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 53 | using helpers::Int64ConstantFrom; |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 54 | using helpers::LocationFrom; |
| 55 | using helpers::LowRegisterFrom; |
| 56 | using helpers::LowSRegisterFrom; |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 57 | using helpers::OperandFrom; |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 58 | using helpers::OutputRegister; |
| 59 | using helpers::OutputSRegister; |
| 60 | using helpers::OutputVRegister; |
| 61 | using helpers::RegisterFrom; |
| 62 | using helpers::SRegisterFrom; |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 63 | using helpers::Uint64ConstantFrom; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 64 | |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 65 | using vixl::ExactAssemblyScope; |
| 66 | using vixl::CodeBufferCheckScope; |
| 67 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 68 | using RegisterList = vixl32::RegisterList; |
| 69 | |
| 70 | static bool ExpectedPairLayout(Location location) { |
| 71 | // We expected this for both core and fpu register pairs. |
| 72 | return ((location.low() & 1) == 0) && (location.low() + 1 == location.high()); |
| 73 | } |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 74 | // Use a local definition to prevent copying mistakes. |
| 75 | static constexpr size_t kArmWordSize = static_cast<size_t>(kArmPointerSize); |
| 76 | static constexpr size_t kArmBitsPerWord = kArmWordSize * kBitsPerByte; |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 77 | static constexpr int kCurrentMethodStackOffset = 0; |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 78 | static constexpr uint32_t kPackedSwitchCompareJumpThreshold = 7; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 79 | |
| 80 | #ifdef __ |
| 81 | #error "ARM Codegen VIXL macro-assembler macro already defined." |
| 82 | #endif |
| 83 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 84 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 85 | #define __ down_cast<CodeGeneratorARMVIXL*>(codegen)->GetVIXLAssembler()-> // NOLINT |
| 86 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kArmPointerSize, x).Int32Value() |
| 87 | |
| 88 | // Marker that code is yet to be, and must, be implemented. |
| 89 | #define TODO_VIXL32(level) LOG(level) << __PRETTY_FUNCTION__ << " unimplemented " |
| 90 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 91 | // SaveLiveRegisters and RestoreLiveRegisters from SlowPathCodeARM operate on sets of S registers, |
| 92 | // for each live D registers they treat two corresponding S registers as live ones. |
| 93 | // |
| 94 | // Two following functions (SaveContiguousSRegisterList, RestoreContiguousSRegisterList) build |
| 95 | // from a list of contiguous S registers a list of contiguous D registers (processing first/last |
| 96 | // S registers corner cases) and save/restore this new list treating them as D registers. |
| 97 | // - decreasing code size |
| 98 | // - avoiding hazards on Cortex-A57, when a pair of S registers for an actual live D register is |
| 99 | // restored and then used in regular non SlowPath code as D register. |
| 100 | // |
| 101 | // For the following example (v means the S register is live): |
| 102 | // D names: | D0 | D1 | D2 | D4 | ... |
| 103 | // S names: | S0 | S1 | S2 | S3 | S4 | S5 | S6 | S7 | ... |
| 104 | // Live? | | v | v | v | v | v | v | | ... |
| 105 | // |
| 106 | // S1 and S6 will be saved/restored independently; D registers list (D1, D2) will be processed |
| 107 | // as D registers. |
| 108 | // |
| 109 | // TODO(VIXL): All this code should be unnecessary once the VIXL AArch32 backend provides helpers |
| 110 | // for lists of floating-point registers. |
| 111 | static size_t SaveContiguousSRegisterList(size_t first, |
| 112 | size_t last, |
| 113 | CodeGenerator* codegen, |
| 114 | size_t stack_offset) { |
| 115 | static_assert(kSRegSizeInBytes == kArmWordSize, "Broken assumption on reg/word sizes."); |
| 116 | static_assert(kDRegSizeInBytes == 2 * kArmWordSize, "Broken assumption on reg/word sizes."); |
| 117 | DCHECK_LE(first, last); |
| 118 | if ((first == last) && (first == 0)) { |
| 119 | __ Vstr(vixl32::SRegister(first), MemOperand(sp, stack_offset)); |
| 120 | return stack_offset + kSRegSizeInBytes; |
| 121 | } |
| 122 | if (first % 2 == 1) { |
| 123 | __ Vstr(vixl32::SRegister(first++), MemOperand(sp, stack_offset)); |
| 124 | stack_offset += kSRegSizeInBytes; |
| 125 | } |
| 126 | |
| 127 | bool save_last = false; |
| 128 | if (last % 2 == 0) { |
| 129 | save_last = true; |
| 130 | --last; |
| 131 | } |
| 132 | |
| 133 | if (first < last) { |
| 134 | vixl32::DRegister d_reg = vixl32::DRegister(first / 2); |
| 135 | DCHECK_EQ((last - first + 1) % 2, 0u); |
| 136 | size_t number_of_d_regs = (last - first + 1) / 2; |
| 137 | |
| 138 | if (number_of_d_regs == 1) { |
| 139 | __ Vstr(d_reg, MemOperand(sp, stack_offset)); |
| 140 | } else if (number_of_d_regs > 1) { |
| 141 | UseScratchRegisterScope temps(down_cast<CodeGeneratorARMVIXL*>(codegen)->GetVIXLAssembler()); |
| 142 | vixl32::Register base = sp; |
| 143 | if (stack_offset != 0) { |
| 144 | base = temps.Acquire(); |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 145 | __ Add(base, sp, Operand::From(stack_offset)); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 146 | } |
| 147 | __ Vstm(F64, base, NO_WRITE_BACK, DRegisterList(d_reg, number_of_d_regs)); |
| 148 | } |
| 149 | stack_offset += number_of_d_regs * kDRegSizeInBytes; |
| 150 | } |
| 151 | |
| 152 | if (save_last) { |
| 153 | __ Vstr(vixl32::SRegister(last + 1), MemOperand(sp, stack_offset)); |
| 154 | stack_offset += kSRegSizeInBytes; |
| 155 | } |
| 156 | |
| 157 | return stack_offset; |
| 158 | } |
| 159 | |
| 160 | static size_t RestoreContiguousSRegisterList(size_t first, |
| 161 | size_t last, |
| 162 | CodeGenerator* codegen, |
| 163 | size_t stack_offset) { |
| 164 | static_assert(kSRegSizeInBytes == kArmWordSize, "Broken assumption on reg/word sizes."); |
| 165 | static_assert(kDRegSizeInBytes == 2 * kArmWordSize, "Broken assumption on reg/word sizes."); |
| 166 | DCHECK_LE(first, last); |
| 167 | if ((first == last) && (first == 0)) { |
| 168 | __ Vldr(vixl32::SRegister(first), MemOperand(sp, stack_offset)); |
| 169 | return stack_offset + kSRegSizeInBytes; |
| 170 | } |
| 171 | if (first % 2 == 1) { |
| 172 | __ Vldr(vixl32::SRegister(first++), MemOperand(sp, stack_offset)); |
| 173 | stack_offset += kSRegSizeInBytes; |
| 174 | } |
| 175 | |
| 176 | bool restore_last = false; |
| 177 | if (last % 2 == 0) { |
| 178 | restore_last = true; |
| 179 | --last; |
| 180 | } |
| 181 | |
| 182 | if (first < last) { |
| 183 | vixl32::DRegister d_reg = vixl32::DRegister(first / 2); |
| 184 | DCHECK_EQ((last - first + 1) % 2, 0u); |
| 185 | size_t number_of_d_regs = (last - first + 1) / 2; |
| 186 | if (number_of_d_regs == 1) { |
| 187 | __ Vldr(d_reg, MemOperand(sp, stack_offset)); |
| 188 | } else if (number_of_d_regs > 1) { |
| 189 | UseScratchRegisterScope temps(down_cast<CodeGeneratorARMVIXL*>(codegen)->GetVIXLAssembler()); |
| 190 | vixl32::Register base = sp; |
| 191 | if (stack_offset != 0) { |
| 192 | base = temps.Acquire(); |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 193 | __ Add(base, sp, Operand::From(stack_offset)); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 194 | } |
| 195 | __ Vldm(F64, base, NO_WRITE_BACK, DRegisterList(d_reg, number_of_d_regs)); |
| 196 | } |
| 197 | stack_offset += number_of_d_regs * kDRegSizeInBytes; |
| 198 | } |
| 199 | |
| 200 | if (restore_last) { |
| 201 | __ Vldr(vixl32::SRegister(last + 1), MemOperand(sp, stack_offset)); |
| 202 | stack_offset += kSRegSizeInBytes; |
| 203 | } |
| 204 | |
| 205 | return stack_offset; |
| 206 | } |
| 207 | |
| 208 | void SlowPathCodeARMVIXL::SaveLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) { |
| 209 | size_t stack_offset = codegen->GetFirstRegisterSlotInSlowPath(); |
| 210 | size_t orig_offset = stack_offset; |
| 211 | |
| 212 | const uint32_t core_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ true); |
| 213 | for (uint32_t i : LowToHighBits(core_spills)) { |
| 214 | // If the register holds an object, update the stack mask. |
| 215 | if (locations->RegisterContainsObject(i)) { |
| 216 | locations->SetStackBit(stack_offset / kVRegSize); |
| 217 | } |
| 218 | DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 219 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 220 | saved_core_stack_offsets_[i] = stack_offset; |
| 221 | stack_offset += kArmWordSize; |
| 222 | } |
| 223 | |
| 224 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 225 | arm_codegen->GetAssembler()->StoreRegisterList(core_spills, orig_offset); |
| 226 | |
| 227 | uint32_t fp_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ false); |
| 228 | orig_offset = stack_offset; |
| 229 | for (uint32_t i : LowToHighBits(fp_spills)) { |
| 230 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 231 | saved_fpu_stack_offsets_[i] = stack_offset; |
| 232 | stack_offset += kArmWordSize; |
| 233 | } |
| 234 | |
| 235 | stack_offset = orig_offset; |
| 236 | while (fp_spills != 0u) { |
| 237 | uint32_t begin = CTZ(fp_spills); |
| 238 | uint32_t tmp = fp_spills + (1u << begin); |
| 239 | fp_spills &= tmp; // Clear the contiguous range of 1s. |
| 240 | uint32_t end = (tmp == 0u) ? 32u : CTZ(tmp); // CTZ(0) is undefined. |
| 241 | stack_offset = SaveContiguousSRegisterList(begin, end - 1, codegen, stack_offset); |
| 242 | } |
| 243 | DCHECK_LE(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 244 | } |
| 245 | |
| 246 | void SlowPathCodeARMVIXL::RestoreLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) { |
| 247 | size_t stack_offset = codegen->GetFirstRegisterSlotInSlowPath(); |
| 248 | size_t orig_offset = stack_offset; |
| 249 | |
| 250 | const uint32_t core_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ true); |
| 251 | for (uint32_t i : LowToHighBits(core_spills)) { |
| 252 | DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 253 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 254 | stack_offset += kArmWordSize; |
| 255 | } |
| 256 | |
| 257 | // TODO(VIXL): Check the coherency of stack_offset after this with a test. |
| 258 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 259 | arm_codegen->GetAssembler()->LoadRegisterList(core_spills, orig_offset); |
| 260 | |
| 261 | uint32_t fp_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ false); |
| 262 | while (fp_spills != 0u) { |
| 263 | uint32_t begin = CTZ(fp_spills); |
| 264 | uint32_t tmp = fp_spills + (1u << begin); |
| 265 | fp_spills &= tmp; // Clear the contiguous range of 1s. |
| 266 | uint32_t end = (tmp == 0u) ? 32u : CTZ(tmp); // CTZ(0) is undefined. |
| 267 | stack_offset = RestoreContiguousSRegisterList(begin, end - 1, codegen, stack_offset); |
| 268 | } |
| 269 | DCHECK_LE(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 270 | } |
| 271 | |
| 272 | class NullCheckSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 273 | public: |
| 274 | explicit NullCheckSlowPathARMVIXL(HNullCheck* instruction) : SlowPathCodeARMVIXL(instruction) {} |
| 275 | |
| 276 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 277 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 278 | __ Bind(GetEntryLabel()); |
| 279 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 280 | // Live registers will be restored in the catch block if caught. |
| 281 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 282 | } |
| 283 | arm_codegen->InvokeRuntime(kQuickThrowNullPointer, |
| 284 | instruction_, |
| 285 | instruction_->GetDexPc(), |
| 286 | this); |
| 287 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); |
| 288 | } |
| 289 | |
| 290 | bool IsFatal() const OVERRIDE { return true; } |
| 291 | |
| 292 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathARMVIXL"; } |
| 293 | |
| 294 | private: |
| 295 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathARMVIXL); |
| 296 | }; |
| 297 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 298 | class DivZeroCheckSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 299 | public: |
| 300 | explicit DivZeroCheckSlowPathARMVIXL(HDivZeroCheck* instruction) |
| 301 | : SlowPathCodeARMVIXL(instruction) {} |
| 302 | |
| 303 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 304 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 305 | __ Bind(GetEntryLabel()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 306 | arm_codegen->InvokeRuntime(kQuickThrowDivZero, instruction_, instruction_->GetDexPc(), this); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 307 | CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); |
| 308 | } |
| 309 | |
| 310 | bool IsFatal() const OVERRIDE { return true; } |
| 311 | |
| 312 | const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathARMVIXL"; } |
| 313 | |
| 314 | private: |
| 315 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathARMVIXL); |
| 316 | }; |
| 317 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 318 | class SuspendCheckSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 319 | public: |
| 320 | SuspendCheckSlowPathARMVIXL(HSuspendCheck* instruction, HBasicBlock* successor) |
| 321 | : SlowPathCodeARMVIXL(instruction), successor_(successor) {} |
| 322 | |
| 323 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 324 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 325 | __ Bind(GetEntryLabel()); |
| 326 | arm_codegen->InvokeRuntime(kQuickTestSuspend, instruction_, instruction_->GetDexPc(), this); |
| 327 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
| 328 | if (successor_ == nullptr) { |
| 329 | __ B(GetReturnLabel()); |
| 330 | } else { |
| 331 | __ B(arm_codegen->GetLabelOf(successor_)); |
| 332 | } |
| 333 | } |
| 334 | |
| 335 | vixl32::Label* GetReturnLabel() { |
| 336 | DCHECK(successor_ == nullptr); |
| 337 | return &return_label_; |
| 338 | } |
| 339 | |
| 340 | HBasicBlock* GetSuccessor() const { |
| 341 | return successor_; |
| 342 | } |
| 343 | |
| 344 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathARMVIXL"; } |
| 345 | |
| 346 | private: |
| 347 | // If not null, the block to branch to after the suspend check. |
| 348 | HBasicBlock* const successor_; |
| 349 | |
| 350 | // If `successor_` is null, the label to branch to after the suspend check. |
| 351 | vixl32::Label return_label_; |
| 352 | |
| 353 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathARMVIXL); |
| 354 | }; |
| 355 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 356 | class BoundsCheckSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 357 | public: |
| 358 | explicit BoundsCheckSlowPathARMVIXL(HBoundsCheck* instruction) |
| 359 | : SlowPathCodeARMVIXL(instruction) {} |
| 360 | |
| 361 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 362 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 363 | LocationSummary* locations = instruction_->GetLocations(); |
| 364 | |
| 365 | __ Bind(GetEntryLabel()); |
| 366 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 367 | // Live registers will be restored in the catch block if caught. |
| 368 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 369 | } |
| 370 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 371 | // move resolver. |
| 372 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 373 | codegen->EmitParallelMoves( |
| 374 | locations->InAt(0), |
| 375 | LocationFrom(calling_convention.GetRegisterAt(0)), |
| 376 | Primitive::kPrimInt, |
| 377 | locations->InAt(1), |
| 378 | LocationFrom(calling_convention.GetRegisterAt(1)), |
| 379 | Primitive::kPrimInt); |
| 380 | QuickEntrypointEnum entrypoint = instruction_->AsBoundsCheck()->IsStringCharAt() |
| 381 | ? kQuickThrowStringBounds |
| 382 | : kQuickThrowArrayBounds; |
| 383 | arm_codegen->InvokeRuntime(entrypoint, instruction_, instruction_->GetDexPc(), this); |
| 384 | CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>(); |
| 385 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
| 386 | } |
| 387 | |
| 388 | bool IsFatal() const OVERRIDE { return true; } |
| 389 | |
| 390 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathARMVIXL"; } |
| 391 | |
| 392 | private: |
| 393 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathARMVIXL); |
| 394 | }; |
| 395 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 396 | class LoadClassSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 397 | public: |
| 398 | LoadClassSlowPathARMVIXL(HLoadClass* cls, HInstruction* at, uint32_t dex_pc, bool do_clinit) |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 399 | : SlowPathCodeARMVIXL(at), cls_(cls), dex_pc_(dex_pc), do_clinit_(do_clinit) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 400 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 401 | } |
| 402 | |
| 403 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 404 | LocationSummary* locations = instruction_->GetLocations(); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 405 | Location out = locations->Out(); |
| 406 | constexpr bool call_saves_everything_except_r0 = (!kUseReadBarrier || kUseBakerReadBarrier); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 407 | |
| 408 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 409 | __ Bind(GetEntryLabel()); |
| 410 | SaveLiveRegisters(codegen, locations); |
| 411 | |
| 412 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 413 | // For HLoadClass/kBssEntry/kSaveEverything, make sure we preserve the address of the entry. |
| 414 | DCHECK_EQ(instruction_->IsLoadClass(), cls_ == instruction_); |
| 415 | bool is_load_class_bss_entry = |
| 416 | (cls_ == instruction_) && (cls_->GetLoadKind() == HLoadClass::LoadKind::kBssEntry); |
| 417 | vixl32::Register entry_address; |
| 418 | if (is_load_class_bss_entry && call_saves_everything_except_r0) { |
| 419 | vixl32::Register temp = RegisterFrom(locations->GetTemp(0)); |
| 420 | // In the unlucky case that the `temp` is R0, we preserve the address in `out` across |
| 421 | // the kSaveEverything call. |
| 422 | bool temp_is_r0 = temp.Is(calling_convention.GetRegisterAt(0)); |
| 423 | entry_address = temp_is_r0 ? RegisterFrom(out) : temp; |
| 424 | DCHECK(!entry_address.Is(calling_convention.GetRegisterAt(0))); |
| 425 | if (temp_is_r0) { |
| 426 | __ Mov(entry_address, temp); |
| 427 | } |
| 428 | } |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 429 | dex::TypeIndex type_index = cls_->GetTypeIndex(); |
| 430 | __ Mov(calling_convention.GetRegisterAt(0), type_index.index_); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 431 | QuickEntrypointEnum entrypoint = do_clinit_ ? kQuickInitializeStaticStorage |
| 432 | : kQuickInitializeType; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 433 | arm_codegen->InvokeRuntime(entrypoint, instruction_, dex_pc_, this); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 434 | if (do_clinit_) { |
| 435 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>(); |
| 436 | } else { |
| 437 | CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>(); |
| 438 | } |
| 439 | |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 440 | // For HLoadClass/kBssEntry, store the resolved Class to the BSS entry. |
| 441 | if (is_load_class_bss_entry) { |
| 442 | if (call_saves_everything_except_r0) { |
| 443 | // The class entry address was preserved in `entry_address` thanks to kSaveEverything. |
| 444 | __ Str(r0, MemOperand(entry_address)); |
| 445 | } else { |
| 446 | // For non-Baker read barrier, we need to re-calculate the address of the string entry. |
| 447 | UseScratchRegisterScope temps( |
| 448 | down_cast<CodeGeneratorARMVIXL*>(codegen)->GetVIXLAssembler()); |
| 449 | vixl32::Register temp = temps.Acquire(); |
| 450 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels = |
| 451 | arm_codegen->NewTypeBssEntryPatch(cls_->GetDexFile(), type_index); |
| 452 | arm_codegen->EmitMovwMovtPlaceholder(labels, temp); |
| 453 | __ Str(r0, MemOperand(temp)); |
| 454 | } |
| 455 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 456 | // Move the class to the desired location. |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 457 | if (out.IsValid()) { |
| 458 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
| 459 | arm_codegen->Move32(locations->Out(), LocationFrom(r0)); |
| 460 | } |
| 461 | RestoreLiveRegisters(codegen, locations); |
| 462 | __ B(GetExitLabel()); |
| 463 | } |
| 464 | |
| 465 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathARMVIXL"; } |
| 466 | |
| 467 | private: |
| 468 | // The class this slow path will load. |
| 469 | HLoadClass* const cls_; |
| 470 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 471 | // The dex PC of `at_`. |
| 472 | const uint32_t dex_pc_; |
| 473 | |
| 474 | // Whether to initialize the class. |
| 475 | const bool do_clinit_; |
| 476 | |
| 477 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathARMVIXL); |
| 478 | }; |
| 479 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 480 | class LoadStringSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 481 | public: |
| 482 | explicit LoadStringSlowPathARMVIXL(HLoadString* instruction) |
| 483 | : SlowPathCodeARMVIXL(instruction) {} |
| 484 | |
| 485 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 486 | DCHECK(instruction_->IsLoadString()); |
| 487 | DCHECK_EQ(instruction_->AsLoadString()->GetLoadKind(), HLoadString::LoadKind::kBssEntry); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 488 | LocationSummary* locations = instruction_->GetLocations(); |
| 489 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 490 | HLoadString* load = instruction_->AsLoadString(); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 491 | const dex::StringIndex string_index = load->GetStringIndex(); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 492 | vixl32::Register out = OutputRegister(load); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 493 | constexpr bool call_saves_everything_except_r0 = (!kUseReadBarrier || kUseBakerReadBarrier); |
| 494 | |
| 495 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 496 | __ Bind(GetEntryLabel()); |
| 497 | SaveLiveRegisters(codegen, locations); |
| 498 | |
| 499 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 500 | // In the unlucky case that the `temp` is R0, we preserve the address in `out` across |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 501 | // the kSaveEverything call. |
| 502 | vixl32::Register entry_address; |
| 503 | if (call_saves_everything_except_r0) { |
| 504 | vixl32::Register temp = RegisterFrom(locations->GetTemp(0)); |
| 505 | bool temp_is_r0 = (temp.Is(calling_convention.GetRegisterAt(0))); |
| 506 | entry_address = temp_is_r0 ? out : temp; |
| 507 | DCHECK(!entry_address.Is(calling_convention.GetRegisterAt(0))); |
| 508 | if (temp_is_r0) { |
| 509 | __ Mov(entry_address, temp); |
| 510 | } |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 511 | } |
| 512 | |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 513 | __ Mov(calling_convention.GetRegisterAt(0), string_index.index_); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 514 | arm_codegen->InvokeRuntime(kQuickResolveString, instruction_, instruction_->GetDexPc(), this); |
| 515 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
| 516 | |
| 517 | // Store the resolved String to the .bss entry. |
| 518 | if (call_saves_everything_except_r0) { |
| 519 | // The string entry address was preserved in `entry_address` thanks to kSaveEverything. |
| 520 | __ Str(r0, MemOperand(entry_address)); |
| 521 | } else { |
| 522 | // For non-Baker read barrier, we need to re-calculate the address of the string entry. |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 523 | UseScratchRegisterScope temps( |
| 524 | down_cast<CodeGeneratorARMVIXL*>(codegen)->GetVIXLAssembler()); |
| 525 | vixl32::Register temp = temps.Acquire(); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 526 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels = |
| 527 | arm_codegen->NewPcRelativeStringPatch(load->GetDexFile(), string_index); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 528 | arm_codegen->EmitMovwMovtPlaceholder(labels, temp); |
| 529 | __ Str(r0, MemOperand(temp)); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 530 | } |
| 531 | |
| 532 | arm_codegen->Move32(locations->Out(), LocationFrom(r0)); |
| 533 | RestoreLiveRegisters(codegen, locations); |
| 534 | |
| 535 | __ B(GetExitLabel()); |
| 536 | } |
| 537 | |
| 538 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathARMVIXL"; } |
| 539 | |
| 540 | private: |
| 541 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathARMVIXL); |
| 542 | }; |
| 543 | |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 544 | class TypeCheckSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 545 | public: |
| 546 | TypeCheckSlowPathARMVIXL(HInstruction* instruction, bool is_fatal) |
| 547 | : SlowPathCodeARMVIXL(instruction), is_fatal_(is_fatal) {} |
| 548 | |
| 549 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 550 | LocationSummary* locations = instruction_->GetLocations(); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 551 | DCHECK(instruction_->IsCheckCast() |
| 552 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 553 | |
| 554 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 555 | __ Bind(GetEntryLabel()); |
| 556 | |
| 557 | if (!is_fatal_) { |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 558 | SaveLiveRegisters(codegen, locations); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 559 | } |
| 560 | |
| 561 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 562 | // move resolver. |
| 563 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 564 | |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 565 | codegen->EmitParallelMoves(locations->InAt(0), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 566 | LocationFrom(calling_convention.GetRegisterAt(0)), |
| 567 | Primitive::kPrimNot, |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 568 | locations->InAt(1), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 569 | LocationFrom(calling_convention.GetRegisterAt(1)), |
| 570 | Primitive::kPrimNot); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 571 | if (instruction_->IsInstanceOf()) { |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 572 | arm_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, |
| 573 | instruction_, |
| 574 | instruction_->GetDexPc(), |
| 575 | this); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 576 | CheckEntrypointTypes<kQuickInstanceofNonTrivial, size_t, mirror::Object*, mirror::Class*>(); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 577 | arm_codegen->Move32(locations->Out(), LocationFrom(r0)); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 578 | } else { |
| 579 | DCHECK(instruction_->IsCheckCast()); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 580 | arm_codegen->InvokeRuntime(kQuickCheckInstanceOf, |
| 581 | instruction_, |
| 582 | instruction_->GetDexPc(), |
| 583 | this); |
| 584 | CheckEntrypointTypes<kQuickCheckInstanceOf, void, mirror::Object*, mirror::Class*>(); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 585 | } |
| 586 | |
| 587 | if (!is_fatal_) { |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 588 | RestoreLiveRegisters(codegen, locations); |
| 589 | __ B(GetExitLabel()); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 590 | } |
| 591 | } |
| 592 | |
| 593 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathARMVIXL"; } |
| 594 | |
| 595 | bool IsFatal() const OVERRIDE { return is_fatal_; } |
| 596 | |
| 597 | private: |
| 598 | const bool is_fatal_; |
| 599 | |
| 600 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathARMVIXL); |
| 601 | }; |
| 602 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 603 | class DeoptimizationSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 604 | public: |
| 605 | explicit DeoptimizationSlowPathARMVIXL(HDeoptimize* instruction) |
| 606 | : SlowPathCodeARMVIXL(instruction) {} |
| 607 | |
| 608 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 609 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 610 | __ Bind(GetEntryLabel()); |
| 611 | arm_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this); |
| 612 | CheckEntrypointTypes<kQuickDeoptimize, void, void>(); |
| 613 | } |
| 614 | |
| 615 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathARMVIXL"; } |
| 616 | |
| 617 | private: |
| 618 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathARMVIXL); |
| 619 | }; |
| 620 | |
| 621 | class ArraySetSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 622 | public: |
| 623 | explicit ArraySetSlowPathARMVIXL(HInstruction* instruction) : SlowPathCodeARMVIXL(instruction) {} |
| 624 | |
| 625 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 626 | LocationSummary* locations = instruction_->GetLocations(); |
| 627 | __ Bind(GetEntryLabel()); |
| 628 | SaveLiveRegisters(codegen, locations); |
| 629 | |
| 630 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 631 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 632 | parallel_move.AddMove( |
| 633 | locations->InAt(0), |
| 634 | LocationFrom(calling_convention.GetRegisterAt(0)), |
| 635 | Primitive::kPrimNot, |
| 636 | nullptr); |
| 637 | parallel_move.AddMove( |
| 638 | locations->InAt(1), |
| 639 | LocationFrom(calling_convention.GetRegisterAt(1)), |
| 640 | Primitive::kPrimInt, |
| 641 | nullptr); |
| 642 | parallel_move.AddMove( |
| 643 | locations->InAt(2), |
| 644 | LocationFrom(calling_convention.GetRegisterAt(2)), |
| 645 | Primitive::kPrimNot, |
| 646 | nullptr); |
| 647 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 648 | |
| 649 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 650 | arm_codegen->InvokeRuntime(kQuickAputObject, instruction_, instruction_->GetDexPc(), this); |
| 651 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
| 652 | RestoreLiveRegisters(codegen, locations); |
| 653 | __ B(GetExitLabel()); |
| 654 | } |
| 655 | |
| 656 | const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathARMVIXL"; } |
| 657 | |
| 658 | private: |
| 659 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathARMVIXL); |
| 660 | }; |
| 661 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 662 | // Abstract base class for read barrier slow paths marking a reference |
| 663 | // `ref`. |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 664 | // |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 665 | // Argument `entrypoint` must be a register location holding the read |
| 666 | // barrier marking runtime entry point to be invoked. |
| 667 | class ReadBarrierMarkSlowPathBaseARMVIXL : public SlowPathCodeARMVIXL { |
| 668 | protected: |
| 669 | ReadBarrierMarkSlowPathBaseARMVIXL(HInstruction* instruction, Location ref, Location entrypoint) |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 670 | : SlowPathCodeARMVIXL(instruction), ref_(ref), entrypoint_(entrypoint) { |
| 671 | DCHECK(kEmitCompilerReadBarrier); |
| 672 | } |
| 673 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 674 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathBaseARMVIXL"; } |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 675 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 676 | // Generate assembly code calling the read barrier marking runtime |
| 677 | // entry point (ReadBarrierMarkRegX). |
| 678 | void GenerateReadBarrierMarkRuntimeCall(CodeGenerator* codegen) { |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 679 | vixl32::Register ref_reg = RegisterFrom(ref_); |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 680 | |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 681 | // No need to save live registers; it's taken care of by the |
| 682 | // entrypoint. Also, there is no need to update the stack mask, |
| 683 | // as this runtime call will not trigger a garbage collection. |
| 684 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 685 | DCHECK(!ref_reg.Is(sp)); |
| 686 | DCHECK(!ref_reg.Is(lr)); |
| 687 | DCHECK(!ref_reg.Is(pc)); |
| 688 | // IP is used internally by the ReadBarrierMarkRegX entry point |
| 689 | // as a temporary, it cannot be the entry point's input/output. |
| 690 | DCHECK(!ref_reg.Is(ip)); |
| 691 | DCHECK(ref_reg.IsRegister()) << ref_reg; |
| 692 | // "Compact" slow path, saving two moves. |
| 693 | // |
| 694 | // Instead of using the standard runtime calling convention (input |
| 695 | // and output in R0): |
| 696 | // |
| 697 | // R0 <- ref |
| 698 | // R0 <- ReadBarrierMark(R0) |
| 699 | // ref <- R0 |
| 700 | // |
| 701 | // we just use rX (the register containing `ref`) as input and output |
| 702 | // of a dedicated entrypoint: |
| 703 | // |
| 704 | // rX <- ReadBarrierMarkRegX(rX) |
| 705 | // |
| 706 | if (entrypoint_.IsValid()) { |
| 707 | arm_codegen->ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction_, this); |
| 708 | __ Blx(RegisterFrom(entrypoint_)); |
| 709 | } else { |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 710 | // Entrypoint is not already loaded, load from the thread. |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 711 | int32_t entry_point_offset = |
| 712 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArmPointerSize>(ref_reg.GetCode()); |
| 713 | // This runtime call does not require a stack map. |
| 714 | arm_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
| 715 | } |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 716 | } |
| 717 | |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 718 | // The location (register) of the marked object reference. |
| 719 | const Location ref_; |
| 720 | |
| 721 | // The location of the entrypoint if already loaded. |
| 722 | const Location entrypoint_; |
| 723 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 724 | private: |
| 725 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathBaseARMVIXL); |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 726 | }; |
| 727 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 728 | // Slow path marking an object reference `ref` during a read |
| 729 | // barrier. The field `obj.field` in the object `obj` holding this |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 730 | // reference does not get updated by this slow path after marking. |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 731 | // |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 732 | // This means that after the execution of this slow path, `ref` will |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 733 | // always be up-to-date, but `obj.field` may not; i.e., after the |
| 734 | // flip, `ref` will be a to-space reference, but `obj.field` will |
| 735 | // probably still be a from-space reference (unless it gets updated by |
| 736 | // another thread, or if another thread installed another object |
| 737 | // reference (different from `ref`) in `obj.field`). |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 738 | // |
| 739 | // If `entrypoint` is a valid location it is assumed to already be |
| 740 | // holding the entrypoint. The case where the entrypoint is passed in |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 741 | // is when the decision to mark is based on whether the GC is marking. |
| 742 | class ReadBarrierMarkSlowPathARMVIXL : public ReadBarrierMarkSlowPathBaseARMVIXL { |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 743 | public: |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 744 | ReadBarrierMarkSlowPathARMVIXL(HInstruction* instruction, |
| 745 | Location ref, |
| 746 | Location entrypoint = Location::NoLocation()) |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 747 | : ReadBarrierMarkSlowPathBaseARMVIXL(instruction, ref, entrypoint) { |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 748 | DCHECK(kEmitCompilerReadBarrier); |
| 749 | } |
| 750 | |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 751 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathARMVIXL"; } |
| 752 | |
| 753 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 754 | LocationSummary* locations = instruction_->GetLocations(); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 755 | DCHECK(locations->CanCall()); |
| 756 | DCHECK(ref_.IsRegister()) << ref_; |
| 757 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_.reg())) << ref_.reg(); |
| 758 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 759 | << "Unexpected instruction in read barrier marking slow path: " |
| 760 | << instruction_->DebugName(); |
| 761 | |
| 762 | __ Bind(GetEntryLabel()); |
| 763 | GenerateReadBarrierMarkRuntimeCall(codegen); |
| 764 | __ B(GetExitLabel()); |
| 765 | } |
| 766 | |
| 767 | private: |
| 768 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathARMVIXL); |
| 769 | }; |
| 770 | |
| 771 | // Slow path loading `obj`'s lock word, loading a reference from |
| 772 | // object `*(obj + offset + (index << scale_factor))` into `ref`, and |
| 773 | // marking `ref` if `obj` is gray according to the lock word (Baker |
| 774 | // read barrier). The field `obj.field` in the object `obj` holding |
| 775 | // this reference does not get updated by this slow path after marking |
| 776 | // (see LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARMVIXL |
| 777 | // below for that). |
| 778 | // |
| 779 | // This means that after the execution of this slow path, `ref` will |
| 780 | // always be up-to-date, but `obj.field` may not; i.e., after the |
| 781 | // flip, `ref` will be a to-space reference, but `obj.field` will |
| 782 | // probably still be a from-space reference (unless it gets updated by |
| 783 | // another thread, or if another thread installed another object |
| 784 | // reference (different from `ref`) in `obj.field`). |
| 785 | // |
| 786 | // Argument `entrypoint` must be a register location holding the read |
| 787 | // barrier marking runtime entry point to be invoked. |
| 788 | class LoadReferenceWithBakerReadBarrierSlowPathARMVIXL : public ReadBarrierMarkSlowPathBaseARMVIXL { |
| 789 | public: |
| 790 | LoadReferenceWithBakerReadBarrierSlowPathARMVIXL(HInstruction* instruction, |
| 791 | Location ref, |
| 792 | vixl32::Register obj, |
| 793 | uint32_t offset, |
| 794 | Location index, |
| 795 | ScaleFactor scale_factor, |
| 796 | bool needs_null_check, |
| 797 | vixl32::Register temp, |
| 798 | Location entrypoint) |
| 799 | : ReadBarrierMarkSlowPathBaseARMVIXL(instruction, ref, entrypoint), |
| 800 | obj_(obj), |
| 801 | offset_(offset), |
| 802 | index_(index), |
| 803 | scale_factor_(scale_factor), |
| 804 | needs_null_check_(needs_null_check), |
| 805 | temp_(temp) { |
| 806 | DCHECK(kEmitCompilerReadBarrier); |
| 807 | DCHECK(kUseBakerReadBarrier); |
| 808 | } |
| 809 | |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 810 | const char* GetDescription() const OVERRIDE { |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 811 | return "LoadReferenceWithBakerReadBarrierSlowPathARMVIXL"; |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 812 | } |
| 813 | |
| 814 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 815 | LocationSummary* locations = instruction_->GetLocations(); |
| 816 | vixl32::Register ref_reg = RegisterFrom(ref_); |
| 817 | DCHECK(locations->CanCall()); |
| 818 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg.GetCode())) << ref_reg; |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 819 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 820 | instruction_->IsStaticFieldGet() || |
| 821 | instruction_->IsArrayGet() || |
| 822 | instruction_->IsArraySet() || |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 823 | instruction_->IsInstanceOf() || |
| 824 | instruction_->IsCheckCast() || |
| 825 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()) || |
| 826 | (instruction_->IsInvokeStaticOrDirect() && instruction_->GetLocations()->Intrinsified())) |
| 827 | << "Unexpected instruction in read barrier marking slow path: " |
| 828 | << instruction_->DebugName(); |
| 829 | // The read barrier instrumentation of object ArrayGet |
| 830 | // instructions does not support the HIntermediateAddress |
| 831 | // instruction. |
| 832 | DCHECK(!(instruction_->IsArrayGet() && |
| 833 | instruction_->AsArrayGet()->GetArray()->IsIntermediateAddress())); |
| 834 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 835 | // Temporary register `temp_`, used to store the lock word, must |
| 836 | // not be IP, as we may use it to emit the reference load (in the |
| 837 | // call to GenerateRawReferenceLoad below), and we need the lock |
| 838 | // word to still be in `temp_` after the reference load. |
| 839 | DCHECK(!temp_.Is(ip)); |
| 840 | |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 841 | __ Bind(GetEntryLabel()); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 842 | |
| 843 | // When using MaybeGenerateReadBarrierSlow, the read barrier call is |
| 844 | // inserted after the original load. However, in fast path based |
| 845 | // Baker's read barriers, we need to perform the load of |
| 846 | // mirror::Object::monitor_ *before* the original reference load. |
| 847 | // This load-load ordering is required by the read barrier. |
| 848 | // The fast path/slow path (for Baker's algorithm) should look like: |
| 849 | // |
| 850 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 851 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 852 | // HeapReference<mirror::Object> ref = *src; // Original reference load. |
| 853 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 854 | // if (is_gray) { |
| 855 | // ref = entrypoint(ref); // ref = ReadBarrier::Mark(ref); // Runtime entry point call. |
| 856 | // } |
| 857 | // |
| 858 | // Note: the original implementation in ReadBarrier::Barrier is |
| 859 | // slightly more complex as it performs additional checks that we do |
| 860 | // not do here for performance reasons. |
| 861 | |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 862 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 863 | |
| 864 | // /* int32_t */ monitor = obj->monitor_ |
| 865 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 866 | arm_codegen->GetAssembler()->LoadFromOffset(kLoadWord, temp_, obj_, monitor_offset); |
| 867 | if (needs_null_check_) { |
| 868 | codegen->MaybeRecordImplicitNullCheck(instruction_); |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 869 | } |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 870 | // /* LockWord */ lock_word = LockWord(monitor) |
| 871 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 872 | "art::LockWord and int32_t have different sizes."); |
| 873 | |
| 874 | // Introduce a dependency on the lock_word including the rb_state, |
| 875 | // which shall prevent load-load reordering without using |
| 876 | // a memory barrier (which would be more expensive). |
| 877 | // `obj` is unchanged by this operation, but its value now depends |
| 878 | // on `temp`. |
| 879 | __ Add(obj_, obj_, Operand(temp_, ShiftType::LSR, 32)); |
| 880 | |
| 881 | // The actual reference load. |
| 882 | // A possible implicit null check has already been handled above. |
| 883 | arm_codegen->GenerateRawReferenceLoad( |
| 884 | instruction_, ref_, obj_, offset_, index_, scale_factor_, /* needs_null_check */ false); |
| 885 | |
| 886 | // Mark the object `ref` when `obj` is gray. |
| 887 | // |
| 888 | // if (rb_state == ReadBarrier::GrayState()) |
| 889 | // ref = ReadBarrier::Mark(ref); |
| 890 | // |
| 891 | // Given the numeric representation, it's enough to check the low bit of the |
| 892 | // rb_state. We do that by shifting the bit out of the lock word with LSRS |
| 893 | // which can be a 16-bit instruction unlike the TST immediate. |
| 894 | static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0"); |
| 895 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
| 896 | __ Lsrs(temp_, temp_, LockWord::kReadBarrierStateShift + 1); |
| 897 | __ B(cc, GetExitLabel()); // Carry flag is the last bit shifted out by LSRS. |
| 898 | GenerateReadBarrierMarkRuntimeCall(codegen); |
| 899 | |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 900 | __ B(GetExitLabel()); |
| 901 | } |
| 902 | |
| 903 | private: |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 904 | // The register containing the object holding the marked object reference field. |
| 905 | vixl32::Register obj_; |
| 906 | // The offset, index and scale factor to access the reference in `obj_`. |
| 907 | uint32_t offset_; |
| 908 | Location index_; |
| 909 | ScaleFactor scale_factor_; |
| 910 | // Is a null check required? |
| 911 | bool needs_null_check_; |
| 912 | // A temporary register used to hold the lock word of `obj_`. |
| 913 | vixl32::Register temp_; |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 914 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 915 | DISALLOW_COPY_AND_ASSIGN(LoadReferenceWithBakerReadBarrierSlowPathARMVIXL); |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 916 | }; |
| 917 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 918 | // Slow path loading `obj`'s lock word, loading a reference from |
| 919 | // object `*(obj + offset + (index << scale_factor))` into `ref`, and |
| 920 | // marking `ref` if `obj` is gray according to the lock word (Baker |
| 921 | // read barrier). If needed, this slow path also atomically updates |
| 922 | // the field `obj.field` in the object `obj` holding this reference |
| 923 | // after marking (contrary to |
| 924 | // LoadReferenceWithBakerReadBarrierSlowPathARMVIXL above, which never |
| 925 | // tries to update `obj.field`). |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 926 | // |
| 927 | // This means that after the execution of this slow path, both `ref` |
| 928 | // and `obj.field` will be up-to-date; i.e., after the flip, both will |
| 929 | // hold the same to-space reference (unless another thread installed |
| 930 | // another object reference (different from `ref`) in `obj.field`). |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 931 | // |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 932 | // |
| 933 | // Argument `entrypoint` must be a register location holding the read |
| 934 | // barrier marking runtime entry point to be invoked. |
| 935 | class LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARMVIXL |
| 936 | : public ReadBarrierMarkSlowPathBaseARMVIXL { |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 937 | public: |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 938 | LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARMVIXL(HInstruction* instruction, |
| 939 | Location ref, |
| 940 | vixl32::Register obj, |
| 941 | uint32_t offset, |
| 942 | Location index, |
| 943 | ScaleFactor scale_factor, |
| 944 | bool needs_null_check, |
| 945 | vixl32::Register temp1, |
| 946 | vixl32::Register temp2, |
| 947 | Location entrypoint) |
| 948 | : ReadBarrierMarkSlowPathBaseARMVIXL(instruction, ref, entrypoint), |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 949 | obj_(obj), |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 950 | offset_(offset), |
| 951 | index_(index), |
| 952 | scale_factor_(scale_factor), |
| 953 | needs_null_check_(needs_null_check), |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 954 | temp1_(temp1), |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 955 | temp2_(temp2) { |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 956 | DCHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 957 | DCHECK(kUseBakerReadBarrier); |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 958 | } |
| 959 | |
| 960 | const char* GetDescription() const OVERRIDE { |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 961 | return "LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARMVIXL"; |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 962 | } |
| 963 | |
| 964 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 965 | LocationSummary* locations = instruction_->GetLocations(); |
| 966 | vixl32::Register ref_reg = RegisterFrom(ref_); |
| 967 | DCHECK(locations->CanCall()); |
| 968 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg.GetCode())) << ref_reg; |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 969 | DCHECK_NE(ref_.reg(), LocationFrom(temp1_).reg()); |
| 970 | |
| 971 | // This slow path is only used by the UnsafeCASObject intrinsic at the moment. |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 972 | DCHECK((instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
| 973 | << "Unexpected instruction in read barrier marking and field updating slow path: " |
| 974 | << instruction_->DebugName(); |
| 975 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 976 | DCHECK_EQ(instruction_->AsInvoke()->GetIntrinsic(), Intrinsics::kUnsafeCASObject); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 977 | DCHECK_EQ(offset_, 0u); |
| 978 | DCHECK_EQ(scale_factor_, ScaleFactor::TIMES_1); |
| 979 | Location field_offset = index_; |
| 980 | DCHECK(field_offset.IsRegisterPair()) << field_offset; |
| 981 | |
| 982 | // Temporary register `temp1_`, used to store the lock word, must |
| 983 | // not be IP, as we may use it to emit the reference load (in the |
| 984 | // call to GenerateRawReferenceLoad below), and we need the lock |
| 985 | // word to still be in `temp1_` after the reference load. |
| 986 | DCHECK(!temp1_.Is(ip)); |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 987 | |
| 988 | __ Bind(GetEntryLabel()); |
| 989 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 990 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 991 | |
| 992 | // /* int32_t */ monitor = obj->monitor_ |
| 993 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 994 | arm_codegen->GetAssembler()->LoadFromOffset(kLoadWord, temp1_, obj_, monitor_offset); |
| 995 | if (needs_null_check_) { |
| 996 | codegen->MaybeRecordImplicitNullCheck(instruction_); |
| 997 | } |
| 998 | // /* LockWord */ lock_word = LockWord(monitor) |
| 999 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 1000 | "art::LockWord and int32_t have different sizes."); |
| 1001 | |
| 1002 | // Introduce a dependency on the lock_word including the rb_state, |
| 1003 | // which shall prevent load-load reordering without using |
| 1004 | // a memory barrier (which would be more expensive). |
| 1005 | // `obj` is unchanged by this operation, but its value now depends |
| 1006 | // on `temp`. |
| 1007 | __ Add(obj_, obj_, Operand(temp1_, ShiftType::LSR, 32)); |
| 1008 | |
| 1009 | // The actual reference load. |
| 1010 | // A possible implicit null check has already been handled above. |
| 1011 | arm_codegen->GenerateRawReferenceLoad( |
| 1012 | instruction_, ref_, obj_, offset_, index_, scale_factor_, /* needs_null_check */ false); |
| 1013 | |
| 1014 | // Mark the object `ref` when `obj` is gray. |
| 1015 | // |
| 1016 | // if (rb_state == ReadBarrier::GrayState()) |
| 1017 | // ref = ReadBarrier::Mark(ref); |
| 1018 | // |
| 1019 | // Given the numeric representation, it's enough to check the low bit of the |
| 1020 | // rb_state. We do that by shifting the bit out of the lock word with LSRS |
| 1021 | // which can be a 16-bit instruction unlike the TST immediate. |
| 1022 | static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0"); |
| 1023 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
| 1024 | __ Lsrs(temp1_, temp1_, LockWord::kReadBarrierStateShift + 1); |
| 1025 | __ B(cc, GetExitLabel()); // Carry flag is the last bit shifted out by LSRS. |
| 1026 | |
| 1027 | // Save the old value of the reference before marking it. |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 1028 | // Note that we cannot use IP to save the old reference, as IP is |
| 1029 | // used internally by the ReadBarrierMarkRegX entry point, and we |
| 1030 | // need the old reference after the call to that entry point. |
| 1031 | DCHECK(!temp1_.Is(ip)); |
| 1032 | __ Mov(temp1_, ref_reg); |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 1033 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1034 | GenerateReadBarrierMarkRuntimeCall(codegen); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 1035 | |
| 1036 | // If the new reference is different from the old reference, |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1037 | // update the field in the holder (`*(obj_ + field_offset)`). |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 1038 | // |
| 1039 | // Note that this field could also hold a different object, if |
| 1040 | // another thread had concurrently changed it. In that case, the |
| 1041 | // LDREX/SUBS/ITNE sequence of instructions in the compare-and-set |
| 1042 | // (CAS) operation below would abort the CAS, leaving the field |
| 1043 | // as-is. |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 1044 | __ Cmp(temp1_, ref_reg); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1045 | __ B(eq, GetExitLabel()); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 1046 | |
| 1047 | // Update the the holder's field atomically. This may fail if |
| 1048 | // mutator updates before us, but it's OK. This is achieved |
| 1049 | // using a strong compare-and-set (CAS) operation with relaxed |
| 1050 | // memory synchronization ordering, where the expected value is |
| 1051 | // the old reference and the desired value is the new reference. |
| 1052 | |
| 1053 | UseScratchRegisterScope temps(arm_codegen->GetVIXLAssembler()); |
| 1054 | // Convenience aliases. |
| 1055 | vixl32::Register base = obj_; |
| 1056 | // The UnsafeCASObject intrinsic uses a register pair as field |
| 1057 | // offset ("long offset"), of which only the low part contains |
| 1058 | // data. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1059 | vixl32::Register offset = LowRegisterFrom(field_offset); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 1060 | vixl32::Register expected = temp1_; |
| 1061 | vixl32::Register value = ref_reg; |
| 1062 | vixl32::Register tmp_ptr = temps.Acquire(); // Pointer to actual memory. |
| 1063 | vixl32::Register tmp = temp2_; // Value in memory. |
| 1064 | |
| 1065 | __ Add(tmp_ptr, base, offset); |
| 1066 | |
| 1067 | if (kPoisonHeapReferences) { |
| 1068 | arm_codegen->GetAssembler()->PoisonHeapReference(expected); |
| 1069 | if (value.Is(expected)) { |
| 1070 | // Do not poison `value`, as it is the same register as |
| 1071 | // `expected`, which has just been poisoned. |
| 1072 | } else { |
| 1073 | arm_codegen->GetAssembler()->PoisonHeapReference(value); |
| 1074 | } |
| 1075 | } |
| 1076 | |
| 1077 | // do { |
| 1078 | // tmp = [r_ptr] - expected; |
| 1079 | // } while (tmp == 0 && failure([r_ptr] <- r_new_value)); |
| 1080 | |
| 1081 | vixl32::Label loop_head, exit_loop; |
| 1082 | __ Bind(&loop_head); |
| 1083 | |
| 1084 | __ Ldrex(tmp, MemOperand(tmp_ptr)); |
| 1085 | |
| 1086 | __ Subs(tmp, tmp, expected); |
| 1087 | |
| 1088 | { |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 1089 | ExactAssemblyScope aas(arm_codegen->GetVIXLAssembler(), |
| 1090 | 2 * kMaxInstructionSizeInBytes, |
| 1091 | CodeBufferCheckScope::kMaximumSize); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 1092 | |
| 1093 | __ it(ne); |
| 1094 | __ clrex(ne); |
| 1095 | } |
| 1096 | |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 1097 | __ B(ne, &exit_loop, /* far_target */ false); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 1098 | |
| 1099 | __ Strex(tmp, value, MemOperand(tmp_ptr)); |
| 1100 | __ Cmp(tmp, 1); |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 1101 | __ B(eq, &loop_head, /* far_target */ false); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 1102 | |
| 1103 | __ Bind(&exit_loop); |
| 1104 | |
| 1105 | if (kPoisonHeapReferences) { |
| 1106 | arm_codegen->GetAssembler()->UnpoisonHeapReference(expected); |
| 1107 | if (value.Is(expected)) { |
| 1108 | // Do not unpoison `value`, as it is the same register as |
| 1109 | // `expected`, which has just been unpoisoned. |
| 1110 | } else { |
| 1111 | arm_codegen->GetAssembler()->UnpoisonHeapReference(value); |
| 1112 | } |
| 1113 | } |
| 1114 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 1115 | __ B(GetExitLabel()); |
| 1116 | } |
| 1117 | |
| 1118 | private: |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 1119 | // The register containing the object holding the marked object reference field. |
| 1120 | const vixl32::Register obj_; |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1121 | // The offset, index and scale factor to access the reference in `obj_`. |
| 1122 | uint32_t offset_; |
| 1123 | Location index_; |
| 1124 | ScaleFactor scale_factor_; |
| 1125 | // Is a null check required? |
| 1126 | bool needs_null_check_; |
| 1127 | // A temporary register used to hold the lock word of `obj_`; and |
| 1128 | // also to hold the original reference value, when the reference is |
| 1129 | // marked. |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 1130 | const vixl32::Register temp1_; |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1131 | // A temporary register used in the implementation of the CAS, to |
| 1132 | // update the object's reference field. |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 1133 | const vixl32::Register temp2_; |
| 1134 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1135 | DISALLOW_COPY_AND_ASSIGN(LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARMVIXL); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 1136 | }; |
| 1137 | |
| 1138 | // Slow path generating a read barrier for a heap reference. |
| 1139 | class ReadBarrierForHeapReferenceSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 1140 | public: |
| 1141 | ReadBarrierForHeapReferenceSlowPathARMVIXL(HInstruction* instruction, |
| 1142 | Location out, |
| 1143 | Location ref, |
| 1144 | Location obj, |
| 1145 | uint32_t offset, |
| 1146 | Location index) |
| 1147 | : SlowPathCodeARMVIXL(instruction), |
| 1148 | out_(out), |
| 1149 | ref_(ref), |
| 1150 | obj_(obj), |
| 1151 | offset_(offset), |
| 1152 | index_(index) { |
| 1153 | DCHECK(kEmitCompilerReadBarrier); |
| 1154 | // If `obj` is equal to `out` or `ref`, it means the initial object |
| 1155 | // has been overwritten by (or after) the heap object reference load |
| 1156 | // to be instrumented, e.g.: |
| 1157 | // |
| 1158 | // __ LoadFromOffset(kLoadWord, out, out, offset); |
| 1159 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
| 1160 | // |
| 1161 | // In that case, we have lost the information about the original |
| 1162 | // object, and the emitted read barrier cannot work properly. |
| 1163 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 1164 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 1165 | } |
| 1166 | |
| 1167 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 1168 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 1169 | LocationSummary* locations = instruction_->GetLocations(); |
| 1170 | vixl32::Register reg_out = RegisterFrom(out_); |
| 1171 | DCHECK(locations->CanCall()); |
| 1172 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out.GetCode())); |
| 1173 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 1174 | instruction_->IsStaticFieldGet() || |
| 1175 | instruction_->IsArrayGet() || |
| 1176 | instruction_->IsInstanceOf() || |
| 1177 | instruction_->IsCheckCast() || |
Andreas Gampe | d9911ee | 2017-03-27 13:27:24 -0700 | [diff] [blame] | 1178 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 1179 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 1180 | << instruction_->DebugName(); |
| 1181 | // The read barrier instrumentation of object ArrayGet |
| 1182 | // instructions does not support the HIntermediateAddress |
| 1183 | // instruction. |
| 1184 | DCHECK(!(instruction_->IsArrayGet() && |
| 1185 | instruction_->AsArrayGet()->GetArray()->IsIntermediateAddress())); |
| 1186 | |
| 1187 | __ Bind(GetEntryLabel()); |
| 1188 | SaveLiveRegisters(codegen, locations); |
| 1189 | |
| 1190 | // We may have to change the index's value, but as `index_` is a |
| 1191 | // constant member (like other "inputs" of this slow path), |
| 1192 | // introduce a copy of it, `index`. |
| 1193 | Location index = index_; |
| 1194 | if (index_.IsValid()) { |
| 1195 | // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
| 1196 | if (instruction_->IsArrayGet()) { |
| 1197 | // Compute the actual memory offset and store it in `index`. |
| 1198 | vixl32::Register index_reg = RegisterFrom(index_); |
| 1199 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_reg.GetCode())); |
| 1200 | if (codegen->IsCoreCalleeSaveRegister(index_reg.GetCode())) { |
| 1201 | // We are about to change the value of `index_reg` (see the |
| 1202 | // calls to art::arm::Thumb2Assembler::Lsl and |
| 1203 | // art::arm::Thumb2Assembler::AddConstant below), but it has |
| 1204 | // not been saved by the previous call to |
| 1205 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 1206 | // callee-save register -- |
| 1207 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 1208 | // callee-save registers, as it has been designed with the |
| 1209 | // assumption that callee-save registers are supposed to be |
| 1210 | // handled by the called function. So, as a callee-save |
| 1211 | // register, `index_reg` _would_ eventually be saved onto |
| 1212 | // the stack, but it would be too late: we would have |
| 1213 | // changed its value earlier. Therefore, we manually save |
| 1214 | // it here into another freely available register, |
| 1215 | // `free_reg`, chosen of course among the caller-save |
| 1216 | // registers (as a callee-save `free_reg` register would |
| 1217 | // exhibit the same problem). |
| 1218 | // |
| 1219 | // Note we could have requested a temporary register from |
| 1220 | // the register allocator instead; but we prefer not to, as |
| 1221 | // this is a slow path, and we know we can find a |
| 1222 | // caller-save register that is available. |
| 1223 | vixl32::Register free_reg = FindAvailableCallerSaveRegister(codegen); |
| 1224 | __ Mov(free_reg, index_reg); |
| 1225 | index_reg = free_reg; |
| 1226 | index = LocationFrom(index_reg); |
| 1227 | } else { |
| 1228 | // The initial register stored in `index_` has already been |
| 1229 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 1230 | // (as it is not a callee-save register), so we can freely |
| 1231 | // use it. |
| 1232 | } |
| 1233 | // Shifting the index value contained in `index_reg` by the scale |
| 1234 | // factor (2) cannot overflow in practice, as the runtime is |
| 1235 | // unable to allocate object arrays with a size larger than |
| 1236 | // 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 1237 | __ Lsl(index_reg, index_reg, TIMES_4); |
| 1238 | static_assert( |
| 1239 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 1240 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 1241 | __ Add(index_reg, index_reg, offset_); |
| 1242 | } else { |
| 1243 | // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile |
| 1244 | // intrinsics, `index_` is not shifted by a scale factor of 2 |
| 1245 | // (as in the case of ArrayGet), as it is actually an offset |
| 1246 | // to an object field within an object. |
| 1247 | DCHECK(instruction_->IsInvoke()) << instruction_->DebugName(); |
| 1248 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 1249 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 1250 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 1251 | << instruction_->AsInvoke()->GetIntrinsic(); |
| 1252 | DCHECK_EQ(offset_, 0U); |
| 1253 | DCHECK(index_.IsRegisterPair()); |
| 1254 | // UnsafeGet's offset location is a register pair, the low |
| 1255 | // part contains the correct offset. |
| 1256 | index = index_.ToLow(); |
| 1257 | } |
| 1258 | } |
| 1259 | |
| 1260 | // We're moving two or three locations to locations that could |
| 1261 | // overlap, so we need a parallel move resolver. |
| 1262 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 1263 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 1264 | parallel_move.AddMove(ref_, |
| 1265 | LocationFrom(calling_convention.GetRegisterAt(0)), |
| 1266 | Primitive::kPrimNot, |
| 1267 | nullptr); |
| 1268 | parallel_move.AddMove(obj_, |
| 1269 | LocationFrom(calling_convention.GetRegisterAt(1)), |
| 1270 | Primitive::kPrimNot, |
| 1271 | nullptr); |
| 1272 | if (index.IsValid()) { |
| 1273 | parallel_move.AddMove(index, |
| 1274 | LocationFrom(calling_convention.GetRegisterAt(2)), |
| 1275 | Primitive::kPrimInt, |
| 1276 | nullptr); |
| 1277 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 1278 | } else { |
| 1279 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 1280 | __ Mov(calling_convention.GetRegisterAt(2), offset_); |
| 1281 | } |
| 1282 | arm_codegen->InvokeRuntime(kQuickReadBarrierSlow, instruction_, instruction_->GetDexPc(), this); |
| 1283 | CheckEntrypointTypes< |
| 1284 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 1285 | arm_codegen->Move32(out_, LocationFrom(r0)); |
| 1286 | |
| 1287 | RestoreLiveRegisters(codegen, locations); |
| 1288 | __ B(GetExitLabel()); |
| 1289 | } |
| 1290 | |
| 1291 | const char* GetDescription() const OVERRIDE { |
| 1292 | return "ReadBarrierForHeapReferenceSlowPathARMVIXL"; |
| 1293 | } |
| 1294 | |
| 1295 | private: |
| 1296 | vixl32::Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
| 1297 | uint32_t ref = RegisterFrom(ref_).GetCode(); |
| 1298 | uint32_t obj = RegisterFrom(obj_).GetCode(); |
| 1299 | for (uint32_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 1300 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 1301 | return vixl32::Register(i); |
| 1302 | } |
| 1303 | } |
| 1304 | // We shall never fail to find a free caller-save register, as |
| 1305 | // there are more than two core caller-save registers on ARM |
| 1306 | // (meaning it is possible to find one which is different from |
| 1307 | // `ref` and `obj`). |
| 1308 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 1309 | LOG(FATAL) << "Could not find a free caller-save register"; |
| 1310 | UNREACHABLE(); |
| 1311 | } |
| 1312 | |
| 1313 | const Location out_; |
| 1314 | const Location ref_; |
| 1315 | const Location obj_; |
| 1316 | const uint32_t offset_; |
| 1317 | // An additional location containing an index to an array. |
| 1318 | // Only used for HArrayGet and the UnsafeGetObject & |
| 1319 | // UnsafeGetObjectVolatile intrinsics. |
| 1320 | const Location index_; |
| 1321 | |
| 1322 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathARMVIXL); |
| 1323 | }; |
| 1324 | |
| 1325 | // Slow path generating a read barrier for a GC root. |
| 1326 | class ReadBarrierForRootSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 1327 | public: |
| 1328 | ReadBarrierForRootSlowPathARMVIXL(HInstruction* instruction, Location out, Location root) |
| 1329 | : SlowPathCodeARMVIXL(instruction), out_(out), root_(root) { |
| 1330 | DCHECK(kEmitCompilerReadBarrier); |
| 1331 | } |
| 1332 | |
| 1333 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 1334 | LocationSummary* locations = instruction_->GetLocations(); |
| 1335 | vixl32::Register reg_out = RegisterFrom(out_); |
| 1336 | DCHECK(locations->CanCall()); |
| 1337 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out.GetCode())); |
| 1338 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 1339 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 1340 | << instruction_->DebugName(); |
| 1341 | |
| 1342 | __ Bind(GetEntryLabel()); |
| 1343 | SaveLiveRegisters(codegen, locations); |
| 1344 | |
| 1345 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 1346 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 1347 | arm_codegen->Move32(LocationFrom(calling_convention.GetRegisterAt(0)), root_); |
| 1348 | arm_codegen->InvokeRuntime(kQuickReadBarrierForRootSlow, |
| 1349 | instruction_, |
| 1350 | instruction_->GetDexPc(), |
| 1351 | this); |
| 1352 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 1353 | arm_codegen->Move32(out_, LocationFrom(r0)); |
| 1354 | |
| 1355 | RestoreLiveRegisters(codegen, locations); |
| 1356 | __ B(GetExitLabel()); |
| 1357 | } |
| 1358 | |
| 1359 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathARMVIXL"; } |
| 1360 | |
| 1361 | private: |
| 1362 | const Location out_; |
| 1363 | const Location root_; |
| 1364 | |
| 1365 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathARMVIXL); |
| 1366 | }; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 1367 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1368 | inline vixl32::Condition ARMCondition(IfCondition cond) { |
| 1369 | switch (cond) { |
| 1370 | case kCondEQ: return eq; |
| 1371 | case kCondNE: return ne; |
| 1372 | case kCondLT: return lt; |
| 1373 | case kCondLE: return le; |
| 1374 | case kCondGT: return gt; |
| 1375 | case kCondGE: return ge; |
| 1376 | case kCondB: return lo; |
| 1377 | case kCondBE: return ls; |
| 1378 | case kCondA: return hi; |
| 1379 | case kCondAE: return hs; |
| 1380 | } |
| 1381 | LOG(FATAL) << "Unreachable"; |
| 1382 | UNREACHABLE(); |
| 1383 | } |
| 1384 | |
| 1385 | // Maps signed condition to unsigned condition. |
| 1386 | inline vixl32::Condition ARMUnsignedCondition(IfCondition cond) { |
| 1387 | switch (cond) { |
| 1388 | case kCondEQ: return eq; |
| 1389 | case kCondNE: return ne; |
| 1390 | // Signed to unsigned. |
| 1391 | case kCondLT: return lo; |
| 1392 | case kCondLE: return ls; |
| 1393 | case kCondGT: return hi; |
| 1394 | case kCondGE: return hs; |
| 1395 | // Unsigned remain unchanged. |
| 1396 | case kCondB: return lo; |
| 1397 | case kCondBE: return ls; |
| 1398 | case kCondA: return hi; |
| 1399 | case kCondAE: return hs; |
| 1400 | } |
| 1401 | LOG(FATAL) << "Unreachable"; |
| 1402 | UNREACHABLE(); |
| 1403 | } |
| 1404 | |
| 1405 | inline vixl32::Condition ARMFPCondition(IfCondition cond, bool gt_bias) { |
| 1406 | // The ARM condition codes can express all the necessary branches, see the |
| 1407 | // "Meaning (floating-point)" column in the table A8-1 of the ARMv7 reference manual. |
| 1408 | // There is no dex instruction or HIR that would need the missing conditions |
| 1409 | // "equal or unordered" or "not equal". |
| 1410 | switch (cond) { |
| 1411 | case kCondEQ: return eq; |
| 1412 | case kCondNE: return ne /* unordered */; |
| 1413 | case kCondLT: return gt_bias ? cc : lt /* unordered */; |
| 1414 | case kCondLE: return gt_bias ? ls : le /* unordered */; |
| 1415 | case kCondGT: return gt_bias ? hi /* unordered */ : gt; |
| 1416 | case kCondGE: return gt_bias ? cs /* unordered */ : ge; |
| 1417 | default: |
| 1418 | LOG(FATAL) << "UNREACHABLE"; |
| 1419 | UNREACHABLE(); |
| 1420 | } |
| 1421 | } |
| 1422 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 1423 | inline ShiftType ShiftFromOpKind(HDataProcWithShifterOp::OpKind op_kind) { |
| 1424 | switch (op_kind) { |
| 1425 | case HDataProcWithShifterOp::kASR: return ShiftType::ASR; |
| 1426 | case HDataProcWithShifterOp::kLSL: return ShiftType::LSL; |
| 1427 | case HDataProcWithShifterOp::kLSR: return ShiftType::LSR; |
| 1428 | default: |
| 1429 | LOG(FATAL) << "Unexpected op kind " << op_kind; |
| 1430 | UNREACHABLE(); |
| 1431 | } |
| 1432 | } |
| 1433 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1434 | void CodeGeneratorARMVIXL::DumpCoreRegister(std::ostream& stream, int reg) const { |
| 1435 | stream << vixl32::Register(reg); |
| 1436 | } |
| 1437 | |
| 1438 | void CodeGeneratorARMVIXL::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
| 1439 | stream << vixl32::SRegister(reg); |
| 1440 | } |
| 1441 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 1442 | static uint32_t ComputeSRegisterListMask(const SRegisterList& regs) { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1443 | uint32_t mask = 0; |
| 1444 | for (uint32_t i = regs.GetFirstSRegister().GetCode(); |
| 1445 | i <= regs.GetLastSRegister().GetCode(); |
| 1446 | ++i) { |
| 1447 | mask |= (1 << i); |
| 1448 | } |
| 1449 | return mask; |
| 1450 | } |
| 1451 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 1452 | // Saves the register in the stack. Returns the size taken on stack. |
| 1453 | size_t CodeGeneratorARMVIXL::SaveCoreRegister(size_t stack_index ATTRIBUTE_UNUSED, |
| 1454 | uint32_t reg_id ATTRIBUTE_UNUSED) { |
| 1455 | TODO_VIXL32(FATAL); |
| 1456 | return 0; |
| 1457 | } |
| 1458 | |
| 1459 | // Restores the register from the stack. Returns the size taken on stack. |
| 1460 | size_t CodeGeneratorARMVIXL::RestoreCoreRegister(size_t stack_index ATTRIBUTE_UNUSED, |
| 1461 | uint32_t reg_id ATTRIBUTE_UNUSED) { |
| 1462 | TODO_VIXL32(FATAL); |
| 1463 | return 0; |
| 1464 | } |
| 1465 | |
| 1466 | size_t CodeGeneratorARMVIXL::SaveFloatingPointRegister(size_t stack_index ATTRIBUTE_UNUSED, |
| 1467 | uint32_t reg_id ATTRIBUTE_UNUSED) { |
| 1468 | TODO_VIXL32(FATAL); |
| 1469 | return 0; |
| 1470 | } |
| 1471 | |
| 1472 | size_t CodeGeneratorARMVIXL::RestoreFloatingPointRegister(size_t stack_index ATTRIBUTE_UNUSED, |
| 1473 | uint32_t reg_id ATTRIBUTE_UNUSED) { |
| 1474 | TODO_VIXL32(FATAL); |
| 1475 | return 0; |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 1476 | } |
| 1477 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 1478 | static void GenerateDataProcInstruction(HInstruction::InstructionKind kind, |
| 1479 | vixl32::Register out, |
| 1480 | vixl32::Register first, |
| 1481 | const Operand& second, |
| 1482 | CodeGeneratorARMVIXL* codegen) { |
| 1483 | if (second.IsImmediate() && second.GetImmediate() == 0) { |
| 1484 | const Operand in = kind == HInstruction::kAnd |
| 1485 | ? Operand(0) |
| 1486 | : Operand(first); |
| 1487 | |
| 1488 | __ Mov(out, in); |
| 1489 | } else { |
| 1490 | switch (kind) { |
| 1491 | case HInstruction::kAdd: |
| 1492 | __ Add(out, first, second); |
| 1493 | break; |
| 1494 | case HInstruction::kAnd: |
| 1495 | __ And(out, first, second); |
| 1496 | break; |
| 1497 | case HInstruction::kOr: |
| 1498 | __ Orr(out, first, second); |
| 1499 | break; |
| 1500 | case HInstruction::kSub: |
| 1501 | __ Sub(out, first, second); |
| 1502 | break; |
| 1503 | case HInstruction::kXor: |
| 1504 | __ Eor(out, first, second); |
| 1505 | break; |
| 1506 | default: |
| 1507 | LOG(FATAL) << "Unexpected instruction kind: " << kind; |
| 1508 | UNREACHABLE(); |
| 1509 | } |
| 1510 | } |
| 1511 | } |
| 1512 | |
| 1513 | static void GenerateDataProc(HInstruction::InstructionKind kind, |
| 1514 | const Location& out, |
| 1515 | const Location& first, |
| 1516 | const Operand& second_lo, |
| 1517 | const Operand& second_hi, |
| 1518 | CodeGeneratorARMVIXL* codegen) { |
| 1519 | const vixl32::Register first_hi = HighRegisterFrom(first); |
| 1520 | const vixl32::Register first_lo = LowRegisterFrom(first); |
| 1521 | const vixl32::Register out_hi = HighRegisterFrom(out); |
| 1522 | const vixl32::Register out_lo = LowRegisterFrom(out); |
| 1523 | |
| 1524 | if (kind == HInstruction::kAdd) { |
| 1525 | __ Adds(out_lo, first_lo, second_lo); |
| 1526 | __ Adc(out_hi, first_hi, second_hi); |
| 1527 | } else if (kind == HInstruction::kSub) { |
| 1528 | __ Subs(out_lo, first_lo, second_lo); |
| 1529 | __ Sbc(out_hi, first_hi, second_hi); |
| 1530 | } else { |
| 1531 | GenerateDataProcInstruction(kind, out_lo, first_lo, second_lo, codegen); |
| 1532 | GenerateDataProcInstruction(kind, out_hi, first_hi, second_hi, codegen); |
| 1533 | } |
| 1534 | } |
| 1535 | |
| 1536 | static Operand GetShifterOperand(vixl32::Register rm, ShiftType shift, uint32_t shift_imm) { |
| 1537 | return shift_imm == 0 ? Operand(rm) : Operand(rm, shift, shift_imm); |
| 1538 | } |
| 1539 | |
| 1540 | static void GenerateLongDataProc(HDataProcWithShifterOp* instruction, |
| 1541 | CodeGeneratorARMVIXL* codegen) { |
| 1542 | DCHECK_EQ(instruction->GetType(), Primitive::kPrimLong); |
| 1543 | DCHECK(HDataProcWithShifterOp::IsShiftOp(instruction->GetOpKind())); |
| 1544 | |
| 1545 | const LocationSummary* const locations = instruction->GetLocations(); |
| 1546 | const uint32_t shift_value = instruction->GetShiftAmount(); |
| 1547 | const HInstruction::InstructionKind kind = instruction->GetInstrKind(); |
| 1548 | const Location first = locations->InAt(0); |
| 1549 | const Location second = locations->InAt(1); |
| 1550 | const Location out = locations->Out(); |
| 1551 | const vixl32::Register first_hi = HighRegisterFrom(first); |
| 1552 | const vixl32::Register first_lo = LowRegisterFrom(first); |
| 1553 | const vixl32::Register out_hi = HighRegisterFrom(out); |
| 1554 | const vixl32::Register out_lo = LowRegisterFrom(out); |
| 1555 | const vixl32::Register second_hi = HighRegisterFrom(second); |
| 1556 | const vixl32::Register second_lo = LowRegisterFrom(second); |
| 1557 | const ShiftType shift = ShiftFromOpKind(instruction->GetOpKind()); |
| 1558 | |
| 1559 | if (shift_value >= 32) { |
| 1560 | if (shift == ShiftType::LSL) { |
| 1561 | GenerateDataProcInstruction(kind, |
| 1562 | out_hi, |
| 1563 | first_hi, |
| 1564 | Operand(second_lo, ShiftType::LSL, shift_value - 32), |
| 1565 | codegen); |
| 1566 | GenerateDataProcInstruction(kind, out_lo, first_lo, 0, codegen); |
| 1567 | } else if (shift == ShiftType::ASR) { |
| 1568 | GenerateDataProc(kind, |
| 1569 | out, |
| 1570 | first, |
| 1571 | GetShifterOperand(second_hi, ShiftType::ASR, shift_value - 32), |
| 1572 | Operand(second_hi, ShiftType::ASR, 31), |
| 1573 | codegen); |
| 1574 | } else { |
| 1575 | DCHECK_EQ(shift, ShiftType::LSR); |
| 1576 | GenerateDataProc(kind, |
| 1577 | out, |
| 1578 | first, |
| 1579 | GetShifterOperand(second_hi, ShiftType::LSR, shift_value - 32), |
| 1580 | 0, |
| 1581 | codegen); |
| 1582 | } |
| 1583 | } else { |
| 1584 | DCHECK_GT(shift_value, 1U); |
| 1585 | DCHECK_LT(shift_value, 32U); |
| 1586 | |
| 1587 | UseScratchRegisterScope temps(codegen->GetVIXLAssembler()); |
| 1588 | |
| 1589 | if (shift == ShiftType::LSL) { |
| 1590 | // We are not doing this for HInstruction::kAdd because the output will require |
| 1591 | // Location::kOutputOverlap; not applicable to other cases. |
| 1592 | if (kind == HInstruction::kOr || kind == HInstruction::kXor) { |
| 1593 | GenerateDataProcInstruction(kind, |
| 1594 | out_hi, |
| 1595 | first_hi, |
| 1596 | Operand(second_hi, ShiftType::LSL, shift_value), |
| 1597 | codegen); |
| 1598 | GenerateDataProcInstruction(kind, |
| 1599 | out_hi, |
| 1600 | out_hi, |
| 1601 | Operand(second_lo, ShiftType::LSR, 32 - shift_value), |
| 1602 | codegen); |
| 1603 | GenerateDataProcInstruction(kind, |
| 1604 | out_lo, |
| 1605 | first_lo, |
| 1606 | Operand(second_lo, ShiftType::LSL, shift_value), |
| 1607 | codegen); |
| 1608 | } else { |
| 1609 | const vixl32::Register temp = temps.Acquire(); |
| 1610 | |
| 1611 | __ Lsl(temp, second_hi, shift_value); |
| 1612 | __ Orr(temp, temp, Operand(second_lo, ShiftType::LSR, 32 - shift_value)); |
| 1613 | GenerateDataProc(kind, |
| 1614 | out, |
| 1615 | first, |
| 1616 | Operand(second_lo, ShiftType::LSL, shift_value), |
| 1617 | temp, |
| 1618 | codegen); |
| 1619 | } |
| 1620 | } else { |
| 1621 | DCHECK(shift == ShiftType::ASR || shift == ShiftType::LSR); |
| 1622 | |
| 1623 | // We are not doing this for HInstruction::kAdd because the output will require |
| 1624 | // Location::kOutputOverlap; not applicable to other cases. |
| 1625 | if (kind == HInstruction::kOr || kind == HInstruction::kXor) { |
| 1626 | GenerateDataProcInstruction(kind, |
| 1627 | out_lo, |
| 1628 | first_lo, |
| 1629 | Operand(second_lo, ShiftType::LSR, shift_value), |
| 1630 | codegen); |
| 1631 | GenerateDataProcInstruction(kind, |
| 1632 | out_lo, |
| 1633 | out_lo, |
| 1634 | Operand(second_hi, ShiftType::LSL, 32 - shift_value), |
| 1635 | codegen); |
| 1636 | GenerateDataProcInstruction(kind, |
| 1637 | out_hi, |
| 1638 | first_hi, |
| 1639 | Operand(second_hi, shift, shift_value), |
| 1640 | codegen); |
| 1641 | } else { |
| 1642 | const vixl32::Register temp = temps.Acquire(); |
| 1643 | |
| 1644 | __ Lsr(temp, second_lo, shift_value); |
| 1645 | __ Orr(temp, temp, Operand(second_hi, ShiftType::LSL, 32 - shift_value)); |
| 1646 | GenerateDataProc(kind, |
| 1647 | out, |
| 1648 | first, |
| 1649 | temp, |
| 1650 | Operand(second_hi, shift, shift_value), |
| 1651 | codegen); |
| 1652 | } |
| 1653 | } |
| 1654 | } |
| 1655 | } |
| 1656 | |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1657 | static void GenerateVcmp(HInstruction* instruction, CodeGeneratorARMVIXL* codegen) { |
| 1658 | const Location rhs_loc = instruction->GetLocations()->InAt(1); |
| 1659 | if (rhs_loc.IsConstant()) { |
| 1660 | // 0.0 is the only immediate that can be encoded directly in |
| 1661 | // a VCMP instruction. |
| 1662 | // |
| 1663 | // Both the JLS (section 15.20.1) and the JVMS (section 6.5) |
| 1664 | // specify that in a floating-point comparison, positive zero |
| 1665 | // and negative zero are considered equal, so we can use the |
| 1666 | // literal 0.0 for both cases here. |
| 1667 | // |
| 1668 | // Note however that some methods (Float.equal, Float.compare, |
| 1669 | // Float.compareTo, Double.equal, Double.compare, |
| 1670 | // Double.compareTo, Math.max, Math.min, StrictMath.max, |
| 1671 | // StrictMath.min) consider 0.0 to be (strictly) greater than |
| 1672 | // -0.0. So if we ever translate calls to these methods into a |
| 1673 | // HCompare instruction, we must handle the -0.0 case with |
| 1674 | // care here. |
| 1675 | DCHECK(rhs_loc.GetConstant()->IsArithmeticZero()); |
| 1676 | |
| 1677 | const Primitive::Type type = instruction->InputAt(0)->GetType(); |
| 1678 | |
| 1679 | if (type == Primitive::kPrimFloat) { |
| 1680 | __ Vcmp(F32, InputSRegisterAt(instruction, 0), 0.0); |
| 1681 | } else { |
| 1682 | DCHECK_EQ(type, Primitive::kPrimDouble); |
| 1683 | __ Vcmp(F64, InputDRegisterAt(instruction, 0), 0.0); |
| 1684 | } |
| 1685 | } else { |
| 1686 | __ Vcmp(InputVRegisterAt(instruction, 0), InputVRegisterAt(instruction, 1)); |
| 1687 | } |
| 1688 | } |
| 1689 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1690 | static std::pair<vixl32::Condition, vixl32::Condition> GenerateLongTestConstant( |
| 1691 | HCondition* condition, |
| 1692 | bool invert, |
| 1693 | CodeGeneratorARMVIXL* codegen) { |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1694 | DCHECK_EQ(condition->GetLeft()->GetType(), Primitive::kPrimLong); |
| 1695 | |
| 1696 | const LocationSummary* const locations = condition->GetLocations(); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1697 | IfCondition cond = condition->GetCondition(); |
| 1698 | IfCondition opposite = condition->GetOppositeCondition(); |
| 1699 | |
| 1700 | if (invert) { |
| 1701 | std::swap(cond, opposite); |
| 1702 | } |
| 1703 | |
| 1704 | std::pair<vixl32::Condition, vixl32::Condition> ret(eq, ne); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1705 | const Location left = locations->InAt(0); |
| 1706 | const Location right = locations->InAt(1); |
| 1707 | |
| 1708 | DCHECK(right.IsConstant()); |
| 1709 | |
| 1710 | const vixl32::Register left_high = HighRegisterFrom(left); |
| 1711 | const vixl32::Register left_low = LowRegisterFrom(left); |
| 1712 | int64_t value = Int64ConstantFrom(right); |
| 1713 | |
| 1714 | switch (cond) { |
| 1715 | case kCondEQ: |
| 1716 | case kCondNE: |
| 1717 | case kCondB: |
| 1718 | case kCondBE: |
| 1719 | case kCondA: |
| 1720 | case kCondAE: { |
| 1721 | __ Cmp(left_high, High32Bits(value)); |
| 1722 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1723 | // We use the scope because of the IT block that follows. |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1724 | ExactAssemblyScope guard(codegen->GetVIXLAssembler(), |
| 1725 | 2 * vixl32::k16BitT32InstructionSizeInBytes, |
| 1726 | CodeBufferCheckScope::kExactSize); |
| 1727 | |
| 1728 | __ it(eq); |
| 1729 | __ cmp(eq, left_low, Low32Bits(value)); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1730 | ret = std::make_pair(ARMUnsignedCondition(cond), ARMUnsignedCondition(opposite)); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1731 | break; |
| 1732 | } |
| 1733 | case kCondLE: |
| 1734 | case kCondGT: |
| 1735 | // Trivially true or false. |
| 1736 | if (value == std::numeric_limits<int64_t>::max()) { |
| 1737 | __ Cmp(left_low, left_low); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1738 | ret = cond == kCondLE ? std::make_pair(eq, ne) : std::make_pair(ne, eq); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1739 | break; |
| 1740 | } |
| 1741 | |
| 1742 | if (cond == kCondLE) { |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1743 | DCHECK_EQ(opposite, kCondGT); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1744 | cond = kCondLT; |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1745 | opposite = kCondGE; |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1746 | } else { |
| 1747 | DCHECK_EQ(cond, kCondGT); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1748 | DCHECK_EQ(opposite, kCondLE); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1749 | cond = kCondGE; |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1750 | opposite = kCondLT; |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1751 | } |
| 1752 | |
| 1753 | value++; |
| 1754 | FALLTHROUGH_INTENDED; |
| 1755 | case kCondGE: |
| 1756 | case kCondLT: { |
| 1757 | UseScratchRegisterScope temps(codegen->GetVIXLAssembler()); |
| 1758 | |
| 1759 | __ Cmp(left_low, Low32Bits(value)); |
| 1760 | __ Sbcs(temps.Acquire(), left_high, High32Bits(value)); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1761 | ret = std::make_pair(ARMCondition(cond), ARMCondition(opposite)); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1762 | break; |
| 1763 | } |
| 1764 | default: |
| 1765 | LOG(FATAL) << "Unreachable"; |
| 1766 | UNREACHABLE(); |
| 1767 | } |
| 1768 | |
| 1769 | return ret; |
| 1770 | } |
| 1771 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1772 | static std::pair<vixl32::Condition, vixl32::Condition> GenerateLongTest( |
| 1773 | HCondition* condition, |
| 1774 | bool invert, |
| 1775 | CodeGeneratorARMVIXL* codegen) { |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1776 | DCHECK_EQ(condition->GetLeft()->GetType(), Primitive::kPrimLong); |
| 1777 | |
| 1778 | const LocationSummary* const locations = condition->GetLocations(); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1779 | IfCondition cond = condition->GetCondition(); |
| 1780 | IfCondition opposite = condition->GetOppositeCondition(); |
| 1781 | |
| 1782 | if (invert) { |
| 1783 | std::swap(cond, opposite); |
| 1784 | } |
| 1785 | |
| 1786 | std::pair<vixl32::Condition, vixl32::Condition> ret(eq, ne); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1787 | Location left = locations->InAt(0); |
| 1788 | Location right = locations->InAt(1); |
| 1789 | |
| 1790 | DCHECK(right.IsRegisterPair()); |
| 1791 | |
| 1792 | switch (cond) { |
| 1793 | case kCondEQ: |
| 1794 | case kCondNE: |
| 1795 | case kCondB: |
| 1796 | case kCondBE: |
| 1797 | case kCondA: |
| 1798 | case kCondAE: { |
| 1799 | __ Cmp(HighRegisterFrom(left), HighRegisterFrom(right)); |
| 1800 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1801 | // We use the scope because of the IT block that follows. |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1802 | ExactAssemblyScope guard(codegen->GetVIXLAssembler(), |
| 1803 | 2 * vixl32::k16BitT32InstructionSizeInBytes, |
| 1804 | CodeBufferCheckScope::kExactSize); |
| 1805 | |
| 1806 | __ it(eq); |
| 1807 | __ cmp(eq, LowRegisterFrom(left), LowRegisterFrom(right)); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1808 | ret = std::make_pair(ARMUnsignedCondition(cond), ARMUnsignedCondition(opposite)); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1809 | break; |
| 1810 | } |
| 1811 | case kCondLE: |
| 1812 | case kCondGT: |
| 1813 | if (cond == kCondLE) { |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1814 | DCHECK_EQ(opposite, kCondGT); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1815 | cond = kCondGE; |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1816 | opposite = kCondLT; |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1817 | } else { |
| 1818 | DCHECK_EQ(cond, kCondGT); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1819 | DCHECK_EQ(opposite, kCondLE); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1820 | cond = kCondLT; |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1821 | opposite = kCondGE; |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1822 | } |
| 1823 | |
| 1824 | std::swap(left, right); |
| 1825 | FALLTHROUGH_INTENDED; |
| 1826 | case kCondGE: |
| 1827 | case kCondLT: { |
| 1828 | UseScratchRegisterScope temps(codegen->GetVIXLAssembler()); |
| 1829 | |
| 1830 | __ Cmp(LowRegisterFrom(left), LowRegisterFrom(right)); |
| 1831 | __ Sbcs(temps.Acquire(), HighRegisterFrom(left), HighRegisterFrom(right)); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1832 | ret = std::make_pair(ARMCondition(cond), ARMCondition(opposite)); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1833 | break; |
| 1834 | } |
| 1835 | default: |
| 1836 | LOG(FATAL) << "Unreachable"; |
| 1837 | UNREACHABLE(); |
| 1838 | } |
| 1839 | |
| 1840 | return ret; |
| 1841 | } |
| 1842 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1843 | static std::pair<vixl32::Condition, vixl32::Condition> GenerateTest(HCondition* condition, |
| 1844 | bool invert, |
| 1845 | CodeGeneratorARMVIXL* codegen) { |
| 1846 | const Primitive::Type type = condition->GetLeft()->GetType(); |
| 1847 | IfCondition cond = condition->GetCondition(); |
| 1848 | IfCondition opposite = condition->GetOppositeCondition(); |
| 1849 | std::pair<vixl32::Condition, vixl32::Condition> ret(eq, ne); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1850 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1851 | if (invert) { |
| 1852 | std::swap(cond, opposite); |
| 1853 | } |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1854 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1855 | if (type == Primitive::kPrimLong) { |
| 1856 | ret = condition->GetLocations()->InAt(1).IsConstant() |
| 1857 | ? GenerateLongTestConstant(condition, invert, codegen) |
| 1858 | : GenerateLongTest(condition, invert, codegen); |
| 1859 | } else if (Primitive::IsFloatingPointType(type)) { |
| 1860 | GenerateVcmp(condition, codegen); |
| 1861 | __ Vmrs(RegisterOrAPSR_nzcv(kPcCode), FPSCR); |
| 1862 | ret = std::make_pair(ARMFPCondition(cond, condition->IsGtBias()), |
| 1863 | ARMFPCondition(opposite, condition->IsGtBias())); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1864 | } else { |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1865 | DCHECK(Primitive::IsIntegralType(type) || type == Primitive::kPrimNot) << type; |
| 1866 | __ Cmp(InputRegisterAt(condition, 0), InputOperandAt(condition, 1)); |
| 1867 | ret = std::make_pair(ARMCondition(cond), ARMCondition(opposite)); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1868 | } |
| 1869 | |
| 1870 | return ret; |
| 1871 | } |
| 1872 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1873 | static bool CanGenerateTest(HCondition* condition, ArmVIXLAssembler* assembler) { |
| 1874 | if (condition->GetLeft()->GetType() == Primitive::kPrimLong) { |
| 1875 | const LocationSummary* const locations = condition->GetLocations(); |
| 1876 | const IfCondition c = condition->GetCondition(); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1877 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1878 | if (locations->InAt(1).IsConstant()) { |
| 1879 | const int64_t value = Int64ConstantFrom(locations->InAt(1)); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1880 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1881 | if (c < kCondLT || c > kCondGE) { |
| 1882 | // Since IT blocks longer than a 16-bit instruction are deprecated by ARMv8, |
| 1883 | // we check that the least significant half of the first input to be compared |
| 1884 | // is in a low register (the other half is read outside an IT block), and |
| 1885 | // the constant fits in an 8-bit unsigned integer, so that a 16-bit CMP |
| 1886 | // encoding can be used. |
| 1887 | if (!LowRegisterFrom(locations->InAt(0)).IsLow() || !IsUint<8>(Low32Bits(value))) { |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1888 | return false; |
| 1889 | } |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1890 | // TODO(VIXL): The rest of the checks are there to keep the backend in sync with |
| 1891 | // the previous one, but are not strictly necessary. |
| 1892 | } else if (c == kCondLE || c == kCondGT) { |
| 1893 | if (value < std::numeric_limits<int64_t>::max() && |
| 1894 | !assembler->ShifterOperandCanHold(SBC, High32Bits(value + 1), kCcSet)) { |
| 1895 | return false; |
| 1896 | } |
| 1897 | } else if (!assembler->ShifterOperandCanHold(SBC, High32Bits(value), kCcSet)) { |
| 1898 | return false; |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1899 | } |
| 1900 | } |
| 1901 | } |
| 1902 | |
| 1903 | return true; |
| 1904 | } |
| 1905 | |
| 1906 | static bool CanEncodeConstantAs8BitImmediate(HConstant* constant) { |
| 1907 | const Primitive::Type type = constant->GetType(); |
| 1908 | bool ret = false; |
| 1909 | |
| 1910 | DCHECK(Primitive::IsIntegralType(type) || type == Primitive::kPrimNot) << type; |
| 1911 | |
| 1912 | if (type == Primitive::kPrimLong) { |
| 1913 | const uint64_t value = Uint64ConstantFrom(constant); |
| 1914 | |
| 1915 | ret = IsUint<8>(Low32Bits(value)) && IsUint<8>(High32Bits(value)); |
| 1916 | } else { |
| 1917 | ret = IsUint<8>(Int32ConstantFrom(constant)); |
| 1918 | } |
| 1919 | |
| 1920 | return ret; |
| 1921 | } |
| 1922 | |
| 1923 | static Location Arm8BitEncodableConstantOrRegister(HInstruction* constant) { |
| 1924 | DCHECK(!Primitive::IsFloatingPointType(constant->GetType())); |
| 1925 | |
| 1926 | if (constant->IsConstant() && CanEncodeConstantAs8BitImmediate(constant->AsConstant())) { |
| 1927 | return Location::ConstantLocation(constant->AsConstant()); |
| 1928 | } |
| 1929 | |
| 1930 | return Location::RequiresRegister(); |
| 1931 | } |
| 1932 | |
| 1933 | static bool CanGenerateConditionalMove(const Location& out, const Location& src) { |
| 1934 | // Since IT blocks longer than a 16-bit instruction are deprecated by ARMv8, |
| 1935 | // we check that we are not dealing with floating-point output (there is no |
| 1936 | // 16-bit VMOV encoding). |
| 1937 | if (!out.IsRegister() && !out.IsRegisterPair()) { |
| 1938 | return false; |
| 1939 | } |
| 1940 | |
| 1941 | // For constants, we also check that the output is in one or two low registers, |
| 1942 | // and that the constants fit in an 8-bit unsigned integer, so that a 16-bit |
| 1943 | // MOV encoding can be used. |
| 1944 | if (src.IsConstant()) { |
| 1945 | if (!CanEncodeConstantAs8BitImmediate(src.GetConstant())) { |
| 1946 | return false; |
| 1947 | } |
| 1948 | |
| 1949 | if (out.IsRegister()) { |
| 1950 | if (!RegisterFrom(out).IsLow()) { |
| 1951 | return false; |
| 1952 | } |
| 1953 | } else { |
| 1954 | DCHECK(out.IsRegisterPair()); |
| 1955 | |
| 1956 | if (!HighRegisterFrom(out).IsLow()) { |
| 1957 | return false; |
| 1958 | } |
| 1959 | } |
| 1960 | } |
| 1961 | |
| 1962 | return true; |
| 1963 | } |
| 1964 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1965 | #undef __ |
| 1966 | |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1967 | vixl32::Label* CodeGeneratorARMVIXL::GetFinalLabel(HInstruction* instruction, |
| 1968 | vixl32::Label* final_label) { |
| 1969 | DCHECK(!instruction->IsControlFlow() && !instruction->IsSuspendCheck()); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 1970 | DCHECK(!instruction->IsInvoke() || !instruction->GetLocations()->CanCall()); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1971 | |
| 1972 | const HBasicBlock* const block = instruction->GetBlock(); |
| 1973 | const HLoopInformation* const info = block->GetLoopInformation(); |
| 1974 | HInstruction* const next = instruction->GetNext(); |
| 1975 | |
| 1976 | // Avoid a branch to a branch. |
| 1977 | if (next->IsGoto() && (info == nullptr || |
| 1978 | !info->IsBackEdge(*block) || |
| 1979 | !info->HasSuspendCheck())) { |
| 1980 | final_label = GetLabelOf(next->AsGoto()->GetSuccessor()); |
| 1981 | } |
| 1982 | |
| 1983 | return final_label; |
| 1984 | } |
| 1985 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1986 | CodeGeneratorARMVIXL::CodeGeneratorARMVIXL(HGraph* graph, |
| 1987 | const ArmInstructionSetFeatures& isa_features, |
| 1988 | const CompilerOptions& compiler_options, |
| 1989 | OptimizingCompilerStats* stats) |
| 1990 | : CodeGenerator(graph, |
| 1991 | kNumberOfCoreRegisters, |
| 1992 | kNumberOfSRegisters, |
| 1993 | kNumberOfRegisterPairs, |
| 1994 | kCoreCalleeSaves.GetList(), |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 1995 | ComputeSRegisterListMask(kFpuCalleeSaves), |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1996 | compiler_options, |
| 1997 | stats), |
| 1998 | block_labels_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 1999 | jump_tables_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2000 | location_builder_(graph, this), |
| 2001 | instruction_visitor_(graph, this), |
| 2002 | move_resolver_(graph->GetArena(), this), |
| 2003 | assembler_(graph->GetArena()), |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2004 | isa_features_(isa_features), |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 2005 | uint32_literals_(std::less<uint32_t>(), |
| 2006 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2007 | pc_relative_dex_cache_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 2008 | boot_image_string_patches_(StringReferenceValueComparator(), |
| 2009 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2010 | pc_relative_string_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 2011 | boot_image_type_patches_(TypeReferenceValueComparator(), |
| 2012 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 2013 | pc_relative_type_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 2014 | type_bss_entry_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 2015 | jit_string_patches_(StringReferenceValueComparator(), |
| 2016 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 2017 | jit_class_patches_(TypeReferenceValueComparator(), |
| 2018 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)) { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2019 | // Always save the LR register to mimic Quick. |
| 2020 | AddAllocatedRegister(Location::RegisterLocation(LR)); |
Nicolas Geoffray | 13a797b | 2017-03-15 16:41:31 +0000 | [diff] [blame] | 2021 | // Give D30 and D31 as scratch register to VIXL. The register allocator only works on |
| 2022 | // S0-S31, which alias to D0-D15. |
| 2023 | GetVIXLAssembler()->GetScratchVRegisterList()->Combine(d31); |
| 2024 | GetVIXLAssembler()->GetScratchVRegisterList()->Combine(d30); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2025 | } |
| 2026 | |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 2027 | void JumpTableARMVIXL::EmitTable(CodeGeneratorARMVIXL* codegen) { |
| 2028 | uint32_t num_entries = switch_instr_->GetNumEntries(); |
| 2029 | DCHECK_GE(num_entries, kPackedSwitchCompareJumpThreshold); |
| 2030 | |
| 2031 | // 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] | 2032 | // underlying code buffer and we have generated a jump table of the right size, using |
| 2033 | // codegen->GetVIXLAssembler()->GetBuffer().Align(); |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 2034 | ExactAssemblyScope aas(codegen->GetVIXLAssembler(), |
| 2035 | num_entries * sizeof(int32_t), |
| 2036 | CodeBufferCheckScope::kMaximumSize); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 2037 | // TODO(VIXL): Check that using lower case bind is fine here. |
| 2038 | codegen->GetVIXLAssembler()->bind(&table_start_); |
Artem Serov | 09a940d | 2016-11-11 16:15:11 +0000 | [diff] [blame] | 2039 | for (uint32_t i = 0; i < num_entries; i++) { |
| 2040 | codegen->GetVIXLAssembler()->place(bb_addresses_[i].get()); |
| 2041 | } |
| 2042 | } |
| 2043 | |
| 2044 | void JumpTableARMVIXL::FixTable(CodeGeneratorARMVIXL* codegen) { |
| 2045 | uint32_t num_entries = switch_instr_->GetNumEntries(); |
| 2046 | DCHECK_GE(num_entries, kPackedSwitchCompareJumpThreshold); |
| 2047 | |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 2048 | const ArenaVector<HBasicBlock*>& successors = switch_instr_->GetBlock()->GetSuccessors(); |
| 2049 | for (uint32_t i = 0; i < num_entries; i++) { |
| 2050 | vixl32::Label* target_label = codegen->GetLabelOf(successors[i]); |
| 2051 | DCHECK(target_label->IsBound()); |
| 2052 | int32_t jump_offset = target_label->GetLocation() - table_start_.GetLocation(); |
| 2053 | // When doing BX to address we need to have lower bit set to 1 in T32. |
| 2054 | if (codegen->GetVIXLAssembler()->IsUsingT32()) { |
| 2055 | jump_offset++; |
| 2056 | } |
| 2057 | DCHECK_GT(jump_offset, std::numeric_limits<int32_t>::min()); |
| 2058 | DCHECK_LE(jump_offset, std::numeric_limits<int32_t>::max()); |
Artem Serov | 09a940d | 2016-11-11 16:15:11 +0000 | [diff] [blame] | 2059 | |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 2060 | bb_addresses_[i].get()->UpdateValue(jump_offset, codegen->GetVIXLAssembler()->GetBuffer()); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 2061 | } |
| 2062 | } |
| 2063 | |
Artem Serov | 09a940d | 2016-11-11 16:15:11 +0000 | [diff] [blame] | 2064 | void CodeGeneratorARMVIXL::FixJumpTables() { |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 2065 | for (auto&& jump_table : jump_tables_) { |
Artem Serov | 09a940d | 2016-11-11 16:15:11 +0000 | [diff] [blame] | 2066 | jump_table->FixTable(this); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 2067 | } |
| 2068 | } |
| 2069 | |
Andreas Gampe | ca620d7 | 2016-11-08 08:09:33 -0800 | [diff] [blame] | 2070 | #define __ reinterpret_cast<ArmVIXLAssembler*>(GetAssembler())->GetVIXLAssembler()-> // NOLINT |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2071 | |
| 2072 | void CodeGeneratorARMVIXL::Finalize(CodeAllocator* allocator) { |
Artem Serov | 09a940d | 2016-11-11 16:15:11 +0000 | [diff] [blame] | 2073 | FixJumpTables(); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2074 | GetAssembler()->FinalizeCode(); |
| 2075 | CodeGenerator::Finalize(allocator); |
| 2076 | } |
| 2077 | |
| 2078 | void CodeGeneratorARMVIXL::SetupBlockedRegisters() const { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2079 | // Stack register, LR and PC are always reserved. |
| 2080 | blocked_core_registers_[SP] = true; |
| 2081 | blocked_core_registers_[LR] = true; |
| 2082 | blocked_core_registers_[PC] = true; |
| 2083 | |
| 2084 | // Reserve thread register. |
| 2085 | blocked_core_registers_[TR] = true; |
| 2086 | |
| 2087 | // Reserve temp register. |
| 2088 | blocked_core_registers_[IP] = true; |
| 2089 | |
| 2090 | if (GetGraph()->IsDebuggable()) { |
| 2091 | // Stubs do not save callee-save floating point registers. If the graph |
| 2092 | // is debuggable, we need to deal with these registers differently. For |
| 2093 | // now, just block them. |
| 2094 | for (uint32_t i = kFpuCalleeSaves.GetFirstSRegister().GetCode(); |
| 2095 | i <= kFpuCalleeSaves.GetLastSRegister().GetCode(); |
| 2096 | ++i) { |
| 2097 | blocked_fpu_registers_[i] = true; |
| 2098 | } |
| 2099 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2100 | } |
| 2101 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2102 | InstructionCodeGeneratorARMVIXL::InstructionCodeGeneratorARMVIXL(HGraph* graph, |
| 2103 | CodeGeneratorARMVIXL* codegen) |
| 2104 | : InstructionCodeGenerator(graph, codegen), |
| 2105 | assembler_(codegen->GetAssembler()), |
| 2106 | codegen_(codegen) {} |
| 2107 | |
| 2108 | void CodeGeneratorARMVIXL::ComputeSpillMask() { |
| 2109 | core_spill_mask_ = allocated_registers_.GetCoreRegisters() & core_callee_save_mask_; |
| 2110 | DCHECK_NE(core_spill_mask_, 0u) << "At least the return address register must be saved"; |
| 2111 | // There is no easy instruction to restore just the PC on thumb2. We spill and |
| 2112 | // restore another arbitrary register. |
| 2113 | core_spill_mask_ |= (1 << kCoreAlwaysSpillRegister.GetCode()); |
| 2114 | fpu_spill_mask_ = allocated_registers_.GetFloatingPointRegisters() & fpu_callee_save_mask_; |
| 2115 | // We use vpush and vpop for saving and restoring floating point registers, which take |
| 2116 | // a SRegister and the number of registers to save/restore after that SRegister. We |
| 2117 | // therefore update the `fpu_spill_mask_` to also contain those registers not allocated, |
| 2118 | // but in the range. |
| 2119 | if (fpu_spill_mask_ != 0) { |
| 2120 | uint32_t least_significant_bit = LeastSignificantBit(fpu_spill_mask_); |
| 2121 | uint32_t most_significant_bit = MostSignificantBit(fpu_spill_mask_); |
| 2122 | for (uint32_t i = least_significant_bit + 1 ; i < most_significant_bit; ++i) { |
| 2123 | fpu_spill_mask_ |= (1 << i); |
| 2124 | } |
| 2125 | } |
| 2126 | } |
| 2127 | |
| 2128 | void CodeGeneratorARMVIXL::GenerateFrameEntry() { |
| 2129 | bool skip_overflow_check = |
| 2130 | IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kArm); |
| 2131 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
| 2132 | __ Bind(&frame_entry_label_); |
| 2133 | |
| 2134 | if (HasEmptyFrame()) { |
| 2135 | return; |
| 2136 | } |
| 2137 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2138 | if (!skip_overflow_check) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2139 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2140 | vixl32::Register temp = temps.Acquire(); |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 2141 | __ Sub(temp, sp, Operand::From(GetStackOverflowReservedBytes(kArm))); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2142 | // The load must immediately precede RecordPcInfo. |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 2143 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 2144 | vixl32::kMaxInstructionSizeInBytes, |
| 2145 | CodeBufferCheckScope::kMaximumSize); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2146 | __ ldr(temp, MemOperand(temp)); |
| 2147 | RecordPcInfo(nullptr, 0); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2148 | } |
| 2149 | |
| 2150 | __ Push(RegisterList(core_spill_mask_)); |
| 2151 | GetAssembler()->cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(core_spill_mask_)); |
| 2152 | GetAssembler()->cfi().RelOffsetForMany(DWARFReg(kMethodRegister), |
| 2153 | 0, |
| 2154 | core_spill_mask_, |
| 2155 | kArmWordSize); |
| 2156 | if (fpu_spill_mask_ != 0) { |
| 2157 | uint32_t first = LeastSignificantBit(fpu_spill_mask_); |
| 2158 | |
| 2159 | // Check that list is contiguous. |
| 2160 | DCHECK_EQ(fpu_spill_mask_ >> CTZ(fpu_spill_mask_), ~0u >> (32 - POPCOUNT(fpu_spill_mask_))); |
| 2161 | |
| 2162 | __ Vpush(SRegisterList(vixl32::SRegister(first), POPCOUNT(fpu_spill_mask_))); |
| 2163 | GetAssembler()->cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(fpu_spill_mask_)); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2164 | GetAssembler()->cfi().RelOffsetForMany(DWARFReg(s0), 0, fpu_spill_mask_, kArmWordSize); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2165 | } |
Scott Wakeling | bffdc70 | 2016-12-07 17:46:03 +0000 | [diff] [blame] | 2166 | |
| 2167 | if (GetGraph()->HasShouldDeoptimizeFlag()) { |
| 2168 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2169 | vixl32::Register temp = temps.Acquire(); |
| 2170 | // Initialize should_deoptimize flag to 0. |
| 2171 | __ Mov(temp, 0); |
| 2172 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, -kShouldDeoptimizeFlagSize); |
| 2173 | } |
| 2174 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2175 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 2176 | __ Sub(sp, sp, adjust); |
| 2177 | GetAssembler()->cfi().AdjustCFAOffset(adjust); |
Scott Wakeling | bffdc70 | 2016-12-07 17:46:03 +0000 | [diff] [blame] | 2178 | |
| 2179 | // Save the current method if we need it. Note that we do not |
| 2180 | // do this in HCurrentMethod, as the instruction might have been removed |
| 2181 | // in the SSA graph. |
| 2182 | if (RequiresCurrentMethod()) { |
| 2183 | GetAssembler()->StoreToOffset(kStoreWord, kMethodRegister, sp, 0); |
| 2184 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2185 | } |
| 2186 | |
| 2187 | void CodeGeneratorARMVIXL::GenerateFrameExit() { |
| 2188 | if (HasEmptyFrame()) { |
| 2189 | __ Bx(lr); |
| 2190 | return; |
| 2191 | } |
| 2192 | GetAssembler()->cfi().RememberState(); |
| 2193 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 2194 | __ Add(sp, sp, adjust); |
| 2195 | GetAssembler()->cfi().AdjustCFAOffset(-adjust); |
| 2196 | if (fpu_spill_mask_ != 0) { |
| 2197 | uint32_t first = LeastSignificantBit(fpu_spill_mask_); |
| 2198 | |
| 2199 | // Check that list is contiguous. |
| 2200 | DCHECK_EQ(fpu_spill_mask_ >> CTZ(fpu_spill_mask_), ~0u >> (32 - POPCOUNT(fpu_spill_mask_))); |
| 2201 | |
| 2202 | __ Vpop(SRegisterList(vixl32::SRegister(first), POPCOUNT(fpu_spill_mask_))); |
| 2203 | GetAssembler()->cfi().AdjustCFAOffset( |
| 2204 | -static_cast<int>(kArmWordSize) * POPCOUNT(fpu_spill_mask_)); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2205 | GetAssembler()->cfi().RestoreMany(DWARFReg(vixl32::SRegister(0)), fpu_spill_mask_); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2206 | } |
| 2207 | // Pop LR into PC to return. |
| 2208 | DCHECK_NE(core_spill_mask_ & (1 << kLrCode), 0U); |
| 2209 | uint32_t pop_mask = (core_spill_mask_ & (~(1 << kLrCode))) | 1 << kPcCode; |
| 2210 | __ Pop(RegisterList(pop_mask)); |
| 2211 | GetAssembler()->cfi().RestoreState(); |
| 2212 | GetAssembler()->cfi().DefCFAOffset(GetFrameSize()); |
| 2213 | } |
| 2214 | |
| 2215 | void CodeGeneratorARMVIXL::Bind(HBasicBlock* block) { |
| 2216 | __ Bind(GetLabelOf(block)); |
| 2217 | } |
| 2218 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2219 | Location InvokeDexCallingConventionVisitorARMVIXL::GetNextLocation(Primitive::Type type) { |
| 2220 | switch (type) { |
| 2221 | case Primitive::kPrimBoolean: |
| 2222 | case Primitive::kPrimByte: |
| 2223 | case Primitive::kPrimChar: |
| 2224 | case Primitive::kPrimShort: |
| 2225 | case Primitive::kPrimInt: |
| 2226 | case Primitive::kPrimNot: { |
| 2227 | uint32_t index = gp_index_++; |
| 2228 | uint32_t stack_index = stack_index_++; |
| 2229 | if (index < calling_convention.GetNumberOfRegisters()) { |
| 2230 | return LocationFrom(calling_convention.GetRegisterAt(index)); |
| 2231 | } else { |
| 2232 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
| 2233 | } |
| 2234 | } |
| 2235 | |
| 2236 | case Primitive::kPrimLong: { |
| 2237 | uint32_t index = gp_index_; |
| 2238 | uint32_t stack_index = stack_index_; |
| 2239 | gp_index_ += 2; |
| 2240 | stack_index_ += 2; |
| 2241 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
| 2242 | if (calling_convention.GetRegisterAt(index).Is(r1)) { |
| 2243 | // Skip R1, and use R2_R3 instead. |
| 2244 | gp_index_++; |
| 2245 | index++; |
| 2246 | } |
| 2247 | } |
| 2248 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
| 2249 | DCHECK_EQ(calling_convention.GetRegisterAt(index).GetCode() + 1, |
| 2250 | calling_convention.GetRegisterAt(index + 1).GetCode()); |
| 2251 | |
| 2252 | return LocationFrom(calling_convention.GetRegisterAt(index), |
| 2253 | calling_convention.GetRegisterAt(index + 1)); |
| 2254 | } else { |
| 2255 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
| 2256 | } |
| 2257 | } |
| 2258 | |
| 2259 | case Primitive::kPrimFloat: { |
| 2260 | uint32_t stack_index = stack_index_++; |
| 2261 | if (float_index_ % 2 == 0) { |
| 2262 | float_index_ = std::max(double_index_, float_index_); |
| 2263 | } |
| 2264 | if (float_index_ < calling_convention.GetNumberOfFpuRegisters()) { |
| 2265 | return LocationFrom(calling_convention.GetFpuRegisterAt(float_index_++)); |
| 2266 | } else { |
| 2267 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
| 2268 | } |
| 2269 | } |
| 2270 | |
| 2271 | case Primitive::kPrimDouble: { |
| 2272 | double_index_ = std::max(double_index_, RoundUp(float_index_, 2)); |
| 2273 | uint32_t stack_index = stack_index_; |
| 2274 | stack_index_ += 2; |
| 2275 | if (double_index_ + 1 < calling_convention.GetNumberOfFpuRegisters()) { |
| 2276 | uint32_t index = double_index_; |
| 2277 | double_index_ += 2; |
| 2278 | Location result = LocationFrom( |
| 2279 | calling_convention.GetFpuRegisterAt(index), |
| 2280 | calling_convention.GetFpuRegisterAt(index + 1)); |
| 2281 | DCHECK(ExpectedPairLayout(result)); |
| 2282 | return result; |
| 2283 | } else { |
| 2284 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
| 2285 | } |
| 2286 | } |
| 2287 | |
| 2288 | case Primitive::kPrimVoid: |
| 2289 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 2290 | break; |
| 2291 | } |
| 2292 | return Location::NoLocation(); |
| 2293 | } |
| 2294 | |
| 2295 | Location InvokeDexCallingConventionVisitorARMVIXL::GetReturnLocation(Primitive::Type type) const { |
| 2296 | switch (type) { |
| 2297 | case Primitive::kPrimBoolean: |
| 2298 | case Primitive::kPrimByte: |
| 2299 | case Primitive::kPrimChar: |
| 2300 | case Primitive::kPrimShort: |
| 2301 | case Primitive::kPrimInt: |
| 2302 | case Primitive::kPrimNot: { |
| 2303 | return LocationFrom(r0); |
| 2304 | } |
| 2305 | |
| 2306 | case Primitive::kPrimFloat: { |
| 2307 | return LocationFrom(s0); |
| 2308 | } |
| 2309 | |
| 2310 | case Primitive::kPrimLong: { |
| 2311 | return LocationFrom(r0, r1); |
| 2312 | } |
| 2313 | |
| 2314 | case Primitive::kPrimDouble: { |
| 2315 | return LocationFrom(s0, s1); |
| 2316 | } |
| 2317 | |
| 2318 | case Primitive::kPrimVoid: |
| 2319 | return Location::NoLocation(); |
| 2320 | } |
| 2321 | |
| 2322 | UNREACHABLE(); |
| 2323 | } |
| 2324 | |
| 2325 | Location InvokeDexCallingConventionVisitorARMVIXL::GetMethodLocation() const { |
| 2326 | return LocationFrom(kMethodRegister); |
| 2327 | } |
| 2328 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2329 | void CodeGeneratorARMVIXL::Move32(Location destination, Location source) { |
| 2330 | if (source.Equals(destination)) { |
| 2331 | return; |
| 2332 | } |
| 2333 | if (destination.IsRegister()) { |
| 2334 | if (source.IsRegister()) { |
| 2335 | __ Mov(RegisterFrom(destination), RegisterFrom(source)); |
| 2336 | } else if (source.IsFpuRegister()) { |
| 2337 | __ Vmov(RegisterFrom(destination), SRegisterFrom(source)); |
| 2338 | } else { |
| 2339 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 2340 | RegisterFrom(destination), |
| 2341 | sp, |
| 2342 | source.GetStackIndex()); |
| 2343 | } |
| 2344 | } else if (destination.IsFpuRegister()) { |
| 2345 | if (source.IsRegister()) { |
| 2346 | __ Vmov(SRegisterFrom(destination), RegisterFrom(source)); |
| 2347 | } else if (source.IsFpuRegister()) { |
| 2348 | __ Vmov(SRegisterFrom(destination), SRegisterFrom(source)); |
| 2349 | } else { |
| 2350 | GetAssembler()->LoadSFromOffset(SRegisterFrom(destination), sp, source.GetStackIndex()); |
| 2351 | } |
| 2352 | } else { |
| 2353 | DCHECK(destination.IsStackSlot()) << destination; |
| 2354 | if (source.IsRegister()) { |
| 2355 | GetAssembler()->StoreToOffset(kStoreWord, |
| 2356 | RegisterFrom(source), |
| 2357 | sp, |
| 2358 | destination.GetStackIndex()); |
| 2359 | } else if (source.IsFpuRegister()) { |
| 2360 | GetAssembler()->StoreSToOffset(SRegisterFrom(source), sp, destination.GetStackIndex()); |
| 2361 | } else { |
| 2362 | DCHECK(source.IsStackSlot()) << source; |
| 2363 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2364 | vixl32::Register temp = temps.Acquire(); |
| 2365 | GetAssembler()->LoadFromOffset(kLoadWord, temp, sp, source.GetStackIndex()); |
| 2366 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, destination.GetStackIndex()); |
| 2367 | } |
| 2368 | } |
| 2369 | } |
| 2370 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 2371 | void CodeGeneratorARMVIXL::MoveConstant(Location location, int32_t value) { |
| 2372 | DCHECK(location.IsRegister()); |
| 2373 | __ Mov(RegisterFrom(location), value); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2374 | } |
| 2375 | |
| 2376 | void CodeGeneratorARMVIXL::MoveLocation(Location dst, Location src, Primitive::Type dst_type) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2377 | // TODO(VIXL): Maybe refactor to have the 'move' implementation here and use it in |
| 2378 | // `ParallelMoveResolverARMVIXL::EmitMove`, as is done in the `arm64` backend. |
| 2379 | HParallelMove move(GetGraph()->GetArena()); |
| 2380 | move.AddMove(src, dst, dst_type, nullptr); |
| 2381 | GetMoveResolver()->EmitNativeCode(&move); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2382 | } |
| 2383 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 2384 | void CodeGeneratorARMVIXL::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 2385 | if (location.IsRegister()) { |
| 2386 | locations->AddTemp(location); |
| 2387 | } else if (location.IsRegisterPair()) { |
| 2388 | locations->AddTemp(LocationFrom(LowRegisterFrom(location))); |
| 2389 | locations->AddTemp(LocationFrom(HighRegisterFrom(location))); |
| 2390 | } else { |
| 2391 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 2392 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2393 | } |
| 2394 | |
| 2395 | void CodeGeneratorARMVIXL::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 2396 | HInstruction* instruction, |
| 2397 | uint32_t dex_pc, |
| 2398 | SlowPathCode* slow_path) { |
| 2399 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 2400 | __ Ldr(lr, MemOperand(tr, GetThreadOffset<kArmPointerSize>(entrypoint).Int32Value())); |
| 2401 | // Ensure the pc position is recorded immediately after the `blx` instruction. |
| 2402 | // 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] | 2403 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 2404 | vixl32::k16BitT32InstructionSizeInBytes, |
| 2405 | CodeBufferCheckScope::kExactSize); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 2406 | __ blx(lr); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2407 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 2408 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 2409 | } |
| 2410 | } |
| 2411 | |
| 2412 | void CodeGeneratorARMVIXL::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 2413 | HInstruction* instruction, |
| 2414 | SlowPathCode* slow_path) { |
| 2415 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 2416 | __ Ldr(lr, MemOperand(tr, entry_point_offset)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2417 | __ Blx(lr); |
| 2418 | } |
| 2419 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2420 | void InstructionCodeGeneratorARMVIXL::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
| 2421 | DCHECK(!successor->IsExitBlock()); |
| 2422 | HBasicBlock* block = got->GetBlock(); |
| 2423 | HInstruction* previous = got->GetPrevious(); |
| 2424 | HLoopInformation* info = block->GetLoopInformation(); |
| 2425 | |
| 2426 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
| 2427 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck()); |
| 2428 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 2429 | return; |
| 2430 | } |
| 2431 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 2432 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 2433 | } |
| 2434 | if (!codegen_->GoesToNextBlock(block, successor)) { |
| 2435 | __ B(codegen_->GetLabelOf(successor)); |
| 2436 | } |
| 2437 | } |
| 2438 | |
| 2439 | void LocationsBuilderARMVIXL::VisitGoto(HGoto* got) { |
| 2440 | got->SetLocations(nullptr); |
| 2441 | } |
| 2442 | |
| 2443 | void InstructionCodeGeneratorARMVIXL::VisitGoto(HGoto* got) { |
| 2444 | HandleGoto(got, got->GetSuccessor()); |
| 2445 | } |
| 2446 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2447 | void LocationsBuilderARMVIXL::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 2448 | try_boundary->SetLocations(nullptr); |
| 2449 | } |
| 2450 | |
| 2451 | void InstructionCodeGeneratorARMVIXL::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 2452 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 2453 | if (!successor->IsExitBlock()) { |
| 2454 | HandleGoto(try_boundary, successor); |
| 2455 | } |
| 2456 | } |
| 2457 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2458 | void LocationsBuilderARMVIXL::VisitExit(HExit* exit) { |
| 2459 | exit->SetLocations(nullptr); |
| 2460 | } |
| 2461 | |
| 2462 | void InstructionCodeGeneratorARMVIXL::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
| 2463 | } |
| 2464 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2465 | void InstructionCodeGeneratorARMVIXL::GenerateLongComparesAndJumps(HCondition* cond, |
| 2466 | vixl32::Label* true_label, |
| 2467 | vixl32::Label* false_label) { |
| 2468 | LocationSummary* locations = cond->GetLocations(); |
| 2469 | Location left = locations->InAt(0); |
| 2470 | Location right = locations->InAt(1); |
| 2471 | IfCondition if_cond = cond->GetCondition(); |
| 2472 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2473 | vixl32::Register left_high = HighRegisterFrom(left); |
| 2474 | vixl32::Register left_low = LowRegisterFrom(left); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2475 | IfCondition true_high_cond = if_cond; |
| 2476 | IfCondition false_high_cond = cond->GetOppositeCondition(); |
| 2477 | vixl32::Condition final_condition = ARMUnsignedCondition(if_cond); // unsigned on lower part |
| 2478 | |
| 2479 | // Set the conditions for the test, remembering that == needs to be |
| 2480 | // decided using the low words. |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2481 | switch (if_cond) { |
| 2482 | case kCondEQ: |
| 2483 | case kCondNE: |
| 2484 | // Nothing to do. |
| 2485 | break; |
| 2486 | case kCondLT: |
| 2487 | false_high_cond = kCondGT; |
| 2488 | break; |
| 2489 | case kCondLE: |
| 2490 | true_high_cond = kCondLT; |
| 2491 | break; |
| 2492 | case kCondGT: |
| 2493 | false_high_cond = kCondLT; |
| 2494 | break; |
| 2495 | case kCondGE: |
| 2496 | true_high_cond = kCondGT; |
| 2497 | break; |
| 2498 | case kCondB: |
| 2499 | false_high_cond = kCondA; |
| 2500 | break; |
| 2501 | case kCondBE: |
| 2502 | true_high_cond = kCondB; |
| 2503 | break; |
| 2504 | case kCondA: |
| 2505 | false_high_cond = kCondB; |
| 2506 | break; |
| 2507 | case kCondAE: |
| 2508 | true_high_cond = kCondA; |
| 2509 | break; |
| 2510 | } |
| 2511 | if (right.IsConstant()) { |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 2512 | int64_t value = Int64ConstantFrom(right); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2513 | int32_t val_low = Low32Bits(value); |
| 2514 | int32_t val_high = High32Bits(value); |
| 2515 | |
| 2516 | __ Cmp(left_high, val_high); |
| 2517 | if (if_cond == kCondNE) { |
| 2518 | __ B(ARMCondition(true_high_cond), true_label); |
| 2519 | } else if (if_cond == kCondEQ) { |
| 2520 | __ B(ARMCondition(false_high_cond), false_label); |
| 2521 | } else { |
| 2522 | __ B(ARMCondition(true_high_cond), true_label); |
| 2523 | __ B(ARMCondition(false_high_cond), false_label); |
| 2524 | } |
| 2525 | // Must be equal high, so compare the lows. |
| 2526 | __ Cmp(left_low, val_low); |
| 2527 | } else { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2528 | vixl32::Register right_high = HighRegisterFrom(right); |
| 2529 | vixl32::Register right_low = LowRegisterFrom(right); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2530 | |
| 2531 | __ Cmp(left_high, right_high); |
| 2532 | if (if_cond == kCondNE) { |
| 2533 | __ B(ARMCondition(true_high_cond), true_label); |
| 2534 | } else if (if_cond == kCondEQ) { |
| 2535 | __ B(ARMCondition(false_high_cond), false_label); |
| 2536 | } else { |
| 2537 | __ B(ARMCondition(true_high_cond), true_label); |
| 2538 | __ B(ARMCondition(false_high_cond), false_label); |
| 2539 | } |
| 2540 | // Must be equal high, so compare the lows. |
| 2541 | __ Cmp(left_low, right_low); |
| 2542 | } |
| 2543 | // The last comparison might be unsigned. |
| 2544 | // TODO: optimize cases where this is always true/false |
| 2545 | __ B(final_condition, true_label); |
| 2546 | } |
| 2547 | |
| 2548 | void InstructionCodeGeneratorARMVIXL::GenerateCompareTestAndBranch(HCondition* condition, |
| 2549 | vixl32::Label* true_target_in, |
| 2550 | vixl32::Label* false_target_in) { |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2551 | if (CanGenerateTest(condition, codegen_->GetAssembler())) { |
| 2552 | vixl32::Label* non_fallthrough_target; |
| 2553 | bool invert; |
| 2554 | |
| 2555 | if (true_target_in == nullptr) { |
| 2556 | DCHECK(false_target_in != nullptr); |
| 2557 | non_fallthrough_target = false_target_in; |
| 2558 | invert = true; |
| 2559 | } else { |
| 2560 | non_fallthrough_target = true_target_in; |
| 2561 | invert = false; |
| 2562 | } |
| 2563 | |
| 2564 | const auto cond = GenerateTest(condition, invert, codegen_); |
| 2565 | |
| 2566 | __ B(cond.first, non_fallthrough_target); |
| 2567 | |
| 2568 | if (false_target_in != nullptr && false_target_in != non_fallthrough_target) { |
| 2569 | __ B(false_target_in); |
| 2570 | } |
| 2571 | |
| 2572 | return; |
| 2573 | } |
| 2574 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2575 | // Generated branching requires both targets to be explicit. If either of the |
| 2576 | // targets is nullptr (fallthrough) use and bind `fallthrough` instead. |
| 2577 | vixl32::Label fallthrough; |
| 2578 | vixl32::Label* true_target = (true_target_in == nullptr) ? &fallthrough : true_target_in; |
| 2579 | vixl32::Label* false_target = (false_target_in == nullptr) ? &fallthrough : false_target_in; |
| 2580 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2581 | DCHECK_EQ(condition->InputAt(0)->GetType(), Primitive::kPrimLong); |
| 2582 | GenerateLongComparesAndJumps(condition, true_target, false_target); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2583 | |
| 2584 | if (false_target != &fallthrough) { |
| 2585 | __ B(false_target); |
| 2586 | } |
| 2587 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2588 | if (fallthrough.IsReferenced()) { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2589 | __ Bind(&fallthrough); |
| 2590 | } |
| 2591 | } |
| 2592 | |
| 2593 | void InstructionCodeGeneratorARMVIXL::GenerateTestAndBranch(HInstruction* instruction, |
| 2594 | size_t condition_input_index, |
| 2595 | vixl32::Label* true_target, |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 2596 | vixl32::Label* false_target, |
| 2597 | bool far_target) { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2598 | HInstruction* cond = instruction->InputAt(condition_input_index); |
| 2599 | |
| 2600 | if (true_target == nullptr && false_target == nullptr) { |
| 2601 | // Nothing to do. The code always falls through. |
| 2602 | return; |
| 2603 | } else if (cond->IsIntConstant()) { |
| 2604 | // Constant condition, statically compared against "true" (integer value 1). |
| 2605 | if (cond->AsIntConstant()->IsTrue()) { |
| 2606 | if (true_target != nullptr) { |
| 2607 | __ B(true_target); |
| 2608 | } |
| 2609 | } else { |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 2610 | DCHECK(cond->AsIntConstant()->IsFalse()) << Int32ConstantFrom(cond); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2611 | if (false_target != nullptr) { |
| 2612 | __ B(false_target); |
| 2613 | } |
| 2614 | } |
| 2615 | return; |
| 2616 | } |
| 2617 | |
| 2618 | // The following code generates these patterns: |
| 2619 | // (1) true_target == nullptr && false_target != nullptr |
| 2620 | // - opposite condition true => branch to false_target |
| 2621 | // (2) true_target != nullptr && false_target == nullptr |
| 2622 | // - condition true => branch to true_target |
| 2623 | // (3) true_target != nullptr && false_target != nullptr |
| 2624 | // - condition true => branch to true_target |
| 2625 | // - branch to false_target |
| 2626 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 2627 | // Condition has been materialized, compare the output to 0. |
| 2628 | if (kIsDebugBuild) { |
| 2629 | Location cond_val = instruction->GetLocations()->InAt(condition_input_index); |
| 2630 | DCHECK(cond_val.IsRegister()); |
| 2631 | } |
| 2632 | if (true_target == nullptr) { |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 2633 | __ CompareAndBranchIfZero(InputRegisterAt(instruction, condition_input_index), |
| 2634 | false_target, |
| 2635 | far_target); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2636 | } else { |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 2637 | __ CompareAndBranchIfNonZero(InputRegisterAt(instruction, condition_input_index), |
| 2638 | true_target, |
| 2639 | far_target); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2640 | } |
| 2641 | } else { |
| 2642 | // Condition has not been materialized. Use its inputs as the comparison and |
| 2643 | // its condition as the branch condition. |
| 2644 | HCondition* condition = cond->AsCondition(); |
| 2645 | |
| 2646 | // If this is a long or FP comparison that has been folded into |
| 2647 | // the HCondition, generate the comparison directly. |
| 2648 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 2649 | if (type == Primitive::kPrimLong || Primitive::IsFloatingPointType(type)) { |
| 2650 | GenerateCompareTestAndBranch(condition, true_target, false_target); |
| 2651 | return; |
| 2652 | } |
| 2653 | |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2654 | vixl32::Label* non_fallthrough_target; |
| 2655 | vixl32::Condition arm_cond = vixl32::Condition::None(); |
| 2656 | const vixl32::Register left = InputRegisterAt(cond, 0); |
| 2657 | const Operand right = InputOperandAt(cond, 1); |
| 2658 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2659 | if (true_target == nullptr) { |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2660 | arm_cond = ARMCondition(condition->GetOppositeCondition()); |
| 2661 | non_fallthrough_target = false_target; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2662 | } else { |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2663 | arm_cond = ARMCondition(condition->GetCondition()); |
| 2664 | non_fallthrough_target = true_target; |
| 2665 | } |
| 2666 | |
| 2667 | if (right.IsImmediate() && right.GetImmediate() == 0 && (arm_cond.Is(ne) || arm_cond.Is(eq))) { |
| 2668 | if (arm_cond.Is(eq)) { |
| 2669 | __ CompareAndBranchIfZero(left, non_fallthrough_target); |
| 2670 | } else { |
| 2671 | DCHECK(arm_cond.Is(ne)); |
| 2672 | __ CompareAndBranchIfNonZero(left, non_fallthrough_target); |
| 2673 | } |
| 2674 | } else { |
| 2675 | __ Cmp(left, right); |
| 2676 | __ B(arm_cond, non_fallthrough_target); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2677 | } |
| 2678 | } |
| 2679 | |
| 2680 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 2681 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 2682 | if (true_target != nullptr && false_target != nullptr) { |
| 2683 | __ B(false_target); |
| 2684 | } |
| 2685 | } |
| 2686 | |
| 2687 | void LocationsBuilderARMVIXL::VisitIf(HIf* if_instr) { |
| 2688 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); |
| 2689 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
| 2690 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2691 | } |
| 2692 | } |
| 2693 | |
| 2694 | void InstructionCodeGeneratorARMVIXL::VisitIf(HIf* if_instr) { |
| 2695 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 2696 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2697 | vixl32::Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 2698 | nullptr : codegen_->GetLabelOf(true_successor); |
| 2699 | vixl32::Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 2700 | nullptr : codegen_->GetLabelOf(false_successor); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2701 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
| 2702 | } |
| 2703 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 2704 | void LocationsBuilderARMVIXL::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 2705 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 2706 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
| 2707 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| 2708 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
| 2709 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2710 | } |
| 2711 | } |
| 2712 | |
| 2713 | void InstructionCodeGeneratorARMVIXL::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 2714 | SlowPathCodeARMVIXL* slow_path = |
| 2715 | deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathARMVIXL>(deoptimize); |
| 2716 | GenerateTestAndBranch(deoptimize, |
| 2717 | /* condition_input_index */ 0, |
| 2718 | slow_path->GetEntryLabel(), |
| 2719 | /* false_target */ nullptr); |
| 2720 | } |
| 2721 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2722 | void LocationsBuilderARMVIXL::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 2723 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 2724 | LocationSummary(flag, LocationSummary::kNoCall); |
| 2725 | locations->SetOut(Location::RequiresRegister()); |
| 2726 | } |
| 2727 | |
| 2728 | void InstructionCodeGeneratorARMVIXL::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 2729 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 2730 | OutputRegister(flag), |
| 2731 | sp, |
| 2732 | codegen_->GetStackOffsetOfShouldDeoptimizeFlag()); |
| 2733 | } |
| 2734 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2735 | void LocationsBuilderARMVIXL::VisitSelect(HSelect* select) { |
| 2736 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(select); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2737 | const bool is_floating_point = Primitive::IsFloatingPointType(select->GetType()); |
| 2738 | |
| 2739 | if (is_floating_point) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2740 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2741 | locations->SetInAt(1, Location::FpuRegisterOrConstant(select->GetTrueValue())); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2742 | } else { |
| 2743 | locations->SetInAt(0, Location::RequiresRegister()); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2744 | locations->SetInAt(1, Arm8BitEncodableConstantOrRegister(select->GetTrueValue())); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2745 | } |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2746 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2747 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2748 | locations->SetInAt(2, Location::RegisterOrConstant(select->GetCondition())); |
| 2749 | // The code generator handles overlap with the values, but not with the condition. |
| 2750 | locations->SetOut(Location::SameAsFirstInput()); |
| 2751 | } else if (is_floating_point) { |
| 2752 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 2753 | } else { |
| 2754 | if (!locations->InAt(1).IsConstant()) { |
| 2755 | locations->SetInAt(0, Arm8BitEncodableConstantOrRegister(select->GetFalseValue())); |
| 2756 | } |
| 2757 | |
| 2758 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2759 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2760 | } |
| 2761 | |
| 2762 | void InstructionCodeGeneratorARMVIXL::VisitSelect(HSelect* select) { |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2763 | HInstruction* const condition = select->GetCondition(); |
| 2764 | const LocationSummary* const locations = select->GetLocations(); |
| 2765 | const Primitive::Type type = select->GetType(); |
| 2766 | const Location first = locations->InAt(0); |
| 2767 | const Location out = locations->Out(); |
| 2768 | const Location second = locations->InAt(1); |
| 2769 | Location src; |
| 2770 | |
| 2771 | if (condition->IsIntConstant()) { |
| 2772 | if (condition->AsIntConstant()->IsFalse()) { |
| 2773 | src = first; |
| 2774 | } else { |
| 2775 | src = second; |
| 2776 | } |
| 2777 | |
| 2778 | codegen_->MoveLocation(out, src, type); |
| 2779 | return; |
| 2780 | } |
| 2781 | |
| 2782 | if (!Primitive::IsFloatingPointType(type) && |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2783 | (IsBooleanValueOrMaterializedCondition(condition) || |
| 2784 | CanGenerateTest(condition->AsCondition(), codegen_->GetAssembler()))) { |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2785 | bool invert = false; |
| 2786 | |
| 2787 | if (out.Equals(second)) { |
| 2788 | src = first; |
| 2789 | invert = true; |
| 2790 | } else if (out.Equals(first)) { |
| 2791 | src = second; |
| 2792 | } else if (second.IsConstant()) { |
| 2793 | DCHECK(CanEncodeConstantAs8BitImmediate(second.GetConstant())); |
| 2794 | src = second; |
| 2795 | } else if (first.IsConstant()) { |
| 2796 | DCHECK(CanEncodeConstantAs8BitImmediate(first.GetConstant())); |
| 2797 | src = first; |
| 2798 | invert = true; |
| 2799 | } else { |
| 2800 | src = second; |
| 2801 | } |
| 2802 | |
| 2803 | if (CanGenerateConditionalMove(out, src)) { |
| 2804 | if (!out.Equals(first) && !out.Equals(second)) { |
| 2805 | codegen_->MoveLocation(out, src.Equals(first) ? second : first, type); |
| 2806 | } |
| 2807 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2808 | std::pair<vixl32::Condition, vixl32::Condition> cond(eq, ne); |
| 2809 | |
| 2810 | if (IsBooleanValueOrMaterializedCondition(condition)) { |
| 2811 | __ Cmp(InputRegisterAt(select, 2), 0); |
| 2812 | cond = invert ? std::make_pair(eq, ne) : std::make_pair(ne, eq); |
| 2813 | } else { |
| 2814 | cond = GenerateTest(condition->AsCondition(), invert, codegen_); |
| 2815 | } |
| 2816 | |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2817 | const size_t instr_count = out.IsRegisterPair() ? 4 : 2; |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2818 | // We use the scope because of the IT block that follows. |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2819 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 2820 | instr_count * vixl32::k16BitT32InstructionSizeInBytes, |
| 2821 | CodeBufferCheckScope::kExactSize); |
| 2822 | |
| 2823 | if (out.IsRegister()) { |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2824 | __ it(cond.first); |
| 2825 | __ mov(cond.first, RegisterFrom(out), OperandFrom(src, type)); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2826 | } else { |
| 2827 | DCHECK(out.IsRegisterPair()); |
| 2828 | |
| 2829 | Operand operand_high(0); |
| 2830 | Operand operand_low(0); |
| 2831 | |
| 2832 | if (src.IsConstant()) { |
| 2833 | const int64_t value = Int64ConstantFrom(src); |
| 2834 | |
| 2835 | operand_high = High32Bits(value); |
| 2836 | operand_low = Low32Bits(value); |
| 2837 | } else { |
| 2838 | DCHECK(src.IsRegisterPair()); |
| 2839 | operand_high = HighRegisterFrom(src); |
| 2840 | operand_low = LowRegisterFrom(src); |
| 2841 | } |
| 2842 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2843 | __ it(cond.first); |
| 2844 | __ mov(cond.first, LowRegisterFrom(out), operand_low); |
| 2845 | __ it(cond.first); |
| 2846 | __ mov(cond.first, HighRegisterFrom(out), operand_high); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2847 | } |
| 2848 | |
| 2849 | return; |
| 2850 | } |
| 2851 | } |
| 2852 | |
| 2853 | vixl32::Label* false_target = nullptr; |
| 2854 | vixl32::Label* true_target = nullptr; |
| 2855 | vixl32::Label select_end; |
| 2856 | vixl32::Label* const target = codegen_->GetFinalLabel(select, &select_end); |
| 2857 | |
| 2858 | if (out.Equals(second)) { |
| 2859 | true_target = target; |
| 2860 | src = first; |
| 2861 | } else { |
| 2862 | false_target = target; |
| 2863 | src = second; |
| 2864 | |
| 2865 | if (!out.Equals(first)) { |
| 2866 | codegen_->MoveLocation(out, first, type); |
| 2867 | } |
| 2868 | } |
| 2869 | |
| 2870 | GenerateTestAndBranch(select, 2, true_target, false_target, /* far_target */ false); |
| 2871 | codegen_->MoveLocation(out, src, type); |
| 2872 | |
| 2873 | if (select_end.IsReferenced()) { |
| 2874 | __ Bind(&select_end); |
| 2875 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2876 | } |
| 2877 | |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 2878 | void LocationsBuilderARMVIXL::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| 2879 | new (GetGraph()->GetArena()) LocationSummary(info); |
| 2880 | } |
| 2881 | |
| 2882 | void InstructionCodeGeneratorARMVIXL::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 2883 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
| 2884 | } |
| 2885 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2886 | void CodeGeneratorARMVIXL::GenerateNop() { |
| 2887 | __ Nop(); |
| 2888 | } |
| 2889 | |
| 2890 | void LocationsBuilderARMVIXL::HandleCondition(HCondition* cond) { |
| 2891 | LocationSummary* locations = |
| 2892 | new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall); |
| 2893 | // Handle the long/FP comparisons made in instruction simplification. |
| 2894 | switch (cond->InputAt(0)->GetType()) { |
| 2895 | case Primitive::kPrimLong: |
| 2896 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2897 | locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1))); |
| 2898 | if (!cond->IsEmittedAtUseSite()) { |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2899 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2900 | } |
| 2901 | break; |
| 2902 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2903 | case Primitive::kPrimFloat: |
| 2904 | case Primitive::kPrimDouble: |
| 2905 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 2906 | locations->SetInAt(1, ArithmeticZeroOrFpuRegister(cond->InputAt(1))); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2907 | if (!cond->IsEmittedAtUseSite()) { |
| 2908 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2909 | } |
| 2910 | break; |
| 2911 | |
| 2912 | default: |
| 2913 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2914 | locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1))); |
| 2915 | if (!cond->IsEmittedAtUseSite()) { |
| 2916 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2917 | } |
| 2918 | } |
| 2919 | } |
| 2920 | |
| 2921 | void InstructionCodeGeneratorARMVIXL::HandleCondition(HCondition* cond) { |
| 2922 | if (cond->IsEmittedAtUseSite()) { |
| 2923 | return; |
| 2924 | } |
| 2925 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2926 | const vixl32::Register out = OutputRegister(cond); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2927 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2928 | if (out.IsLow() && CanGenerateTest(cond, codegen_->GetAssembler())) { |
| 2929 | const auto condition = GenerateTest(cond, false, codegen_); |
| 2930 | // We use the scope because of the IT block that follows. |
| 2931 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 2932 | 4 * vixl32::k16BitT32InstructionSizeInBytes, |
| 2933 | CodeBufferCheckScope::kExactSize); |
| 2934 | |
| 2935 | __ it(condition.first); |
| 2936 | __ mov(condition.first, out, 1); |
| 2937 | __ it(condition.second); |
| 2938 | __ mov(condition.second, out, 0); |
| 2939 | return; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2940 | } |
| 2941 | |
| 2942 | // Convert the jumps into the result. |
| 2943 | vixl32::Label done_label; |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2944 | vixl32::Label* const final_label = codegen_->GetFinalLabel(cond, &done_label); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2945 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2946 | if (cond->InputAt(0)->GetType() == Primitive::kPrimLong) { |
| 2947 | vixl32::Label true_label, false_label; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2948 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2949 | GenerateLongComparesAndJumps(cond, &true_label, &false_label); |
| 2950 | |
| 2951 | // False case: result = 0. |
| 2952 | __ Bind(&false_label); |
| 2953 | __ Mov(out, 0); |
| 2954 | __ B(final_label); |
| 2955 | |
| 2956 | // True case: result = 1. |
| 2957 | __ Bind(&true_label); |
| 2958 | __ Mov(out, 1); |
| 2959 | } else { |
| 2960 | DCHECK(CanGenerateTest(cond, codegen_->GetAssembler())); |
| 2961 | |
| 2962 | const auto condition = GenerateTest(cond, false, codegen_); |
| 2963 | |
| 2964 | __ Mov(LeaveFlags, out, 0); |
| 2965 | __ B(condition.second, final_label, /* far_target */ false); |
| 2966 | __ Mov(out, 1); |
| 2967 | } |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 2968 | |
| 2969 | if (done_label.IsReferenced()) { |
| 2970 | __ Bind(&done_label); |
| 2971 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2972 | } |
| 2973 | |
| 2974 | void LocationsBuilderARMVIXL::VisitEqual(HEqual* comp) { |
| 2975 | HandleCondition(comp); |
| 2976 | } |
| 2977 | |
| 2978 | void InstructionCodeGeneratorARMVIXL::VisitEqual(HEqual* comp) { |
| 2979 | HandleCondition(comp); |
| 2980 | } |
| 2981 | |
| 2982 | void LocationsBuilderARMVIXL::VisitNotEqual(HNotEqual* comp) { |
| 2983 | HandleCondition(comp); |
| 2984 | } |
| 2985 | |
| 2986 | void InstructionCodeGeneratorARMVIXL::VisitNotEqual(HNotEqual* comp) { |
| 2987 | HandleCondition(comp); |
| 2988 | } |
| 2989 | |
| 2990 | void LocationsBuilderARMVIXL::VisitLessThan(HLessThan* comp) { |
| 2991 | HandleCondition(comp); |
| 2992 | } |
| 2993 | |
| 2994 | void InstructionCodeGeneratorARMVIXL::VisitLessThan(HLessThan* comp) { |
| 2995 | HandleCondition(comp); |
| 2996 | } |
| 2997 | |
| 2998 | void LocationsBuilderARMVIXL::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| 2999 | HandleCondition(comp); |
| 3000 | } |
| 3001 | |
| 3002 | void InstructionCodeGeneratorARMVIXL::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| 3003 | HandleCondition(comp); |
| 3004 | } |
| 3005 | |
| 3006 | void LocationsBuilderARMVIXL::VisitGreaterThan(HGreaterThan* comp) { |
| 3007 | HandleCondition(comp); |
| 3008 | } |
| 3009 | |
| 3010 | void InstructionCodeGeneratorARMVIXL::VisitGreaterThan(HGreaterThan* comp) { |
| 3011 | HandleCondition(comp); |
| 3012 | } |
| 3013 | |
| 3014 | void LocationsBuilderARMVIXL::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| 3015 | HandleCondition(comp); |
| 3016 | } |
| 3017 | |
| 3018 | void InstructionCodeGeneratorARMVIXL::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| 3019 | HandleCondition(comp); |
| 3020 | } |
| 3021 | |
| 3022 | void LocationsBuilderARMVIXL::VisitBelow(HBelow* comp) { |
| 3023 | HandleCondition(comp); |
| 3024 | } |
| 3025 | |
| 3026 | void InstructionCodeGeneratorARMVIXL::VisitBelow(HBelow* comp) { |
| 3027 | HandleCondition(comp); |
| 3028 | } |
| 3029 | |
| 3030 | void LocationsBuilderARMVIXL::VisitBelowOrEqual(HBelowOrEqual* comp) { |
| 3031 | HandleCondition(comp); |
| 3032 | } |
| 3033 | |
| 3034 | void InstructionCodeGeneratorARMVIXL::VisitBelowOrEqual(HBelowOrEqual* comp) { |
| 3035 | HandleCondition(comp); |
| 3036 | } |
| 3037 | |
| 3038 | void LocationsBuilderARMVIXL::VisitAbove(HAbove* comp) { |
| 3039 | HandleCondition(comp); |
| 3040 | } |
| 3041 | |
| 3042 | void InstructionCodeGeneratorARMVIXL::VisitAbove(HAbove* comp) { |
| 3043 | HandleCondition(comp); |
| 3044 | } |
| 3045 | |
| 3046 | void LocationsBuilderARMVIXL::VisitAboveOrEqual(HAboveOrEqual* comp) { |
| 3047 | HandleCondition(comp); |
| 3048 | } |
| 3049 | |
| 3050 | void InstructionCodeGeneratorARMVIXL::VisitAboveOrEqual(HAboveOrEqual* comp) { |
| 3051 | HandleCondition(comp); |
| 3052 | } |
| 3053 | |
| 3054 | void LocationsBuilderARMVIXL::VisitIntConstant(HIntConstant* constant) { |
| 3055 | LocationSummary* locations = |
| 3056 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 3057 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3058 | } |
| 3059 | |
| 3060 | void InstructionCodeGeneratorARMVIXL::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
| 3061 | // Will be generated at use site. |
| 3062 | } |
| 3063 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3064 | void LocationsBuilderARMVIXL::VisitNullConstant(HNullConstant* constant) { |
| 3065 | LocationSummary* locations = |
| 3066 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 3067 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3068 | } |
| 3069 | |
| 3070 | void InstructionCodeGeneratorARMVIXL::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
| 3071 | // Will be generated at use site. |
| 3072 | } |
| 3073 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3074 | void LocationsBuilderARMVIXL::VisitLongConstant(HLongConstant* constant) { |
| 3075 | LocationSummary* locations = |
| 3076 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 3077 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3078 | } |
| 3079 | |
| 3080 | void InstructionCodeGeneratorARMVIXL::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
| 3081 | // Will be generated at use site. |
| 3082 | } |
| 3083 | |
Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 3084 | void LocationsBuilderARMVIXL::VisitFloatConstant(HFloatConstant* constant) { |
| 3085 | LocationSummary* locations = |
| 3086 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 3087 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3088 | } |
| 3089 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 3090 | void InstructionCodeGeneratorARMVIXL::VisitFloatConstant( |
| 3091 | HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 3092 | // Will be generated at use site. |
| 3093 | } |
| 3094 | |
| 3095 | void LocationsBuilderARMVIXL::VisitDoubleConstant(HDoubleConstant* constant) { |
| 3096 | LocationSummary* locations = |
| 3097 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 3098 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3099 | } |
| 3100 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 3101 | void InstructionCodeGeneratorARMVIXL::VisitDoubleConstant( |
| 3102 | HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 3103 | // Will be generated at use site. |
| 3104 | } |
| 3105 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3106 | void LocationsBuilderARMVIXL::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 3107 | memory_barrier->SetLocations(nullptr); |
| 3108 | } |
| 3109 | |
| 3110 | void InstructionCodeGeneratorARMVIXL::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 3111 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
| 3112 | } |
| 3113 | |
| 3114 | void LocationsBuilderARMVIXL::VisitReturnVoid(HReturnVoid* ret) { |
| 3115 | ret->SetLocations(nullptr); |
| 3116 | } |
| 3117 | |
| 3118 | void InstructionCodeGeneratorARMVIXL::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
| 3119 | codegen_->GenerateFrameExit(); |
| 3120 | } |
| 3121 | |
| 3122 | void LocationsBuilderARMVIXL::VisitReturn(HReturn* ret) { |
| 3123 | LocationSummary* locations = |
| 3124 | new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall); |
| 3125 | locations->SetInAt(0, parameter_visitor_.GetReturnLocation(ret->InputAt(0)->GetType())); |
| 3126 | } |
| 3127 | |
| 3128 | void InstructionCodeGeneratorARMVIXL::VisitReturn(HReturn* ret ATTRIBUTE_UNUSED) { |
| 3129 | codegen_->GenerateFrameExit(); |
| 3130 | } |
| 3131 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3132 | void LocationsBuilderARMVIXL::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 3133 | // The trampoline uses the same calling convention as dex calling conventions, |
| 3134 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 3135 | // the method_idx. |
| 3136 | HandleInvoke(invoke); |
| 3137 | } |
| 3138 | |
| 3139 | void InstructionCodeGeneratorARMVIXL::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 3140 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 3141 | } |
| 3142 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3143 | void LocationsBuilderARMVIXL::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
| 3144 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 3145 | // art::PrepareForRegisterAllocation. |
| 3146 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
| 3147 | |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 3148 | IntrinsicLocationsBuilderARMVIXL intrinsic(codegen_); |
| 3149 | if (intrinsic.TryDispatch(invoke)) { |
| 3150 | if (invoke->GetLocations()->CanCall() && invoke->HasPcRelativeDexCache()) { |
| 3151 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::Any()); |
| 3152 | } |
| 3153 | return; |
| 3154 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3155 | |
| 3156 | HandleInvoke(invoke); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 3157 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 3158 | // For PC-relative dex cache the invoke has an extra input, the PC-relative address base. |
| 3159 | if (invoke->HasPcRelativeDexCache()) { |
| 3160 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::RequiresRegister()); |
| 3161 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3162 | } |
| 3163 | |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 3164 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARMVIXL* codegen) { |
| 3165 | if (invoke->GetLocations()->Intrinsified()) { |
| 3166 | IntrinsicCodeGeneratorARMVIXL intrinsic(codegen); |
| 3167 | intrinsic.Dispatch(invoke); |
| 3168 | return true; |
| 3169 | } |
| 3170 | return false; |
| 3171 | } |
| 3172 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3173 | void InstructionCodeGeneratorARMVIXL::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
| 3174 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 3175 | // art::PrepareForRegisterAllocation. |
| 3176 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
| 3177 | |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 3178 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 3179 | return; |
| 3180 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3181 | |
| 3182 | LocationSummary* locations = invoke->GetLocations(); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 3183 | codegen_->GenerateStaticOrDirectCall( |
| 3184 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3185 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 3186 | } |
| 3187 | |
| 3188 | void LocationsBuilderARMVIXL::HandleInvoke(HInvoke* invoke) { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 3189 | InvokeDexCallingConventionVisitorARMVIXL calling_convention_visitor; |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3190 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
| 3191 | } |
| 3192 | |
| 3193 | void LocationsBuilderARMVIXL::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 3194 | IntrinsicLocationsBuilderARMVIXL intrinsic(codegen_); |
| 3195 | if (intrinsic.TryDispatch(invoke)) { |
| 3196 | return; |
| 3197 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3198 | |
| 3199 | HandleInvoke(invoke); |
| 3200 | } |
| 3201 | |
| 3202 | void InstructionCodeGeneratorARMVIXL::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 3203 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 3204 | return; |
| 3205 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3206 | |
| 3207 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3208 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 3209 | DCHECK(!codegen_->IsLeafMethod()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3210 | } |
| 3211 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3212 | void LocationsBuilderARMVIXL::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 3213 | HandleInvoke(invoke); |
| 3214 | // Add the hidden argument. |
| 3215 | invoke->GetLocations()->AddTemp(LocationFrom(r12)); |
| 3216 | } |
| 3217 | |
| 3218 | void InstructionCodeGeneratorARMVIXL::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 3219 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
| 3220 | LocationSummary* locations = invoke->GetLocations(); |
| 3221 | vixl32::Register temp = RegisterFrom(locations->GetTemp(0)); |
| 3222 | vixl32::Register hidden_reg = RegisterFrom(locations->GetTemp(1)); |
| 3223 | Location receiver = locations->InAt(0); |
| 3224 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 3225 | |
| 3226 | DCHECK(!receiver.IsStackSlot()); |
| 3227 | |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 3228 | // Ensure the pc position is recorded immediately after the `ldr` instruction. |
| 3229 | { |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 3230 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 3231 | vixl32::kMaxInstructionSizeInBytes, |
| 3232 | CodeBufferCheckScope::kMaximumSize); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 3233 | // /* HeapReference<Class> */ temp = receiver->klass_ |
| 3234 | __ ldr(temp, MemOperand(RegisterFrom(receiver), class_offset)); |
| 3235 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
| 3236 | } |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3237 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 3238 | // emit a read barrier for the previous class reference load. |
| 3239 | // However this is not required in practice, as this is an |
| 3240 | // intermediate/temporary reference and because the current |
| 3241 | // concurrent copying collector keeps the from-space memory |
| 3242 | // intact/accessible until the end of the marking phase (the |
| 3243 | // concurrent copying collector may not in the future). |
| 3244 | GetAssembler()->MaybeUnpoisonHeapReference(temp); |
| 3245 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 3246 | temp, |
| 3247 | temp, |
| 3248 | mirror::Class::ImtPtrOffset(kArmPointerSize).Uint32Value()); |
| 3249 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
| 3250 | invoke->GetImtIndex(), kArmPointerSize)); |
| 3251 | // temp = temp->GetImtEntryAt(method_offset); |
| 3252 | GetAssembler()->LoadFromOffset(kLoadWord, temp, temp, method_offset); |
| 3253 | uint32_t entry_point = |
| 3254 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize).Int32Value(); |
| 3255 | // LR = temp->GetEntryPoint(); |
| 3256 | GetAssembler()->LoadFromOffset(kLoadWord, lr, temp, entry_point); |
| 3257 | |
| 3258 | // Set the hidden (in r12) argument. It is done here, right before a BLX to prevent other |
| 3259 | // instruction from clobbering it as they might use r12 as a scratch register. |
| 3260 | DCHECK(hidden_reg.Is(r12)); |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 3261 | |
| 3262 | { |
| 3263 | // The VIXL macro assembler may clobber any of the scratch registers that are available to it, |
| 3264 | // so it checks if the application is using them (by passing them to the macro assembler |
| 3265 | // methods). The following application of UseScratchRegisterScope corrects VIXL's notion of |
| 3266 | // what is available, and is the opposite of the standard usage: Instead of requesting a |
| 3267 | // temporary location, it imposes an external constraint (i.e. a specific register is reserved |
| 3268 | // for the hidden argument). Note that this works even if VIXL needs a scratch register itself |
| 3269 | // (to materialize the constant), since the destination register becomes available for such use |
| 3270 | // internally for the duration of the macro instruction. |
| 3271 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 3272 | temps.Exclude(hidden_reg); |
| 3273 | __ Mov(hidden_reg, invoke->GetDexMethodIndex()); |
| 3274 | } |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3275 | { |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 3276 | // Ensure the pc position is recorded immediately after the `blx` instruction. |
| 3277 | // 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] | 3278 | ExactAssemblyScope aas(GetVIXLAssembler(), |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 3279 | vixl32::k16BitT32InstructionSizeInBytes, |
| 3280 | CodeBufferCheckScope::kExactSize); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3281 | // LR(); |
| 3282 | __ blx(lr); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3283 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 3284 | DCHECK(!codegen_->IsLeafMethod()); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3285 | } |
| 3286 | } |
| 3287 | |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 3288 | void LocationsBuilderARMVIXL::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 3289 | HandleInvoke(invoke); |
| 3290 | } |
| 3291 | |
| 3292 | void InstructionCodeGeneratorARMVIXL::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 3293 | codegen_->GenerateInvokePolymorphicCall(invoke); |
| 3294 | } |
| 3295 | |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 3296 | void LocationsBuilderARMVIXL::VisitNeg(HNeg* neg) { |
| 3297 | LocationSummary* locations = |
| 3298 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 3299 | switch (neg->GetResultType()) { |
| 3300 | case Primitive::kPrimInt: { |
| 3301 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3302 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3303 | break; |
| 3304 | } |
| 3305 | case Primitive::kPrimLong: { |
| 3306 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3307 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 3308 | break; |
| 3309 | } |
| 3310 | |
| 3311 | case Primitive::kPrimFloat: |
| 3312 | case Primitive::kPrimDouble: |
| 3313 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3314 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3315 | break; |
| 3316 | |
| 3317 | default: |
| 3318 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 3319 | } |
| 3320 | } |
| 3321 | |
| 3322 | void InstructionCodeGeneratorARMVIXL::VisitNeg(HNeg* neg) { |
| 3323 | LocationSummary* locations = neg->GetLocations(); |
| 3324 | Location out = locations->Out(); |
| 3325 | Location in = locations->InAt(0); |
| 3326 | switch (neg->GetResultType()) { |
| 3327 | case Primitive::kPrimInt: |
| 3328 | __ Rsb(OutputRegister(neg), InputRegisterAt(neg, 0), 0); |
| 3329 | break; |
| 3330 | |
| 3331 | case Primitive::kPrimLong: |
| 3332 | // out.lo = 0 - in.lo (and update the carry/borrow (C) flag) |
| 3333 | __ Rsbs(LowRegisterFrom(out), LowRegisterFrom(in), 0); |
| 3334 | // We cannot emit an RSC (Reverse Subtract with Carry) |
| 3335 | // instruction here, as it does not exist in the Thumb-2 |
| 3336 | // instruction set. We use the following approach |
| 3337 | // using SBC and SUB instead. |
| 3338 | // |
| 3339 | // out.hi = -C |
| 3340 | __ Sbc(HighRegisterFrom(out), HighRegisterFrom(out), HighRegisterFrom(out)); |
| 3341 | // out.hi = out.hi - in.hi |
| 3342 | __ Sub(HighRegisterFrom(out), HighRegisterFrom(out), HighRegisterFrom(in)); |
| 3343 | break; |
| 3344 | |
| 3345 | case Primitive::kPrimFloat: |
| 3346 | case Primitive::kPrimDouble: |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 3347 | __ Vneg(OutputVRegister(neg), InputVRegister(neg)); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 3348 | break; |
| 3349 | |
| 3350 | default: |
| 3351 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 3352 | } |
| 3353 | } |
| 3354 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3355 | void LocationsBuilderARMVIXL::VisitTypeConversion(HTypeConversion* conversion) { |
| 3356 | Primitive::Type result_type = conversion->GetResultType(); |
| 3357 | Primitive::Type input_type = conversion->GetInputType(); |
| 3358 | DCHECK_NE(result_type, input_type); |
| 3359 | |
| 3360 | // The float-to-long, double-to-long and long-to-float type conversions |
| 3361 | // rely on a call to the runtime. |
| 3362 | LocationSummary::CallKind call_kind = |
| 3363 | (((input_type == Primitive::kPrimFloat || input_type == Primitive::kPrimDouble) |
| 3364 | && result_type == Primitive::kPrimLong) |
| 3365 | || (input_type == Primitive::kPrimLong && result_type == Primitive::kPrimFloat)) |
| 3366 | ? LocationSummary::kCallOnMainOnly |
| 3367 | : LocationSummary::kNoCall; |
| 3368 | LocationSummary* locations = |
| 3369 | new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind); |
| 3370 | |
| 3371 | // The Java language does not allow treating boolean as an integral type but |
| 3372 | // our bit representation makes it safe. |
| 3373 | |
| 3374 | switch (result_type) { |
| 3375 | case Primitive::kPrimByte: |
| 3376 | switch (input_type) { |
| 3377 | case Primitive::kPrimLong: |
| 3378 | // Type conversion from long to byte is a result of code transformations. |
| 3379 | case Primitive::kPrimBoolean: |
| 3380 | // Boolean input is a result of code transformations. |
| 3381 | case Primitive::kPrimShort: |
| 3382 | case Primitive::kPrimInt: |
| 3383 | case Primitive::kPrimChar: |
| 3384 | // Processing a Dex `int-to-byte' instruction. |
| 3385 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3386 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3387 | break; |
| 3388 | |
| 3389 | default: |
| 3390 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3391 | << " to " << result_type; |
| 3392 | } |
| 3393 | break; |
| 3394 | |
| 3395 | case Primitive::kPrimShort: |
| 3396 | switch (input_type) { |
| 3397 | case Primitive::kPrimLong: |
| 3398 | // Type conversion from long to short is a result of code transformations. |
| 3399 | case Primitive::kPrimBoolean: |
| 3400 | // Boolean input is a result of code transformations. |
| 3401 | case Primitive::kPrimByte: |
| 3402 | case Primitive::kPrimInt: |
| 3403 | case Primitive::kPrimChar: |
| 3404 | // Processing a Dex `int-to-short' instruction. |
| 3405 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3406 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3407 | break; |
| 3408 | |
| 3409 | default: |
| 3410 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3411 | << " to " << result_type; |
| 3412 | } |
| 3413 | break; |
| 3414 | |
| 3415 | case Primitive::kPrimInt: |
| 3416 | switch (input_type) { |
| 3417 | case Primitive::kPrimLong: |
| 3418 | // Processing a Dex `long-to-int' instruction. |
| 3419 | locations->SetInAt(0, Location::Any()); |
| 3420 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3421 | break; |
| 3422 | |
| 3423 | case Primitive::kPrimFloat: |
| 3424 | // Processing a Dex `float-to-int' instruction. |
| 3425 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3426 | locations->SetOut(Location::RequiresRegister()); |
| 3427 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 3428 | break; |
| 3429 | |
| 3430 | case Primitive::kPrimDouble: |
| 3431 | // Processing a Dex `double-to-int' instruction. |
| 3432 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3433 | locations->SetOut(Location::RequiresRegister()); |
| 3434 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 3435 | break; |
| 3436 | |
| 3437 | default: |
| 3438 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3439 | << " to " << result_type; |
| 3440 | } |
| 3441 | break; |
| 3442 | |
| 3443 | case Primitive::kPrimLong: |
| 3444 | switch (input_type) { |
| 3445 | case Primitive::kPrimBoolean: |
| 3446 | // Boolean input is a result of code transformations. |
| 3447 | case Primitive::kPrimByte: |
| 3448 | case Primitive::kPrimShort: |
| 3449 | case Primitive::kPrimInt: |
| 3450 | case Primitive::kPrimChar: |
| 3451 | // Processing a Dex `int-to-long' instruction. |
| 3452 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3453 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3454 | break; |
| 3455 | |
| 3456 | case Primitive::kPrimFloat: { |
| 3457 | // Processing a Dex `float-to-long' instruction. |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3458 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 3459 | locations->SetInAt(0, LocationFrom(calling_convention.GetFpuRegisterAt(0))); |
| 3460 | locations->SetOut(LocationFrom(r0, r1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3461 | break; |
| 3462 | } |
| 3463 | |
| 3464 | case Primitive::kPrimDouble: { |
| 3465 | // Processing a Dex `double-to-long' instruction. |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3466 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 3467 | locations->SetInAt(0, LocationFrom(calling_convention.GetFpuRegisterAt(0), |
| 3468 | calling_convention.GetFpuRegisterAt(1))); |
| 3469 | locations->SetOut(LocationFrom(r0, r1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3470 | break; |
| 3471 | } |
| 3472 | |
| 3473 | default: |
| 3474 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3475 | << " to " << result_type; |
| 3476 | } |
| 3477 | break; |
| 3478 | |
| 3479 | case Primitive::kPrimChar: |
| 3480 | switch (input_type) { |
| 3481 | case Primitive::kPrimLong: |
| 3482 | // Type conversion from long to char is a result of code transformations. |
| 3483 | case Primitive::kPrimBoolean: |
| 3484 | // Boolean input is a result of code transformations. |
| 3485 | case Primitive::kPrimByte: |
| 3486 | case Primitive::kPrimShort: |
| 3487 | case Primitive::kPrimInt: |
| 3488 | // Processing a Dex `int-to-char' instruction. |
| 3489 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3490 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3491 | break; |
| 3492 | |
| 3493 | default: |
| 3494 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3495 | << " to " << result_type; |
| 3496 | } |
| 3497 | break; |
| 3498 | |
| 3499 | case Primitive::kPrimFloat: |
| 3500 | switch (input_type) { |
| 3501 | case Primitive::kPrimBoolean: |
| 3502 | // Boolean input is a result of code transformations. |
| 3503 | case Primitive::kPrimByte: |
| 3504 | case Primitive::kPrimShort: |
| 3505 | case Primitive::kPrimInt: |
| 3506 | case Primitive::kPrimChar: |
| 3507 | // Processing a Dex `int-to-float' instruction. |
| 3508 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3509 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3510 | break; |
| 3511 | |
| 3512 | case Primitive::kPrimLong: { |
| 3513 | // Processing a Dex `long-to-float' instruction. |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3514 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 3515 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0), |
| 3516 | calling_convention.GetRegisterAt(1))); |
| 3517 | locations->SetOut(LocationFrom(calling_convention.GetFpuRegisterAt(0))); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3518 | break; |
| 3519 | } |
| 3520 | |
| 3521 | case Primitive::kPrimDouble: |
| 3522 | // Processing a Dex `double-to-float' instruction. |
| 3523 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3524 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3525 | break; |
| 3526 | |
| 3527 | default: |
| 3528 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3529 | << " to " << result_type; |
| 3530 | }; |
| 3531 | break; |
| 3532 | |
| 3533 | case Primitive::kPrimDouble: |
| 3534 | switch (input_type) { |
| 3535 | case Primitive::kPrimBoolean: |
| 3536 | // Boolean input is a result of code transformations. |
| 3537 | case Primitive::kPrimByte: |
| 3538 | case Primitive::kPrimShort: |
| 3539 | case Primitive::kPrimInt: |
| 3540 | case Primitive::kPrimChar: |
| 3541 | // Processing a Dex `int-to-double' instruction. |
| 3542 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3543 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3544 | break; |
| 3545 | |
| 3546 | case Primitive::kPrimLong: |
| 3547 | // Processing a Dex `long-to-double' instruction. |
| 3548 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3549 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3550 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 3551 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 3552 | break; |
| 3553 | |
| 3554 | case Primitive::kPrimFloat: |
| 3555 | // Processing a Dex `float-to-double' instruction. |
| 3556 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3557 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3558 | break; |
| 3559 | |
| 3560 | default: |
| 3561 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3562 | << " to " << result_type; |
| 3563 | }; |
| 3564 | break; |
| 3565 | |
| 3566 | default: |
| 3567 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3568 | << " to " << result_type; |
| 3569 | } |
| 3570 | } |
| 3571 | |
| 3572 | void InstructionCodeGeneratorARMVIXL::VisitTypeConversion(HTypeConversion* conversion) { |
| 3573 | LocationSummary* locations = conversion->GetLocations(); |
| 3574 | Location out = locations->Out(); |
| 3575 | Location in = locations->InAt(0); |
| 3576 | Primitive::Type result_type = conversion->GetResultType(); |
| 3577 | Primitive::Type input_type = conversion->GetInputType(); |
| 3578 | DCHECK_NE(result_type, input_type); |
| 3579 | switch (result_type) { |
| 3580 | case Primitive::kPrimByte: |
| 3581 | switch (input_type) { |
| 3582 | case Primitive::kPrimLong: |
| 3583 | // Type conversion from long to byte is a result of code transformations. |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3584 | __ Sbfx(OutputRegister(conversion), LowRegisterFrom(in), 0, 8); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3585 | break; |
| 3586 | case Primitive::kPrimBoolean: |
| 3587 | // Boolean input is a result of code transformations. |
| 3588 | case Primitive::kPrimShort: |
| 3589 | case Primitive::kPrimInt: |
| 3590 | case Primitive::kPrimChar: |
| 3591 | // Processing a Dex `int-to-byte' instruction. |
| 3592 | __ Sbfx(OutputRegister(conversion), InputRegisterAt(conversion, 0), 0, 8); |
| 3593 | break; |
| 3594 | |
| 3595 | default: |
| 3596 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3597 | << " to " << result_type; |
| 3598 | } |
| 3599 | break; |
| 3600 | |
| 3601 | case Primitive::kPrimShort: |
| 3602 | switch (input_type) { |
| 3603 | case Primitive::kPrimLong: |
| 3604 | // Type conversion from long to short is a result of code transformations. |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3605 | __ Sbfx(OutputRegister(conversion), LowRegisterFrom(in), 0, 16); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3606 | break; |
| 3607 | case Primitive::kPrimBoolean: |
| 3608 | // Boolean input is a result of code transformations. |
| 3609 | case Primitive::kPrimByte: |
| 3610 | case Primitive::kPrimInt: |
| 3611 | case Primitive::kPrimChar: |
| 3612 | // Processing a Dex `int-to-short' instruction. |
| 3613 | __ Sbfx(OutputRegister(conversion), InputRegisterAt(conversion, 0), 0, 16); |
| 3614 | break; |
| 3615 | |
| 3616 | default: |
| 3617 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3618 | << " to " << result_type; |
| 3619 | } |
| 3620 | break; |
| 3621 | |
| 3622 | case Primitive::kPrimInt: |
| 3623 | switch (input_type) { |
| 3624 | case Primitive::kPrimLong: |
| 3625 | // Processing a Dex `long-to-int' instruction. |
| 3626 | DCHECK(out.IsRegister()); |
| 3627 | if (in.IsRegisterPair()) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3628 | __ Mov(OutputRegister(conversion), LowRegisterFrom(in)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3629 | } else if (in.IsDoubleStackSlot()) { |
| 3630 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 3631 | OutputRegister(conversion), |
| 3632 | sp, |
| 3633 | in.GetStackIndex()); |
| 3634 | } else { |
| 3635 | DCHECK(in.IsConstant()); |
| 3636 | DCHECK(in.GetConstant()->IsLongConstant()); |
Vladimir Marko | ba1a48e | 2017-04-13 11:50:14 +0100 | [diff] [blame] | 3637 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 3638 | __ Mov(OutputRegister(conversion), static_cast<int32_t>(value)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3639 | } |
| 3640 | break; |
| 3641 | |
| 3642 | case Primitive::kPrimFloat: { |
| 3643 | // Processing a Dex `float-to-int' instruction. |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3644 | vixl32::SRegister temp = LowSRegisterFrom(locations->GetTemp(0)); |
Scott Wakeling | fb0b7d4 | 2016-10-28 16:11:08 +0100 | [diff] [blame] | 3645 | __ Vcvt(S32, F32, temp, InputSRegisterAt(conversion, 0)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3646 | __ Vmov(OutputRegister(conversion), temp); |
| 3647 | break; |
| 3648 | } |
| 3649 | |
| 3650 | case Primitive::kPrimDouble: { |
| 3651 | // Processing a Dex `double-to-int' instruction. |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3652 | vixl32::SRegister temp_s = LowSRegisterFrom(locations->GetTemp(0)); |
Scott Wakeling | fb0b7d4 | 2016-10-28 16:11:08 +0100 | [diff] [blame] | 3653 | __ Vcvt(S32, F64, temp_s, DRegisterFrom(in)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3654 | __ Vmov(OutputRegister(conversion), temp_s); |
| 3655 | break; |
| 3656 | } |
| 3657 | |
| 3658 | default: |
| 3659 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3660 | << " to " << result_type; |
| 3661 | } |
| 3662 | break; |
| 3663 | |
| 3664 | case Primitive::kPrimLong: |
| 3665 | switch (input_type) { |
| 3666 | case Primitive::kPrimBoolean: |
| 3667 | // Boolean input is a result of code transformations. |
| 3668 | case Primitive::kPrimByte: |
| 3669 | case Primitive::kPrimShort: |
| 3670 | case Primitive::kPrimInt: |
| 3671 | case Primitive::kPrimChar: |
| 3672 | // Processing a Dex `int-to-long' instruction. |
| 3673 | DCHECK(out.IsRegisterPair()); |
| 3674 | DCHECK(in.IsRegister()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3675 | __ Mov(LowRegisterFrom(out), InputRegisterAt(conversion, 0)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3676 | // Sign extension. |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3677 | __ Asr(HighRegisterFrom(out), LowRegisterFrom(out), 31); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3678 | break; |
| 3679 | |
| 3680 | case Primitive::kPrimFloat: |
| 3681 | // Processing a Dex `float-to-long' instruction. |
| 3682 | codegen_->InvokeRuntime(kQuickF2l, conversion, conversion->GetDexPc()); |
| 3683 | CheckEntrypointTypes<kQuickF2l, int64_t, float>(); |
| 3684 | break; |
| 3685 | |
| 3686 | case Primitive::kPrimDouble: |
| 3687 | // Processing a Dex `double-to-long' instruction. |
| 3688 | codegen_->InvokeRuntime(kQuickD2l, conversion, conversion->GetDexPc()); |
| 3689 | CheckEntrypointTypes<kQuickD2l, int64_t, double>(); |
| 3690 | break; |
| 3691 | |
| 3692 | default: |
| 3693 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3694 | << " to " << result_type; |
| 3695 | } |
| 3696 | break; |
| 3697 | |
| 3698 | case Primitive::kPrimChar: |
| 3699 | switch (input_type) { |
| 3700 | case Primitive::kPrimLong: |
| 3701 | // Type conversion from long to char is a result of code transformations. |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3702 | __ Ubfx(OutputRegister(conversion), LowRegisterFrom(in), 0, 16); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3703 | break; |
| 3704 | case Primitive::kPrimBoolean: |
| 3705 | // Boolean input is a result of code transformations. |
| 3706 | case Primitive::kPrimByte: |
| 3707 | case Primitive::kPrimShort: |
| 3708 | case Primitive::kPrimInt: |
| 3709 | // Processing a Dex `int-to-char' instruction. |
| 3710 | __ Ubfx(OutputRegister(conversion), InputRegisterAt(conversion, 0), 0, 16); |
| 3711 | break; |
| 3712 | |
| 3713 | default: |
| 3714 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3715 | << " to " << result_type; |
| 3716 | } |
| 3717 | break; |
| 3718 | |
| 3719 | case Primitive::kPrimFloat: |
| 3720 | switch (input_type) { |
| 3721 | case Primitive::kPrimBoolean: |
| 3722 | // Boolean input is a result of code transformations. |
| 3723 | case Primitive::kPrimByte: |
| 3724 | case Primitive::kPrimShort: |
| 3725 | case Primitive::kPrimInt: |
| 3726 | case Primitive::kPrimChar: { |
| 3727 | // Processing a Dex `int-to-float' instruction. |
| 3728 | __ Vmov(OutputSRegister(conversion), InputRegisterAt(conversion, 0)); |
Scott Wakeling | fb0b7d4 | 2016-10-28 16:11:08 +0100 | [diff] [blame] | 3729 | __ Vcvt(F32, S32, OutputSRegister(conversion), OutputSRegister(conversion)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3730 | break; |
| 3731 | } |
| 3732 | |
| 3733 | case Primitive::kPrimLong: |
| 3734 | // Processing a Dex `long-to-float' instruction. |
| 3735 | codegen_->InvokeRuntime(kQuickL2f, conversion, conversion->GetDexPc()); |
| 3736 | CheckEntrypointTypes<kQuickL2f, float, int64_t>(); |
| 3737 | break; |
| 3738 | |
| 3739 | case Primitive::kPrimDouble: |
| 3740 | // Processing a Dex `double-to-float' instruction. |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 3741 | __ Vcvt(F32, F64, OutputSRegister(conversion), DRegisterFrom(in)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3742 | break; |
| 3743 | |
| 3744 | default: |
| 3745 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3746 | << " to " << result_type; |
| 3747 | }; |
| 3748 | break; |
| 3749 | |
| 3750 | case Primitive::kPrimDouble: |
| 3751 | switch (input_type) { |
| 3752 | case Primitive::kPrimBoolean: |
| 3753 | // Boolean input is a result of code transformations. |
| 3754 | case Primitive::kPrimByte: |
| 3755 | case Primitive::kPrimShort: |
| 3756 | case Primitive::kPrimInt: |
| 3757 | case Primitive::kPrimChar: { |
| 3758 | // Processing a Dex `int-to-double' instruction. |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3759 | __ Vmov(LowSRegisterFrom(out), InputRegisterAt(conversion, 0)); |
Scott Wakeling | fb0b7d4 | 2016-10-28 16:11:08 +0100 | [diff] [blame] | 3760 | __ Vcvt(F64, S32, DRegisterFrom(out), LowSRegisterFrom(out)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3761 | break; |
| 3762 | } |
| 3763 | |
| 3764 | case Primitive::kPrimLong: { |
| 3765 | // Processing a Dex `long-to-double' instruction. |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3766 | vixl32::Register low = LowRegisterFrom(in); |
| 3767 | vixl32::Register high = HighRegisterFrom(in); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3768 | vixl32::SRegister out_s = LowSRegisterFrom(out); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 3769 | vixl32::DRegister out_d = DRegisterFrom(out); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3770 | vixl32::SRegister temp_s = LowSRegisterFrom(locations->GetTemp(0)); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 3771 | vixl32::DRegister temp_d = DRegisterFrom(locations->GetTemp(0)); |
Scott Wakeling | fb0b7d4 | 2016-10-28 16:11:08 +0100 | [diff] [blame] | 3772 | vixl32::DRegister constant_d = DRegisterFrom(locations->GetTemp(1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3773 | |
| 3774 | // temp_d = int-to-double(high) |
| 3775 | __ Vmov(temp_s, high); |
Scott Wakeling | fb0b7d4 | 2016-10-28 16:11:08 +0100 | [diff] [blame] | 3776 | __ Vcvt(F64, S32, temp_d, temp_s); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3777 | // constant_d = k2Pow32EncodingForDouble |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3778 | __ Vmov(constant_d, bit_cast<double, int64_t>(k2Pow32EncodingForDouble)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3779 | // out_d = unsigned-to-double(low) |
| 3780 | __ Vmov(out_s, low); |
| 3781 | __ Vcvt(F64, U32, out_d, out_s); |
| 3782 | // out_d += temp_d * constant_d |
| 3783 | __ Vmla(F64, out_d, temp_d, constant_d); |
| 3784 | break; |
| 3785 | } |
| 3786 | |
| 3787 | case Primitive::kPrimFloat: |
| 3788 | // Processing a Dex `float-to-double' instruction. |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 3789 | __ Vcvt(F64, F32, DRegisterFrom(out), InputSRegisterAt(conversion, 0)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3790 | break; |
| 3791 | |
| 3792 | default: |
| 3793 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3794 | << " to " << result_type; |
| 3795 | }; |
| 3796 | break; |
| 3797 | |
| 3798 | default: |
| 3799 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3800 | << " to " << result_type; |
| 3801 | } |
| 3802 | } |
| 3803 | |
| 3804 | void LocationsBuilderARMVIXL::VisitAdd(HAdd* add) { |
| 3805 | LocationSummary* locations = |
| 3806 | new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall); |
| 3807 | switch (add->GetResultType()) { |
| 3808 | case Primitive::kPrimInt: { |
| 3809 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3810 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
| 3811 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3812 | break; |
| 3813 | } |
| 3814 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3815 | case Primitive::kPrimLong: { |
| 3816 | locations->SetInAt(0, Location::RequiresRegister()); |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 3817 | locations->SetInAt(1, ArmEncodableConstantOrRegister(add->InputAt(1), ADD)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3818 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3819 | break; |
| 3820 | } |
| 3821 | |
| 3822 | case Primitive::kPrimFloat: |
| 3823 | case Primitive::kPrimDouble: { |
| 3824 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3825 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3826 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3827 | break; |
| 3828 | } |
| 3829 | |
| 3830 | default: |
| 3831 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
| 3832 | } |
| 3833 | } |
| 3834 | |
| 3835 | void InstructionCodeGeneratorARMVIXL::VisitAdd(HAdd* add) { |
| 3836 | LocationSummary* locations = add->GetLocations(); |
| 3837 | Location out = locations->Out(); |
| 3838 | Location first = locations->InAt(0); |
| 3839 | Location second = locations->InAt(1); |
| 3840 | |
| 3841 | switch (add->GetResultType()) { |
| 3842 | case Primitive::kPrimInt: { |
| 3843 | __ Add(OutputRegister(add), InputRegisterAt(add, 0), InputOperandAt(add, 1)); |
| 3844 | } |
| 3845 | break; |
| 3846 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3847 | case Primitive::kPrimLong: { |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 3848 | if (second.IsConstant()) { |
| 3849 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant())); |
| 3850 | GenerateAddLongConst(out, first, value); |
| 3851 | } else { |
| 3852 | DCHECK(second.IsRegisterPair()); |
| 3853 | __ Adds(LowRegisterFrom(out), LowRegisterFrom(first), LowRegisterFrom(second)); |
| 3854 | __ Adc(HighRegisterFrom(out), HighRegisterFrom(first), HighRegisterFrom(second)); |
| 3855 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3856 | break; |
| 3857 | } |
| 3858 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3859 | case Primitive::kPrimFloat: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3860 | case Primitive::kPrimDouble: |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3861 | __ Vadd(OutputVRegister(add), InputVRegisterAt(add, 0), InputVRegisterAt(add, 1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3862 | break; |
| 3863 | |
| 3864 | default: |
| 3865 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
| 3866 | } |
| 3867 | } |
| 3868 | |
| 3869 | void LocationsBuilderARMVIXL::VisitSub(HSub* sub) { |
| 3870 | LocationSummary* locations = |
| 3871 | new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); |
| 3872 | switch (sub->GetResultType()) { |
| 3873 | case Primitive::kPrimInt: { |
| 3874 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3875 | locations->SetInAt(1, Location::RegisterOrConstant(sub->InputAt(1))); |
| 3876 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3877 | break; |
| 3878 | } |
| 3879 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3880 | case Primitive::kPrimLong: { |
| 3881 | locations->SetInAt(0, Location::RequiresRegister()); |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 3882 | locations->SetInAt(1, ArmEncodableConstantOrRegister(sub->InputAt(1), SUB)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3883 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3884 | break; |
| 3885 | } |
| 3886 | case Primitive::kPrimFloat: |
| 3887 | case Primitive::kPrimDouble: { |
| 3888 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3889 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3890 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3891 | break; |
| 3892 | } |
| 3893 | default: |
| 3894 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
| 3895 | } |
| 3896 | } |
| 3897 | |
| 3898 | void InstructionCodeGeneratorARMVIXL::VisitSub(HSub* sub) { |
| 3899 | LocationSummary* locations = sub->GetLocations(); |
| 3900 | Location out = locations->Out(); |
| 3901 | Location first = locations->InAt(0); |
| 3902 | Location second = locations->InAt(1); |
| 3903 | switch (sub->GetResultType()) { |
| 3904 | case Primitive::kPrimInt: { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3905 | __ Sub(OutputRegister(sub), InputRegisterAt(sub, 0), InputOperandAt(sub, 1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3906 | break; |
| 3907 | } |
| 3908 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3909 | case Primitive::kPrimLong: { |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 3910 | if (second.IsConstant()) { |
| 3911 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant())); |
| 3912 | GenerateAddLongConst(out, first, -value); |
| 3913 | } else { |
| 3914 | DCHECK(second.IsRegisterPair()); |
| 3915 | __ Subs(LowRegisterFrom(out), LowRegisterFrom(first), LowRegisterFrom(second)); |
| 3916 | __ Sbc(HighRegisterFrom(out), HighRegisterFrom(first), HighRegisterFrom(second)); |
| 3917 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3918 | break; |
| 3919 | } |
| 3920 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3921 | case Primitive::kPrimFloat: |
| 3922 | case Primitive::kPrimDouble: |
| 3923 | __ Vsub(OutputVRegister(sub), InputVRegisterAt(sub, 0), InputVRegisterAt(sub, 1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3924 | break; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3925 | |
| 3926 | default: |
| 3927 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
| 3928 | } |
| 3929 | } |
| 3930 | |
| 3931 | void LocationsBuilderARMVIXL::VisitMul(HMul* mul) { |
| 3932 | LocationSummary* locations = |
| 3933 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 3934 | switch (mul->GetResultType()) { |
| 3935 | case Primitive::kPrimInt: |
| 3936 | case Primitive::kPrimLong: { |
| 3937 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3938 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3939 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3940 | break; |
| 3941 | } |
| 3942 | |
| 3943 | case Primitive::kPrimFloat: |
| 3944 | case Primitive::kPrimDouble: { |
| 3945 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3946 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3947 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3948 | break; |
| 3949 | } |
| 3950 | |
| 3951 | default: |
| 3952 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 3953 | } |
| 3954 | } |
| 3955 | |
| 3956 | void InstructionCodeGeneratorARMVIXL::VisitMul(HMul* mul) { |
| 3957 | LocationSummary* locations = mul->GetLocations(); |
| 3958 | Location out = locations->Out(); |
| 3959 | Location first = locations->InAt(0); |
| 3960 | Location second = locations->InAt(1); |
| 3961 | switch (mul->GetResultType()) { |
| 3962 | case Primitive::kPrimInt: { |
| 3963 | __ Mul(OutputRegister(mul), InputRegisterAt(mul, 0), InputRegisterAt(mul, 1)); |
| 3964 | break; |
| 3965 | } |
| 3966 | case Primitive::kPrimLong: { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3967 | vixl32::Register out_hi = HighRegisterFrom(out); |
| 3968 | vixl32::Register out_lo = LowRegisterFrom(out); |
| 3969 | vixl32::Register in1_hi = HighRegisterFrom(first); |
| 3970 | vixl32::Register in1_lo = LowRegisterFrom(first); |
| 3971 | vixl32::Register in2_hi = HighRegisterFrom(second); |
| 3972 | vixl32::Register in2_lo = LowRegisterFrom(second); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3973 | |
| 3974 | // Extra checks to protect caused by the existence of R1_R2. |
| 3975 | // The algorithm is wrong if out.hi is either in1.lo or in2.lo: |
| 3976 | // (e.g. in1=r0_r1, in2=r2_r3 and out=r1_r2); |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 3977 | DCHECK(!out_hi.Is(in1_lo)); |
| 3978 | DCHECK(!out_hi.Is(in2_lo)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3979 | |
| 3980 | // input: in1 - 64 bits, in2 - 64 bits |
| 3981 | // output: out |
| 3982 | // formula: out.hi : out.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo |
| 3983 | // parts: out.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32] |
| 3984 | // parts: out.lo = (in1.lo * in2.lo)[31:0] |
| 3985 | |
| 3986 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 3987 | vixl32::Register temp = temps.Acquire(); |
| 3988 | // temp <- in1.lo * in2.hi |
| 3989 | __ Mul(temp, in1_lo, in2_hi); |
| 3990 | // out.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3991 | __ Mla(out_hi, in1_hi, in2_lo, temp); |
| 3992 | // out.lo <- (in1.lo * in2.lo)[31:0]; |
| 3993 | __ Umull(out_lo, temp, in1_lo, in2_lo); |
| 3994 | // 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] | 3995 | __ Add(out_hi, out_hi, temp); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3996 | break; |
| 3997 | } |
| 3998 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3999 | case Primitive::kPrimFloat: |
| 4000 | case Primitive::kPrimDouble: |
| 4001 | __ Vmul(OutputVRegister(mul), InputVRegisterAt(mul, 0), InputVRegisterAt(mul, 1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4002 | break; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4003 | |
| 4004 | default: |
| 4005 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 4006 | } |
| 4007 | } |
| 4008 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4009 | void InstructionCodeGeneratorARMVIXL::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 4010 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 4011 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 4012 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4013 | Location second = instruction->GetLocations()->InAt(1); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4014 | DCHECK(second.IsConstant()); |
| 4015 | |
| 4016 | vixl32::Register out = OutputRegister(instruction); |
| 4017 | vixl32::Register dividend = InputRegisterAt(instruction, 0); |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 4018 | int32_t imm = Int32ConstantFrom(second); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4019 | DCHECK(imm == 1 || imm == -1); |
| 4020 | |
| 4021 | if (instruction->IsRem()) { |
| 4022 | __ Mov(out, 0); |
| 4023 | } else { |
| 4024 | if (imm == 1) { |
| 4025 | __ Mov(out, dividend); |
| 4026 | } else { |
| 4027 | __ Rsb(out, dividend, 0); |
| 4028 | } |
| 4029 | } |
| 4030 | } |
| 4031 | |
| 4032 | void InstructionCodeGeneratorARMVIXL::DivRemByPowerOfTwo(HBinaryOperation* instruction) { |
| 4033 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 4034 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 4035 | |
| 4036 | LocationSummary* locations = instruction->GetLocations(); |
| 4037 | Location second = locations->InAt(1); |
| 4038 | DCHECK(second.IsConstant()); |
| 4039 | |
| 4040 | vixl32::Register out = OutputRegister(instruction); |
| 4041 | vixl32::Register dividend = InputRegisterAt(instruction, 0); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4042 | vixl32::Register temp = RegisterFrom(locations->GetTemp(0)); |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 4043 | int32_t imm = Int32ConstantFrom(second); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4044 | uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm)); |
| 4045 | int ctz_imm = CTZ(abs_imm); |
| 4046 | |
| 4047 | if (ctz_imm == 1) { |
| 4048 | __ Lsr(temp, dividend, 32 - ctz_imm); |
| 4049 | } else { |
| 4050 | __ Asr(temp, dividend, 31); |
| 4051 | __ Lsr(temp, temp, 32 - ctz_imm); |
| 4052 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4053 | __ Add(out, temp, dividend); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4054 | |
| 4055 | if (instruction->IsDiv()) { |
| 4056 | __ Asr(out, out, ctz_imm); |
| 4057 | if (imm < 0) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4058 | __ Rsb(out, out, 0); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4059 | } |
| 4060 | } else { |
| 4061 | __ Ubfx(out, out, 0, ctz_imm); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4062 | __ Sub(out, out, temp); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4063 | } |
| 4064 | } |
| 4065 | |
| 4066 | void InstructionCodeGeneratorARMVIXL::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 4067 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 4068 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 4069 | |
| 4070 | LocationSummary* locations = instruction->GetLocations(); |
| 4071 | Location second = locations->InAt(1); |
| 4072 | DCHECK(second.IsConstant()); |
| 4073 | |
| 4074 | vixl32::Register out = OutputRegister(instruction); |
| 4075 | vixl32::Register dividend = InputRegisterAt(instruction, 0); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4076 | vixl32::Register temp1 = RegisterFrom(locations->GetTemp(0)); |
| 4077 | vixl32::Register temp2 = RegisterFrom(locations->GetTemp(1)); |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 4078 | int32_t imm = Int32ConstantFrom(second); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4079 | |
| 4080 | int64_t magic; |
| 4081 | int shift; |
| 4082 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 4083 | |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 4084 | // TODO(VIXL): Change the static cast to Operand::From() after VIXL is fixed. |
| 4085 | __ Mov(temp1, static_cast<int32_t>(magic)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4086 | __ Smull(temp2, temp1, dividend, temp1); |
| 4087 | |
| 4088 | if (imm > 0 && magic < 0) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4089 | __ Add(temp1, temp1, dividend); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4090 | } else if (imm < 0 && magic > 0) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4091 | __ Sub(temp1, temp1, dividend); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4092 | } |
| 4093 | |
| 4094 | if (shift != 0) { |
| 4095 | __ Asr(temp1, temp1, shift); |
| 4096 | } |
| 4097 | |
| 4098 | if (instruction->IsDiv()) { |
| 4099 | __ Sub(out, temp1, Operand(temp1, vixl32::Shift(ASR), 31)); |
| 4100 | } else { |
| 4101 | __ Sub(temp1, temp1, Operand(temp1, vixl32::Shift(ASR), 31)); |
| 4102 | // TODO: Strength reduction for mls. |
| 4103 | __ Mov(temp2, imm); |
| 4104 | __ Mls(out, temp1, temp2, dividend); |
| 4105 | } |
| 4106 | } |
| 4107 | |
| 4108 | void InstructionCodeGeneratorARMVIXL::GenerateDivRemConstantIntegral( |
| 4109 | HBinaryOperation* instruction) { |
| 4110 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 4111 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 4112 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4113 | Location second = instruction->GetLocations()->InAt(1); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4114 | DCHECK(second.IsConstant()); |
| 4115 | |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 4116 | int32_t imm = Int32ConstantFrom(second); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4117 | if (imm == 0) { |
| 4118 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 4119 | } else if (imm == 1 || imm == -1) { |
| 4120 | DivRemOneOrMinusOne(instruction); |
| 4121 | } else if (IsPowerOfTwo(AbsOrMin(imm))) { |
| 4122 | DivRemByPowerOfTwo(instruction); |
| 4123 | } else { |
| 4124 | DCHECK(imm <= -2 || imm >= 2); |
| 4125 | GenerateDivRemWithAnyConstant(instruction); |
| 4126 | } |
| 4127 | } |
| 4128 | |
| 4129 | void LocationsBuilderARMVIXL::VisitDiv(HDiv* div) { |
| 4130 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 4131 | if (div->GetResultType() == Primitive::kPrimLong) { |
| 4132 | // pLdiv runtime call. |
| 4133 | call_kind = LocationSummary::kCallOnMainOnly; |
| 4134 | } else if (div->GetResultType() == Primitive::kPrimInt && div->InputAt(1)->IsConstant()) { |
| 4135 | // sdiv will be replaced by other instruction sequence. |
| 4136 | } else if (div->GetResultType() == Primitive::kPrimInt && |
| 4137 | !codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 4138 | // pIdivmod runtime call. |
| 4139 | call_kind = LocationSummary::kCallOnMainOnly; |
| 4140 | } |
| 4141 | |
| 4142 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind); |
| 4143 | |
| 4144 | switch (div->GetResultType()) { |
| 4145 | case Primitive::kPrimInt: { |
| 4146 | if (div->InputAt(1)->IsConstant()) { |
| 4147 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4148 | locations->SetInAt(1, Location::ConstantLocation(div->InputAt(1)->AsConstant())); |
| 4149 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 4150 | int32_t value = Int32ConstantFrom(div->InputAt(1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4151 | if (value == 1 || value == 0 || value == -1) { |
| 4152 | // No temp register required. |
| 4153 | } else { |
| 4154 | locations->AddTemp(Location::RequiresRegister()); |
| 4155 | if (!IsPowerOfTwo(AbsOrMin(value))) { |
| 4156 | locations->AddTemp(Location::RequiresRegister()); |
| 4157 | } |
| 4158 | } |
| 4159 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 4160 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4161 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4162 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4163 | } else { |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4164 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4165 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 4166 | locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(1))); |
Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 4167 | // Note: divmod will compute both the quotient and the remainder as the pair R0 and R1, but |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4168 | // we only need the former. |
| 4169 | locations->SetOut(LocationFrom(r0)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4170 | } |
| 4171 | break; |
| 4172 | } |
| 4173 | case Primitive::kPrimLong: { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 4174 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4175 | locations->SetInAt(0, LocationFrom( |
| 4176 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 4177 | locations->SetInAt(1, LocationFrom( |
| 4178 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 4179 | locations->SetOut(LocationFrom(r0, r1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4180 | break; |
| 4181 | } |
| 4182 | case Primitive::kPrimFloat: |
| 4183 | case Primitive::kPrimDouble: { |
| 4184 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4185 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4186 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4187 | break; |
| 4188 | } |
| 4189 | |
| 4190 | default: |
| 4191 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 4192 | } |
| 4193 | } |
| 4194 | |
| 4195 | void InstructionCodeGeneratorARMVIXL::VisitDiv(HDiv* div) { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 4196 | Location lhs = div->GetLocations()->InAt(0); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4197 | Location rhs = div->GetLocations()->InAt(1); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4198 | |
| 4199 | switch (div->GetResultType()) { |
| 4200 | case Primitive::kPrimInt: { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4201 | if (rhs.IsConstant()) { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4202 | GenerateDivRemConstantIntegral(div); |
| 4203 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 4204 | __ Sdiv(OutputRegister(div), InputRegisterAt(div, 0), InputRegisterAt(div, 1)); |
| 4205 | } else { |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4206 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4207 | DCHECK(calling_convention.GetRegisterAt(0).Is(RegisterFrom(lhs))); |
| 4208 | DCHECK(calling_convention.GetRegisterAt(1).Is(RegisterFrom(rhs))); |
| 4209 | DCHECK(r0.Is(OutputRegister(div))); |
| 4210 | |
| 4211 | codegen_->InvokeRuntime(kQuickIdivmod, div, div->GetDexPc()); |
| 4212 | CheckEntrypointTypes<kQuickIdivmod, int32_t, int32_t, int32_t>(); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4213 | } |
| 4214 | break; |
| 4215 | } |
| 4216 | |
| 4217 | case Primitive::kPrimLong: { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 4218 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4219 | DCHECK(calling_convention.GetRegisterAt(0).Is(LowRegisterFrom(lhs))); |
| 4220 | DCHECK(calling_convention.GetRegisterAt(1).Is(HighRegisterFrom(lhs))); |
| 4221 | DCHECK(calling_convention.GetRegisterAt(2).Is(LowRegisterFrom(rhs))); |
| 4222 | DCHECK(calling_convention.GetRegisterAt(3).Is(HighRegisterFrom(rhs))); |
| 4223 | DCHECK(LowRegisterFrom(div->GetLocations()->Out()).Is(r0)); |
| 4224 | DCHECK(HighRegisterFrom(div->GetLocations()->Out()).Is(r1)); |
| 4225 | |
| 4226 | codegen_->InvokeRuntime(kQuickLdiv, div, div->GetDexPc()); |
| 4227 | CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>(); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4228 | break; |
| 4229 | } |
| 4230 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4231 | case Primitive::kPrimFloat: |
| 4232 | case Primitive::kPrimDouble: |
| 4233 | __ Vdiv(OutputVRegister(div), InputVRegisterAt(div, 0), InputVRegisterAt(div, 1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4234 | break; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4235 | |
| 4236 | default: |
| 4237 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 4238 | } |
| 4239 | } |
| 4240 | |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4241 | void LocationsBuilderARMVIXL::VisitRem(HRem* rem) { |
| 4242 | Primitive::Type type = rem->GetResultType(); |
| 4243 | |
| 4244 | // Most remainders are implemented in the runtime. |
| 4245 | LocationSummary::CallKind call_kind = LocationSummary::kCallOnMainOnly; |
| 4246 | if (rem->GetResultType() == Primitive::kPrimInt && rem->InputAt(1)->IsConstant()) { |
| 4247 | // sdiv will be replaced by other instruction sequence. |
| 4248 | call_kind = LocationSummary::kNoCall; |
| 4249 | } else if ((rem->GetResultType() == Primitive::kPrimInt) |
| 4250 | && codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 4251 | // Have hardware divide instruction for int, do it with three instructions. |
| 4252 | call_kind = LocationSummary::kNoCall; |
| 4253 | } |
| 4254 | |
| 4255 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind); |
| 4256 | |
| 4257 | switch (type) { |
| 4258 | case Primitive::kPrimInt: { |
| 4259 | if (rem->InputAt(1)->IsConstant()) { |
| 4260 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4261 | locations->SetInAt(1, Location::ConstantLocation(rem->InputAt(1)->AsConstant())); |
| 4262 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 4263 | int32_t value = Int32ConstantFrom(rem->InputAt(1)); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4264 | if (value == 1 || value == 0 || value == -1) { |
| 4265 | // No temp register required. |
| 4266 | } else { |
| 4267 | locations->AddTemp(Location::RequiresRegister()); |
| 4268 | if (!IsPowerOfTwo(AbsOrMin(value))) { |
| 4269 | locations->AddTemp(Location::RequiresRegister()); |
| 4270 | } |
| 4271 | } |
| 4272 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 4273 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4274 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4275 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4276 | locations->AddTemp(Location::RequiresRegister()); |
| 4277 | } else { |
| 4278 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4279 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 4280 | locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(1))); |
Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 4281 | // Note: divmod will compute both the quotient and the remainder as the pair R0 and R1, but |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4282 | // we only need the latter. |
| 4283 | locations->SetOut(LocationFrom(r1)); |
| 4284 | } |
| 4285 | break; |
| 4286 | } |
| 4287 | case Primitive::kPrimLong: { |
| 4288 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4289 | locations->SetInAt(0, LocationFrom( |
| 4290 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 4291 | locations->SetInAt(1, LocationFrom( |
| 4292 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 4293 | // The runtime helper puts the output in R2,R3. |
| 4294 | locations->SetOut(LocationFrom(r2, r3)); |
| 4295 | break; |
| 4296 | } |
| 4297 | case Primitive::kPrimFloat: { |
| 4298 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4299 | locations->SetInAt(0, LocationFrom(calling_convention.GetFpuRegisterAt(0))); |
| 4300 | locations->SetInAt(1, LocationFrom(calling_convention.GetFpuRegisterAt(1))); |
| 4301 | locations->SetOut(LocationFrom(s0)); |
| 4302 | break; |
| 4303 | } |
| 4304 | |
| 4305 | case Primitive::kPrimDouble: { |
| 4306 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4307 | locations->SetInAt(0, LocationFrom( |
| 4308 | calling_convention.GetFpuRegisterAt(0), calling_convention.GetFpuRegisterAt(1))); |
| 4309 | locations->SetInAt(1, LocationFrom( |
| 4310 | calling_convention.GetFpuRegisterAt(2), calling_convention.GetFpuRegisterAt(3))); |
| 4311 | locations->SetOut(LocationFrom(s0, s1)); |
| 4312 | break; |
| 4313 | } |
| 4314 | |
| 4315 | default: |
| 4316 | LOG(FATAL) << "Unexpected rem type " << type; |
| 4317 | } |
| 4318 | } |
| 4319 | |
| 4320 | void InstructionCodeGeneratorARMVIXL::VisitRem(HRem* rem) { |
| 4321 | LocationSummary* locations = rem->GetLocations(); |
| 4322 | Location second = locations->InAt(1); |
| 4323 | |
| 4324 | Primitive::Type type = rem->GetResultType(); |
| 4325 | switch (type) { |
| 4326 | case Primitive::kPrimInt: { |
| 4327 | vixl32::Register reg1 = InputRegisterAt(rem, 0); |
| 4328 | vixl32::Register out_reg = OutputRegister(rem); |
| 4329 | if (second.IsConstant()) { |
| 4330 | GenerateDivRemConstantIntegral(rem); |
| 4331 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 4332 | vixl32::Register reg2 = RegisterFrom(second); |
| 4333 | vixl32::Register temp = RegisterFrom(locations->GetTemp(0)); |
| 4334 | |
| 4335 | // temp = reg1 / reg2 (integer division) |
| 4336 | // dest = reg1 - temp * reg2 |
| 4337 | __ Sdiv(temp, reg1, reg2); |
| 4338 | __ Mls(out_reg, temp, reg2, reg1); |
| 4339 | } else { |
| 4340 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4341 | DCHECK(reg1.Is(calling_convention.GetRegisterAt(0))); |
| 4342 | DCHECK(RegisterFrom(second).Is(calling_convention.GetRegisterAt(1))); |
| 4343 | DCHECK(out_reg.Is(r1)); |
| 4344 | |
| 4345 | codegen_->InvokeRuntime(kQuickIdivmod, rem, rem->GetDexPc()); |
| 4346 | CheckEntrypointTypes<kQuickIdivmod, int32_t, int32_t, int32_t>(); |
| 4347 | } |
| 4348 | break; |
| 4349 | } |
| 4350 | |
| 4351 | case Primitive::kPrimLong: { |
| 4352 | codegen_->InvokeRuntime(kQuickLmod, rem, rem->GetDexPc()); |
| 4353 | CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>(); |
| 4354 | break; |
| 4355 | } |
| 4356 | |
| 4357 | case Primitive::kPrimFloat: { |
| 4358 | codegen_->InvokeRuntime(kQuickFmodf, rem, rem->GetDexPc()); |
| 4359 | CheckEntrypointTypes<kQuickFmodf, float, float, float>(); |
| 4360 | break; |
| 4361 | } |
| 4362 | |
| 4363 | case Primitive::kPrimDouble: { |
| 4364 | codegen_->InvokeRuntime(kQuickFmod, rem, rem->GetDexPc()); |
| 4365 | CheckEntrypointTypes<kQuickFmod, double, double, double>(); |
| 4366 | break; |
| 4367 | } |
| 4368 | |
| 4369 | default: |
| 4370 | LOG(FATAL) << "Unexpected rem type " << type; |
| 4371 | } |
| 4372 | } |
| 4373 | |
| 4374 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4375 | void LocationsBuilderARMVIXL::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 4376 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4377 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4378 | } |
| 4379 | |
| 4380 | void InstructionCodeGeneratorARMVIXL::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 4381 | DivZeroCheckSlowPathARMVIXL* slow_path = |
| 4382 | new (GetGraph()->GetArena()) DivZeroCheckSlowPathARMVIXL(instruction); |
| 4383 | codegen_->AddSlowPath(slow_path); |
| 4384 | |
| 4385 | LocationSummary* locations = instruction->GetLocations(); |
| 4386 | Location value = locations->InAt(0); |
| 4387 | |
| 4388 | switch (instruction->GetType()) { |
| 4389 | case Primitive::kPrimBoolean: |
| 4390 | case Primitive::kPrimByte: |
| 4391 | case Primitive::kPrimChar: |
| 4392 | case Primitive::kPrimShort: |
| 4393 | case Primitive::kPrimInt: { |
| 4394 | if (value.IsRegister()) { |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 4395 | __ CompareAndBranchIfZero(InputRegisterAt(instruction, 0), slow_path->GetEntryLabel()); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4396 | } else { |
| 4397 | DCHECK(value.IsConstant()) << value; |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 4398 | if (Int32ConstantFrom(value) == 0) { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4399 | __ B(slow_path->GetEntryLabel()); |
| 4400 | } |
| 4401 | } |
| 4402 | break; |
| 4403 | } |
| 4404 | case Primitive::kPrimLong: { |
| 4405 | if (value.IsRegisterPair()) { |
| 4406 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 4407 | vixl32::Register temp = temps.Acquire(); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4408 | __ Orrs(temp, LowRegisterFrom(value), HighRegisterFrom(value)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4409 | __ B(eq, slow_path->GetEntryLabel()); |
| 4410 | } else { |
| 4411 | DCHECK(value.IsConstant()) << value; |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 4412 | if (Int64ConstantFrom(value) == 0) { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4413 | __ B(slow_path->GetEntryLabel()); |
| 4414 | } |
| 4415 | } |
| 4416 | break; |
| 4417 | } |
| 4418 | default: |
| 4419 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
| 4420 | } |
| 4421 | } |
| 4422 | |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 4423 | void InstructionCodeGeneratorARMVIXL::HandleIntegerRotate(HRor* ror) { |
| 4424 | LocationSummary* locations = ror->GetLocations(); |
| 4425 | vixl32::Register in = InputRegisterAt(ror, 0); |
| 4426 | Location rhs = locations->InAt(1); |
| 4427 | vixl32::Register out = OutputRegister(ror); |
| 4428 | |
| 4429 | if (rhs.IsConstant()) { |
| 4430 | // Arm32 and Thumb2 assemblers require a rotation on the interval [1,31], |
| 4431 | // so map all rotations to a +ve. equivalent in that range. |
| 4432 | // (e.g. left *or* right by -2 bits == 30 bits in the same direction.) |
| 4433 | uint32_t rot = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()) & 0x1F; |
| 4434 | if (rot) { |
| 4435 | // Rotate, mapping left rotations to right equivalents if necessary. |
| 4436 | // (e.g. left by 2 bits == right by 30.) |
| 4437 | __ Ror(out, in, rot); |
| 4438 | } else if (!out.Is(in)) { |
| 4439 | __ Mov(out, in); |
| 4440 | } |
| 4441 | } else { |
| 4442 | __ Ror(out, in, RegisterFrom(rhs)); |
| 4443 | } |
| 4444 | } |
| 4445 | |
| 4446 | // Gain some speed by mapping all Long rotates onto equivalent pairs of Integer |
| 4447 | // rotates by swapping input regs (effectively rotating by the first 32-bits of |
| 4448 | // a larger rotation) or flipping direction (thus treating larger right/left |
| 4449 | // rotations as sub-word sized rotations in the other direction) as appropriate. |
| 4450 | void InstructionCodeGeneratorARMVIXL::HandleLongRotate(HRor* ror) { |
| 4451 | LocationSummary* locations = ror->GetLocations(); |
| 4452 | vixl32::Register in_reg_lo = LowRegisterFrom(locations->InAt(0)); |
| 4453 | vixl32::Register in_reg_hi = HighRegisterFrom(locations->InAt(0)); |
| 4454 | Location rhs = locations->InAt(1); |
| 4455 | vixl32::Register out_reg_lo = LowRegisterFrom(locations->Out()); |
| 4456 | vixl32::Register out_reg_hi = HighRegisterFrom(locations->Out()); |
| 4457 | |
| 4458 | if (rhs.IsConstant()) { |
| 4459 | uint64_t rot = CodeGenerator::GetInt64ValueOf(rhs.GetConstant()); |
| 4460 | // Map all rotations to +ve. equivalents on the interval [0,63]. |
| 4461 | rot &= kMaxLongShiftDistance; |
| 4462 | // For rotates over a word in size, 'pre-rotate' by 32-bits to keep rotate |
| 4463 | // logic below to a simple pair of binary orr. |
| 4464 | // (e.g. 34 bits == in_reg swap + 2 bits right.) |
| 4465 | if (rot >= kArmBitsPerWord) { |
| 4466 | rot -= kArmBitsPerWord; |
| 4467 | std::swap(in_reg_hi, in_reg_lo); |
| 4468 | } |
| 4469 | // Rotate, or mov to out for zero or word size rotations. |
| 4470 | if (rot != 0u) { |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 4471 | __ Lsr(out_reg_hi, in_reg_hi, Operand::From(rot)); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 4472 | __ 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] | 4473 | __ Lsr(out_reg_lo, in_reg_lo, Operand::From(rot)); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 4474 | __ Orr(out_reg_lo, out_reg_lo, Operand(in_reg_hi, ShiftType::LSL, kArmBitsPerWord - rot)); |
| 4475 | } else { |
| 4476 | __ Mov(out_reg_lo, in_reg_lo); |
| 4477 | __ Mov(out_reg_hi, in_reg_hi); |
| 4478 | } |
| 4479 | } else { |
| 4480 | vixl32::Register shift_right = RegisterFrom(locations->GetTemp(0)); |
| 4481 | vixl32::Register shift_left = RegisterFrom(locations->GetTemp(1)); |
| 4482 | vixl32::Label end; |
| 4483 | vixl32::Label shift_by_32_plus_shift_right; |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 4484 | vixl32::Label* final_label = codegen_->GetFinalLabel(ror, &end); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 4485 | |
| 4486 | __ And(shift_right, RegisterFrom(rhs), 0x1F); |
| 4487 | __ Lsrs(shift_left, RegisterFrom(rhs), 6); |
Scott Wakeling | bffdc70 | 2016-12-07 17:46:03 +0000 | [diff] [blame] | 4488 | __ Rsb(LeaveFlags, shift_left, shift_right, Operand::From(kArmBitsPerWord)); |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 4489 | __ B(cc, &shift_by_32_plus_shift_right, /* far_target */ false); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 4490 | |
| 4491 | // out_reg_hi = (reg_hi << shift_left) | (reg_lo >> shift_right). |
| 4492 | // out_reg_lo = (reg_lo << shift_left) | (reg_hi >> shift_right). |
| 4493 | __ Lsl(out_reg_hi, in_reg_hi, shift_left); |
| 4494 | __ Lsr(out_reg_lo, in_reg_lo, shift_right); |
| 4495 | __ Add(out_reg_hi, out_reg_hi, out_reg_lo); |
| 4496 | __ Lsl(out_reg_lo, in_reg_lo, shift_left); |
| 4497 | __ Lsr(shift_left, in_reg_hi, shift_right); |
| 4498 | __ Add(out_reg_lo, out_reg_lo, shift_left); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 4499 | __ B(final_label); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 4500 | |
| 4501 | __ Bind(&shift_by_32_plus_shift_right); // Shift by 32+shift_right. |
| 4502 | // out_reg_hi = (reg_hi >> shift_right) | (reg_lo << shift_left). |
| 4503 | // out_reg_lo = (reg_lo >> shift_right) | (reg_hi << shift_left). |
| 4504 | __ Lsr(out_reg_hi, in_reg_hi, shift_right); |
| 4505 | __ Lsl(out_reg_lo, in_reg_lo, shift_left); |
| 4506 | __ Add(out_reg_hi, out_reg_hi, out_reg_lo); |
| 4507 | __ Lsr(out_reg_lo, in_reg_lo, shift_right); |
| 4508 | __ Lsl(shift_right, in_reg_hi, shift_left); |
| 4509 | __ Add(out_reg_lo, out_reg_lo, shift_right); |
| 4510 | |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 4511 | if (end.IsReferenced()) { |
| 4512 | __ Bind(&end); |
| 4513 | } |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 4514 | } |
| 4515 | } |
| 4516 | |
| 4517 | void LocationsBuilderARMVIXL::VisitRor(HRor* ror) { |
| 4518 | LocationSummary* locations = |
| 4519 | new (GetGraph()->GetArena()) LocationSummary(ror, LocationSummary::kNoCall); |
| 4520 | switch (ror->GetResultType()) { |
| 4521 | case Primitive::kPrimInt: { |
| 4522 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4523 | locations->SetInAt(1, Location::RegisterOrConstant(ror->InputAt(1))); |
| 4524 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4525 | break; |
| 4526 | } |
| 4527 | case Primitive::kPrimLong: { |
| 4528 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4529 | if (ror->InputAt(1)->IsConstant()) { |
| 4530 | locations->SetInAt(1, Location::ConstantLocation(ror->InputAt(1)->AsConstant())); |
| 4531 | } else { |
| 4532 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4533 | locations->AddTemp(Location::RequiresRegister()); |
| 4534 | locations->AddTemp(Location::RequiresRegister()); |
| 4535 | } |
| 4536 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 4537 | break; |
| 4538 | } |
| 4539 | default: |
| 4540 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 4541 | } |
| 4542 | } |
| 4543 | |
| 4544 | void InstructionCodeGeneratorARMVIXL::VisitRor(HRor* ror) { |
| 4545 | Primitive::Type type = ror->GetResultType(); |
| 4546 | switch (type) { |
| 4547 | case Primitive::kPrimInt: { |
| 4548 | HandleIntegerRotate(ror); |
| 4549 | break; |
| 4550 | } |
| 4551 | case Primitive::kPrimLong: { |
| 4552 | HandleLongRotate(ror); |
| 4553 | break; |
| 4554 | } |
| 4555 | default: |
| 4556 | LOG(FATAL) << "Unexpected operation type " << type; |
| 4557 | UNREACHABLE(); |
| 4558 | } |
| 4559 | } |
| 4560 | |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4561 | void LocationsBuilderARMVIXL::HandleShift(HBinaryOperation* op) { |
| 4562 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 4563 | |
| 4564 | LocationSummary* locations = |
| 4565 | new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall); |
| 4566 | |
| 4567 | switch (op->GetResultType()) { |
| 4568 | case Primitive::kPrimInt: { |
| 4569 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4570 | if (op->InputAt(1)->IsConstant()) { |
| 4571 | locations->SetInAt(1, Location::ConstantLocation(op->InputAt(1)->AsConstant())); |
| 4572 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4573 | } else { |
| 4574 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4575 | // Make the output overlap, as it will be used to hold the masked |
| 4576 | // second input. |
| 4577 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 4578 | } |
| 4579 | break; |
| 4580 | } |
| 4581 | case Primitive::kPrimLong: { |
| 4582 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4583 | if (op->InputAt(1)->IsConstant()) { |
| 4584 | locations->SetInAt(1, Location::ConstantLocation(op->InputAt(1)->AsConstant())); |
| 4585 | // For simplicity, use kOutputOverlap even though we only require that low registers |
| 4586 | // don't clash with high registers which the register allocator currently guarantees. |
| 4587 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 4588 | } else { |
| 4589 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4590 | locations->AddTemp(Location::RequiresRegister()); |
| 4591 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 4592 | } |
| 4593 | break; |
| 4594 | } |
| 4595 | default: |
| 4596 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
| 4597 | } |
| 4598 | } |
| 4599 | |
| 4600 | void InstructionCodeGeneratorARMVIXL::HandleShift(HBinaryOperation* op) { |
| 4601 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 4602 | |
| 4603 | LocationSummary* locations = op->GetLocations(); |
| 4604 | Location out = locations->Out(); |
| 4605 | Location first = locations->InAt(0); |
| 4606 | Location second = locations->InAt(1); |
| 4607 | |
| 4608 | Primitive::Type type = op->GetResultType(); |
| 4609 | switch (type) { |
| 4610 | case Primitive::kPrimInt: { |
| 4611 | vixl32::Register out_reg = OutputRegister(op); |
| 4612 | vixl32::Register first_reg = InputRegisterAt(op, 0); |
| 4613 | if (second.IsRegister()) { |
| 4614 | vixl32::Register second_reg = RegisterFrom(second); |
| 4615 | // ARM doesn't mask the shift count so we need to do it ourselves. |
| 4616 | __ And(out_reg, second_reg, kMaxIntShiftDistance); |
| 4617 | if (op->IsShl()) { |
| 4618 | __ Lsl(out_reg, first_reg, out_reg); |
| 4619 | } else if (op->IsShr()) { |
| 4620 | __ Asr(out_reg, first_reg, out_reg); |
| 4621 | } else { |
| 4622 | __ Lsr(out_reg, first_reg, out_reg); |
| 4623 | } |
| 4624 | } else { |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 4625 | int32_t cst = Int32ConstantFrom(second); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4626 | uint32_t shift_value = cst & kMaxIntShiftDistance; |
| 4627 | if (shift_value == 0) { // ARM does not support shifting with 0 immediate. |
| 4628 | __ Mov(out_reg, first_reg); |
| 4629 | } else if (op->IsShl()) { |
| 4630 | __ Lsl(out_reg, first_reg, shift_value); |
| 4631 | } else if (op->IsShr()) { |
| 4632 | __ Asr(out_reg, first_reg, shift_value); |
| 4633 | } else { |
| 4634 | __ Lsr(out_reg, first_reg, shift_value); |
| 4635 | } |
| 4636 | } |
| 4637 | break; |
| 4638 | } |
| 4639 | case Primitive::kPrimLong: { |
| 4640 | vixl32::Register o_h = HighRegisterFrom(out); |
| 4641 | vixl32::Register o_l = LowRegisterFrom(out); |
| 4642 | |
| 4643 | vixl32::Register high = HighRegisterFrom(first); |
| 4644 | vixl32::Register low = LowRegisterFrom(first); |
| 4645 | |
| 4646 | if (second.IsRegister()) { |
| 4647 | vixl32::Register temp = RegisterFrom(locations->GetTemp(0)); |
| 4648 | |
| 4649 | vixl32::Register second_reg = RegisterFrom(second); |
| 4650 | |
| 4651 | if (op->IsShl()) { |
| 4652 | __ And(o_l, second_reg, kMaxLongShiftDistance); |
| 4653 | // Shift the high part |
| 4654 | __ Lsl(o_h, high, o_l); |
| 4655 | // Shift the low part and `or` what overflew on the high part |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 4656 | __ Rsb(temp, o_l, Operand::From(kArmBitsPerWord)); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4657 | __ Lsr(temp, low, temp); |
| 4658 | __ Orr(o_h, o_h, temp); |
| 4659 | // If the shift is > 32 bits, override the high part |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 4660 | __ Subs(temp, o_l, Operand::From(kArmBitsPerWord)); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4661 | { |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 4662 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 4663 | 2 * vixl32::kMaxInstructionSizeInBytes, |
| 4664 | CodeBufferCheckScope::kMaximumSize); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4665 | __ it(pl); |
| 4666 | __ lsl(pl, o_h, low, temp); |
| 4667 | } |
| 4668 | // Shift the low part |
| 4669 | __ Lsl(o_l, low, o_l); |
| 4670 | } else if (op->IsShr()) { |
| 4671 | __ And(o_h, second_reg, kMaxLongShiftDistance); |
| 4672 | // Shift the low part |
| 4673 | __ Lsr(o_l, low, o_h); |
| 4674 | // Shift the high part and `or` what underflew on the low part |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 4675 | __ Rsb(temp, o_h, Operand::From(kArmBitsPerWord)); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4676 | __ Lsl(temp, high, temp); |
| 4677 | __ Orr(o_l, o_l, temp); |
| 4678 | // If the shift is > 32 bits, override the low part |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 4679 | __ Subs(temp, o_h, Operand::From(kArmBitsPerWord)); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4680 | { |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 4681 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 4682 | 2 * vixl32::kMaxInstructionSizeInBytes, |
| 4683 | CodeBufferCheckScope::kMaximumSize); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4684 | __ it(pl); |
| 4685 | __ asr(pl, o_l, high, temp); |
| 4686 | } |
| 4687 | // Shift the high part |
| 4688 | __ Asr(o_h, high, o_h); |
| 4689 | } else { |
| 4690 | __ And(o_h, second_reg, kMaxLongShiftDistance); |
| 4691 | // same as Shr except we use `Lsr`s and not `Asr`s |
| 4692 | __ Lsr(o_l, low, o_h); |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 4693 | __ Rsb(temp, o_h, Operand::From(kArmBitsPerWord)); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4694 | __ Lsl(temp, high, temp); |
| 4695 | __ Orr(o_l, o_l, temp); |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 4696 | __ Subs(temp, o_h, Operand::From(kArmBitsPerWord)); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4697 | { |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 4698 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 4699 | 2 * vixl32::kMaxInstructionSizeInBytes, |
| 4700 | CodeBufferCheckScope::kMaximumSize); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4701 | __ it(pl); |
| 4702 | __ lsr(pl, o_l, high, temp); |
| 4703 | } |
| 4704 | __ Lsr(o_h, high, o_h); |
| 4705 | } |
| 4706 | } else { |
| 4707 | // Register allocator doesn't create partial overlap. |
| 4708 | DCHECK(!o_l.Is(high)); |
| 4709 | DCHECK(!o_h.Is(low)); |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 4710 | int32_t cst = Int32ConstantFrom(second); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4711 | uint32_t shift_value = cst & kMaxLongShiftDistance; |
| 4712 | if (shift_value > 32) { |
| 4713 | if (op->IsShl()) { |
| 4714 | __ Lsl(o_h, low, shift_value - 32); |
| 4715 | __ Mov(o_l, 0); |
| 4716 | } else if (op->IsShr()) { |
| 4717 | __ Asr(o_l, high, shift_value - 32); |
| 4718 | __ Asr(o_h, high, 31); |
| 4719 | } else { |
| 4720 | __ Lsr(o_l, high, shift_value - 32); |
| 4721 | __ Mov(o_h, 0); |
| 4722 | } |
| 4723 | } else if (shift_value == 32) { |
| 4724 | if (op->IsShl()) { |
| 4725 | __ Mov(o_h, low); |
| 4726 | __ Mov(o_l, 0); |
| 4727 | } else if (op->IsShr()) { |
| 4728 | __ Mov(o_l, high); |
| 4729 | __ Asr(o_h, high, 31); |
| 4730 | } else { |
| 4731 | __ Mov(o_l, high); |
| 4732 | __ Mov(o_h, 0); |
| 4733 | } |
| 4734 | } else if (shift_value == 1) { |
| 4735 | if (op->IsShl()) { |
| 4736 | __ Lsls(o_l, low, 1); |
| 4737 | __ Adc(o_h, high, high); |
| 4738 | } else if (op->IsShr()) { |
| 4739 | __ Asrs(o_h, high, 1); |
| 4740 | __ Rrx(o_l, low); |
| 4741 | } else { |
| 4742 | __ Lsrs(o_h, high, 1); |
| 4743 | __ Rrx(o_l, low); |
| 4744 | } |
| 4745 | } else { |
| 4746 | DCHECK(2 <= shift_value && shift_value < 32) << shift_value; |
| 4747 | if (op->IsShl()) { |
| 4748 | __ Lsl(o_h, high, shift_value); |
| 4749 | __ Orr(o_h, o_h, Operand(low, ShiftType::LSR, 32 - shift_value)); |
| 4750 | __ Lsl(o_l, low, shift_value); |
| 4751 | } else if (op->IsShr()) { |
| 4752 | __ Lsr(o_l, low, shift_value); |
| 4753 | __ Orr(o_l, o_l, Operand(high, ShiftType::LSL, 32 - shift_value)); |
| 4754 | __ Asr(o_h, high, shift_value); |
| 4755 | } else { |
| 4756 | __ Lsr(o_l, low, shift_value); |
| 4757 | __ Orr(o_l, o_l, Operand(high, ShiftType::LSL, 32 - shift_value)); |
| 4758 | __ Lsr(o_h, high, shift_value); |
| 4759 | } |
| 4760 | } |
| 4761 | } |
| 4762 | break; |
| 4763 | } |
| 4764 | default: |
| 4765 | LOG(FATAL) << "Unexpected operation type " << type; |
| 4766 | UNREACHABLE(); |
| 4767 | } |
| 4768 | } |
| 4769 | |
| 4770 | void LocationsBuilderARMVIXL::VisitShl(HShl* shl) { |
| 4771 | HandleShift(shl); |
| 4772 | } |
| 4773 | |
| 4774 | void InstructionCodeGeneratorARMVIXL::VisitShl(HShl* shl) { |
| 4775 | HandleShift(shl); |
| 4776 | } |
| 4777 | |
| 4778 | void LocationsBuilderARMVIXL::VisitShr(HShr* shr) { |
| 4779 | HandleShift(shr); |
| 4780 | } |
| 4781 | |
| 4782 | void InstructionCodeGeneratorARMVIXL::VisitShr(HShr* shr) { |
| 4783 | HandleShift(shr); |
| 4784 | } |
| 4785 | |
| 4786 | void LocationsBuilderARMVIXL::VisitUShr(HUShr* ushr) { |
| 4787 | HandleShift(ushr); |
| 4788 | } |
| 4789 | |
| 4790 | void InstructionCodeGeneratorARMVIXL::VisitUShr(HUShr* ushr) { |
| 4791 | HandleShift(ushr); |
| 4792 | } |
| 4793 | |
| 4794 | void LocationsBuilderARMVIXL::VisitNewInstance(HNewInstance* instruction) { |
| 4795 | LocationSummary* locations = |
| 4796 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
| 4797 | if (instruction->IsStringAlloc()) { |
| 4798 | locations->AddTemp(LocationFrom(kMethodRegister)); |
| 4799 | } else { |
| 4800 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4801 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4802 | } |
| 4803 | locations->SetOut(LocationFrom(r0)); |
| 4804 | } |
| 4805 | |
| 4806 | void InstructionCodeGeneratorARMVIXL::VisitNewInstance(HNewInstance* instruction) { |
| 4807 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 4808 | // of poisoning the reference. |
| 4809 | if (instruction->IsStringAlloc()) { |
| 4810 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 4811 | vixl32::Register temp = RegisterFrom(instruction->GetLocations()->GetTemp(0)); |
| 4812 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize); |
| 4813 | GetAssembler()->LoadFromOffset(kLoadWord, temp, tr, QUICK_ENTRY_POINT(pNewEmptyString)); |
| 4814 | GetAssembler()->LoadFromOffset(kLoadWord, lr, temp, code_offset.Int32Value()); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 4815 | // 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] | 4816 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 4817 | vixl32::k16BitT32InstructionSizeInBytes, |
| 4818 | CodeBufferCheckScope::kExactSize); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4819 | __ blx(lr); |
| 4820 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 4821 | } else { |
| 4822 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
Nicolas Geoffray | 0d3998b | 2017-01-12 15:35:12 +0000 | [diff] [blame] | 4823 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4824 | } |
| 4825 | } |
| 4826 | |
| 4827 | void LocationsBuilderARMVIXL::VisitNewArray(HNewArray* instruction) { |
| 4828 | LocationSummary* locations = |
| 4829 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
| 4830 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4831 | locations->SetOut(LocationFrom(r0)); |
Nicolas Geoffray | 8c7c4f1 | 2017-01-26 10:13:11 +0000 | [diff] [blame] | 4832 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 4833 | locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(1))); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4834 | } |
| 4835 | |
| 4836 | void InstructionCodeGeneratorARMVIXL::VisitNewArray(HNewArray* instruction) { |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4837 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 4838 | // of poisoning the reference. |
Artem Serov | 7b3672e | 2017-02-03 17:30:34 +0000 | [diff] [blame] | 4839 | QuickEntrypointEnum entrypoint = |
| 4840 | CodeGenerator::GetArrayAllocationEntrypoint(instruction->GetLoadClass()->GetClass()); |
| 4841 | codegen_->InvokeRuntime(entrypoint, instruction, instruction->GetDexPc()); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4842 | CheckEntrypointTypes<kQuickAllocArrayResolved, void*, mirror::Class*, int32_t>(); |
Artem Serov | 7b3672e | 2017-02-03 17:30:34 +0000 | [diff] [blame] | 4843 | DCHECK(!codegen_->IsLeafMethod()); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4844 | } |
| 4845 | |
| 4846 | void LocationsBuilderARMVIXL::VisitParameterValue(HParameterValue* instruction) { |
| 4847 | LocationSummary* locations = |
| 4848 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4849 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 4850 | if (location.IsStackSlot()) { |
| 4851 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 4852 | } else if (location.IsDoubleStackSlot()) { |
| 4853 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 4854 | } |
| 4855 | locations->SetOut(location); |
| 4856 | } |
| 4857 | |
| 4858 | void InstructionCodeGeneratorARMVIXL::VisitParameterValue( |
| 4859 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
| 4860 | // Nothing to do, the parameter is already at its location. |
| 4861 | } |
| 4862 | |
| 4863 | void LocationsBuilderARMVIXL::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 4864 | LocationSummary* locations = |
| 4865 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4866 | locations->SetOut(LocationFrom(kMethodRegister)); |
| 4867 | } |
| 4868 | |
| 4869 | void InstructionCodeGeneratorARMVIXL::VisitCurrentMethod( |
| 4870 | HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
| 4871 | // Nothing to do, the method is already at its location. |
| 4872 | } |
| 4873 | |
| 4874 | void LocationsBuilderARMVIXL::VisitNot(HNot* not_) { |
| 4875 | LocationSummary* locations = |
| 4876 | new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall); |
| 4877 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4878 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4879 | } |
| 4880 | |
| 4881 | void InstructionCodeGeneratorARMVIXL::VisitNot(HNot* not_) { |
| 4882 | LocationSummary* locations = not_->GetLocations(); |
| 4883 | Location out = locations->Out(); |
| 4884 | Location in = locations->InAt(0); |
| 4885 | switch (not_->GetResultType()) { |
| 4886 | case Primitive::kPrimInt: |
| 4887 | __ Mvn(OutputRegister(not_), InputRegisterAt(not_, 0)); |
| 4888 | break; |
| 4889 | |
| 4890 | case Primitive::kPrimLong: |
| 4891 | __ Mvn(LowRegisterFrom(out), LowRegisterFrom(in)); |
| 4892 | __ Mvn(HighRegisterFrom(out), HighRegisterFrom(in)); |
| 4893 | break; |
| 4894 | |
| 4895 | default: |
| 4896 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 4897 | } |
| 4898 | } |
| 4899 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 4900 | void LocationsBuilderARMVIXL::VisitBooleanNot(HBooleanNot* bool_not) { |
| 4901 | LocationSummary* locations = |
| 4902 | new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall); |
| 4903 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4904 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4905 | } |
| 4906 | |
| 4907 | void InstructionCodeGeneratorARMVIXL::VisitBooleanNot(HBooleanNot* bool_not) { |
| 4908 | __ Eor(OutputRegister(bool_not), InputRegister(bool_not), 1); |
| 4909 | } |
| 4910 | |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4911 | void LocationsBuilderARMVIXL::VisitCompare(HCompare* compare) { |
| 4912 | LocationSummary* locations = |
| 4913 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
| 4914 | switch (compare->InputAt(0)->GetType()) { |
| 4915 | case Primitive::kPrimBoolean: |
| 4916 | case Primitive::kPrimByte: |
| 4917 | case Primitive::kPrimShort: |
| 4918 | case Primitive::kPrimChar: |
| 4919 | case Primitive::kPrimInt: |
| 4920 | case Primitive::kPrimLong: { |
| 4921 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4922 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4923 | // Output overlaps because it is written before doing the low comparison. |
| 4924 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 4925 | break; |
| 4926 | } |
| 4927 | case Primitive::kPrimFloat: |
| 4928 | case Primitive::kPrimDouble: { |
| 4929 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4930 | locations->SetInAt(1, ArithmeticZeroOrFpuRegister(compare->InputAt(1))); |
| 4931 | locations->SetOut(Location::RequiresRegister()); |
| 4932 | break; |
| 4933 | } |
| 4934 | default: |
| 4935 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 4936 | } |
| 4937 | } |
| 4938 | |
| 4939 | void InstructionCodeGeneratorARMVIXL::VisitCompare(HCompare* compare) { |
| 4940 | LocationSummary* locations = compare->GetLocations(); |
| 4941 | vixl32::Register out = OutputRegister(compare); |
| 4942 | Location left = locations->InAt(0); |
| 4943 | Location right = locations->InAt(1); |
| 4944 | |
| 4945 | vixl32::Label less, greater, done; |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 4946 | vixl32::Label* final_label = codegen_->GetFinalLabel(compare, &done); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4947 | Primitive::Type type = compare->InputAt(0)->GetType(); |
| 4948 | vixl32::Condition less_cond = vixl32::Condition(kNone); |
| 4949 | switch (type) { |
| 4950 | case Primitive::kPrimBoolean: |
| 4951 | case Primitive::kPrimByte: |
| 4952 | case Primitive::kPrimShort: |
| 4953 | case Primitive::kPrimChar: |
| 4954 | case Primitive::kPrimInt: { |
| 4955 | // Emit move to `out` before the `Cmp`, as `Mov` might affect the status flags. |
| 4956 | __ Mov(out, 0); |
| 4957 | __ Cmp(RegisterFrom(left), RegisterFrom(right)); // Signed compare. |
| 4958 | less_cond = lt; |
| 4959 | break; |
| 4960 | } |
| 4961 | case Primitive::kPrimLong: { |
| 4962 | __ Cmp(HighRegisterFrom(left), HighRegisterFrom(right)); // Signed compare. |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 4963 | __ B(lt, &less, /* far_target */ false); |
| 4964 | __ B(gt, &greater, /* far_target */ false); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4965 | // Emit move to `out` before the last `Cmp`, as `Mov` might affect the status flags. |
| 4966 | __ Mov(out, 0); |
| 4967 | __ Cmp(LowRegisterFrom(left), LowRegisterFrom(right)); // Unsigned compare. |
| 4968 | less_cond = lo; |
| 4969 | break; |
| 4970 | } |
| 4971 | case Primitive::kPrimFloat: |
| 4972 | case Primitive::kPrimDouble: { |
| 4973 | __ Mov(out, 0); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 4974 | GenerateVcmp(compare, codegen_); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4975 | // To branch on the FP compare result we transfer FPSCR to APSR (encoded as PC in VMRS). |
| 4976 | __ Vmrs(RegisterOrAPSR_nzcv(kPcCode), FPSCR); |
| 4977 | less_cond = ARMFPCondition(kCondLT, compare->IsGtBias()); |
| 4978 | break; |
| 4979 | } |
| 4980 | default: |
| 4981 | LOG(FATAL) << "Unexpected compare type " << type; |
| 4982 | UNREACHABLE(); |
| 4983 | } |
| 4984 | |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 4985 | __ B(eq, final_label, /* far_target */ false); |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 4986 | __ B(less_cond, &less, /* far_target */ false); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4987 | |
| 4988 | __ Bind(&greater); |
| 4989 | __ Mov(out, 1); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 4990 | __ B(final_label); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4991 | |
| 4992 | __ Bind(&less); |
| 4993 | __ Mov(out, -1); |
| 4994 | |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 4995 | if (done.IsReferenced()) { |
| 4996 | __ Bind(&done); |
| 4997 | } |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4998 | } |
| 4999 | |
| 5000 | void LocationsBuilderARMVIXL::VisitPhi(HPhi* instruction) { |
| 5001 | LocationSummary* locations = |
| 5002 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 5003 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
| 5004 | locations->SetInAt(i, Location::Any()); |
| 5005 | } |
| 5006 | locations->SetOut(Location::Any()); |
| 5007 | } |
| 5008 | |
| 5009 | void InstructionCodeGeneratorARMVIXL::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
| 5010 | LOG(FATAL) << "Unreachable"; |
| 5011 | } |
| 5012 | |
| 5013 | void CodeGeneratorARMVIXL::GenerateMemoryBarrier(MemBarrierKind kind) { |
| 5014 | // TODO (ported from quick): revisit ARM barrier kinds. |
| 5015 | DmbOptions flavor = DmbOptions::ISH; // Quiet C++ warnings. |
| 5016 | switch (kind) { |
| 5017 | case MemBarrierKind::kAnyStore: |
| 5018 | case MemBarrierKind::kLoadAny: |
| 5019 | case MemBarrierKind::kAnyAny: { |
| 5020 | flavor = DmbOptions::ISH; |
| 5021 | break; |
| 5022 | } |
| 5023 | case MemBarrierKind::kStoreStore: { |
| 5024 | flavor = DmbOptions::ISHST; |
| 5025 | break; |
| 5026 | } |
| 5027 | default: |
| 5028 | LOG(FATAL) << "Unexpected memory barrier " << kind; |
| 5029 | } |
| 5030 | __ Dmb(flavor); |
| 5031 | } |
| 5032 | |
| 5033 | void InstructionCodeGeneratorARMVIXL::GenerateWideAtomicLoad(vixl32::Register addr, |
| 5034 | uint32_t offset, |
| 5035 | vixl32::Register out_lo, |
| 5036 | vixl32::Register out_hi) { |
| 5037 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 5038 | if (offset != 0) { |
| 5039 | vixl32::Register temp = temps.Acquire(); |
| 5040 | __ Add(temp, addr, offset); |
| 5041 | addr = temp; |
| 5042 | } |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 5043 | __ Ldrexd(out_lo, out_hi, MemOperand(addr)); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5044 | } |
| 5045 | |
| 5046 | void InstructionCodeGeneratorARMVIXL::GenerateWideAtomicStore(vixl32::Register addr, |
| 5047 | uint32_t offset, |
| 5048 | vixl32::Register value_lo, |
| 5049 | vixl32::Register value_hi, |
| 5050 | vixl32::Register temp1, |
| 5051 | vixl32::Register temp2, |
| 5052 | HInstruction* instruction) { |
| 5053 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 5054 | vixl32::Label fail; |
| 5055 | if (offset != 0) { |
| 5056 | vixl32::Register temp = temps.Acquire(); |
| 5057 | __ Add(temp, addr, offset); |
| 5058 | addr = temp; |
| 5059 | } |
| 5060 | __ Bind(&fail); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 5061 | { |
| 5062 | // Ensure the pc position is recorded immediately after the `ldrexd` instruction. |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 5063 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 5064 | vixl32::kMaxInstructionSizeInBytes, |
| 5065 | CodeBufferCheckScope::kMaximumSize); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 5066 | // We need a load followed by store. (The address used in a STREX instruction must |
| 5067 | // be the same as the address in the most recently executed LDREX instruction.) |
| 5068 | __ ldrexd(temp1, temp2, MemOperand(addr)); |
| 5069 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5070 | } |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 5071 | __ Strexd(temp1, value_lo, value_hi, MemOperand(addr)); |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 5072 | __ CompareAndBranchIfNonZero(temp1, &fail); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5073 | } |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5074 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5075 | void LocationsBuilderARMVIXL::HandleFieldSet( |
| 5076 | HInstruction* instruction, const FieldInfo& field_info) { |
| 5077 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 5078 | |
| 5079 | LocationSummary* locations = |
| 5080 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 5081 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5082 | |
| 5083 | Primitive::Type field_type = field_info.GetFieldType(); |
| 5084 | if (Primitive::IsFloatingPointType(field_type)) { |
| 5085 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 5086 | } else { |
| 5087 | locations->SetInAt(1, Location::RequiresRegister()); |
| 5088 | } |
| 5089 | |
| 5090 | bool is_wide = field_type == Primitive::kPrimLong || field_type == Primitive::kPrimDouble; |
| 5091 | bool generate_volatile = field_info.IsVolatile() |
| 5092 | && is_wide |
| 5093 | && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
| 5094 | bool needs_write_barrier = |
| 5095 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
| 5096 | // Temporary registers for the write barrier. |
| 5097 | // TODO: consider renaming StoreNeedsWriteBarrier to StoreNeedsGCMark. |
| 5098 | if (needs_write_barrier) { |
| 5099 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for reference poisoning too. |
| 5100 | locations->AddTemp(Location::RequiresRegister()); |
| 5101 | } else if (generate_volatile) { |
| 5102 | // ARM encoding have some additional constraints for ldrexd/strexd: |
| 5103 | // - registers need to be consecutive |
| 5104 | // - the first register should be even but not R14. |
| 5105 | // We don't test for ARM yet, and the assertion makes sure that we |
| 5106 | // revisit this if we ever enable ARM encoding. |
| 5107 | DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet()); |
| 5108 | |
| 5109 | locations->AddTemp(Location::RequiresRegister()); |
| 5110 | locations->AddTemp(Location::RequiresRegister()); |
| 5111 | if (field_type == Primitive::kPrimDouble) { |
| 5112 | // For doubles we need two more registers to copy the value. |
| 5113 | locations->AddTemp(LocationFrom(r2)); |
| 5114 | locations->AddTemp(LocationFrom(r3)); |
| 5115 | } |
| 5116 | } |
| 5117 | } |
| 5118 | |
| 5119 | void InstructionCodeGeneratorARMVIXL::HandleFieldSet(HInstruction* instruction, |
| 5120 | const FieldInfo& field_info, |
| 5121 | bool value_can_be_null) { |
| 5122 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 5123 | |
| 5124 | LocationSummary* locations = instruction->GetLocations(); |
| 5125 | vixl32::Register base = InputRegisterAt(instruction, 0); |
| 5126 | Location value = locations->InAt(1); |
| 5127 | |
| 5128 | bool is_volatile = field_info.IsVolatile(); |
| 5129 | bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
| 5130 | Primitive::Type field_type = field_info.GetFieldType(); |
| 5131 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 5132 | bool needs_write_barrier = |
| 5133 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
| 5134 | |
| 5135 | if (is_volatile) { |
| 5136 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
| 5137 | } |
| 5138 | |
| 5139 | switch (field_type) { |
| 5140 | case Primitive::kPrimBoolean: |
| 5141 | case Primitive::kPrimByte: { |
| 5142 | GetAssembler()->StoreToOffset(kStoreByte, RegisterFrom(value), base, offset); |
| 5143 | break; |
| 5144 | } |
| 5145 | |
| 5146 | case Primitive::kPrimShort: |
| 5147 | case Primitive::kPrimChar: { |
| 5148 | GetAssembler()->StoreToOffset(kStoreHalfword, RegisterFrom(value), base, offset); |
| 5149 | break; |
| 5150 | } |
| 5151 | |
| 5152 | case Primitive::kPrimInt: |
| 5153 | case Primitive::kPrimNot: { |
| 5154 | if (kPoisonHeapReferences && needs_write_barrier) { |
| 5155 | // Note that in the case where `value` is a null reference, |
| 5156 | // we do not enter this block, as a null reference does not |
| 5157 | // need poisoning. |
| 5158 | DCHECK_EQ(field_type, Primitive::kPrimNot); |
| 5159 | vixl32::Register temp = RegisterFrom(locations->GetTemp(0)); |
| 5160 | __ Mov(temp, RegisterFrom(value)); |
| 5161 | GetAssembler()->PoisonHeapReference(temp); |
| 5162 | GetAssembler()->StoreToOffset(kStoreWord, temp, base, offset); |
| 5163 | } else { |
| 5164 | GetAssembler()->StoreToOffset(kStoreWord, RegisterFrom(value), base, offset); |
| 5165 | } |
| 5166 | break; |
| 5167 | } |
| 5168 | |
| 5169 | case Primitive::kPrimLong: { |
| 5170 | if (is_volatile && !atomic_ldrd_strd) { |
| 5171 | GenerateWideAtomicStore(base, |
| 5172 | offset, |
| 5173 | LowRegisterFrom(value), |
| 5174 | HighRegisterFrom(value), |
| 5175 | RegisterFrom(locations->GetTemp(0)), |
| 5176 | RegisterFrom(locations->GetTemp(1)), |
| 5177 | instruction); |
| 5178 | } else { |
| 5179 | GetAssembler()->StoreToOffset(kStoreWordPair, LowRegisterFrom(value), base, offset); |
| 5180 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5181 | } |
| 5182 | break; |
| 5183 | } |
| 5184 | |
| 5185 | case Primitive::kPrimFloat: { |
| 5186 | GetAssembler()->StoreSToOffset(SRegisterFrom(value), base, offset); |
| 5187 | break; |
| 5188 | } |
| 5189 | |
| 5190 | case Primitive::kPrimDouble: { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5191 | vixl32::DRegister value_reg = DRegisterFrom(value); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5192 | if (is_volatile && !atomic_ldrd_strd) { |
| 5193 | vixl32::Register value_reg_lo = RegisterFrom(locations->GetTemp(0)); |
| 5194 | vixl32::Register value_reg_hi = RegisterFrom(locations->GetTemp(1)); |
| 5195 | |
| 5196 | __ Vmov(value_reg_lo, value_reg_hi, value_reg); |
| 5197 | |
| 5198 | GenerateWideAtomicStore(base, |
| 5199 | offset, |
| 5200 | value_reg_lo, |
| 5201 | value_reg_hi, |
| 5202 | RegisterFrom(locations->GetTemp(2)), |
| 5203 | RegisterFrom(locations->GetTemp(3)), |
| 5204 | instruction); |
| 5205 | } else { |
| 5206 | GetAssembler()->StoreDToOffset(value_reg, base, offset); |
| 5207 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5208 | } |
| 5209 | break; |
| 5210 | } |
| 5211 | |
| 5212 | case Primitive::kPrimVoid: |
| 5213 | LOG(FATAL) << "Unreachable type " << field_type; |
| 5214 | UNREACHABLE(); |
| 5215 | } |
| 5216 | |
| 5217 | // Longs and doubles are handled in the switch. |
| 5218 | if (field_type != Primitive::kPrimLong && field_type != Primitive::kPrimDouble) { |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 5219 | // TODO(VIXL): Here and for other calls to `MaybeRecordImplicitNullCheck` in this method, we |
| 5220 | // should use a scope and the assembler to emit the store instruction to guarantee that we |
| 5221 | // record the pc at the correct position. But the `Assembler` does not automatically handle |
| 5222 | // unencodable offsets. Practically, everything is fine because the helper and VIXL, at the time |
| 5223 | // of writing, do generate the store instruction last. |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5224 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5225 | } |
| 5226 | |
| 5227 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 5228 | vixl32::Register temp = RegisterFrom(locations->GetTemp(0)); |
| 5229 | vixl32::Register card = RegisterFrom(locations->GetTemp(1)); |
| 5230 | codegen_->MarkGCCard(temp, card, base, RegisterFrom(value), value_can_be_null); |
| 5231 | } |
| 5232 | |
| 5233 | if (is_volatile) { |
| 5234 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
| 5235 | } |
| 5236 | } |
| 5237 | |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5238 | void LocationsBuilderARMVIXL::HandleFieldGet(HInstruction* instruction, |
| 5239 | const FieldInfo& field_info) { |
| 5240 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 5241 | |
| 5242 | bool object_field_get_with_read_barrier = |
| 5243 | kEmitCompilerReadBarrier && (field_info.GetFieldType() == Primitive::kPrimNot); |
| 5244 | LocationSummary* locations = |
| 5245 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 5246 | object_field_get_with_read_barrier ? |
| 5247 | LocationSummary::kCallOnSlowPath : |
| 5248 | LocationSummary::kNoCall); |
| 5249 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| 5250 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| 5251 | } |
| 5252 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5253 | |
| 5254 | bool volatile_for_double = field_info.IsVolatile() |
| 5255 | && (field_info.GetFieldType() == Primitive::kPrimDouble) |
| 5256 | && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
| 5257 | // The output overlaps in case of volatile long: we don't want the |
| 5258 | // code generated by GenerateWideAtomicLoad to overwrite the |
| 5259 | // object's location. Likewise, in the case of an object field get |
| 5260 | // with read barriers enabled, we do not want the load to overwrite |
| 5261 | // the object's location, as we need it to emit the read barrier. |
| 5262 | bool overlap = (field_info.IsVolatile() && (field_info.GetFieldType() == Primitive::kPrimLong)) || |
| 5263 | object_field_get_with_read_barrier; |
| 5264 | |
| 5265 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 5266 | locations->SetOut(Location::RequiresFpuRegister()); |
| 5267 | } else { |
| 5268 | locations->SetOut(Location::RequiresRegister(), |
| 5269 | (overlap ? Location::kOutputOverlap : Location::kNoOutputOverlap)); |
| 5270 | } |
| 5271 | if (volatile_for_double) { |
| 5272 | // ARM encoding have some additional constraints for ldrexd/strexd: |
| 5273 | // - registers need to be consecutive |
| 5274 | // - the first register should be even but not R14. |
| 5275 | // We don't test for ARM yet, and the assertion makes sure that we |
| 5276 | // revisit this if we ever enable ARM encoding. |
| 5277 | DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet()); |
| 5278 | locations->AddTemp(Location::RequiresRegister()); |
| 5279 | locations->AddTemp(Location::RequiresRegister()); |
| 5280 | } else if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| 5281 | // We need a temporary register for the read barrier marking slow |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 5282 | // path in CodeGeneratorARMVIXL::GenerateFieldLoadWithBakerReadBarrier. |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5283 | locations->AddTemp(Location::RequiresRegister()); |
| 5284 | } |
| 5285 | } |
| 5286 | |
| 5287 | Location LocationsBuilderARMVIXL::ArithmeticZeroOrFpuRegister(HInstruction* input) { |
| 5288 | DCHECK(Primitive::IsFloatingPointType(input->GetType())) << input->GetType(); |
| 5289 | if ((input->IsFloatConstant() && (input->AsFloatConstant()->IsArithmeticZero())) || |
| 5290 | (input->IsDoubleConstant() && (input->AsDoubleConstant()->IsArithmeticZero()))) { |
| 5291 | return Location::ConstantLocation(input->AsConstant()); |
| 5292 | } else { |
| 5293 | return Location::RequiresFpuRegister(); |
| 5294 | } |
| 5295 | } |
| 5296 | |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5297 | Location LocationsBuilderARMVIXL::ArmEncodableConstantOrRegister(HInstruction* constant, |
| 5298 | Opcode opcode) { |
| 5299 | DCHECK(!Primitive::IsFloatingPointType(constant->GetType())); |
| 5300 | if (constant->IsConstant() && |
| 5301 | CanEncodeConstantAsImmediate(constant->AsConstant(), opcode)) { |
| 5302 | return Location::ConstantLocation(constant->AsConstant()); |
| 5303 | } |
| 5304 | return Location::RequiresRegister(); |
| 5305 | } |
| 5306 | |
| 5307 | bool LocationsBuilderARMVIXL::CanEncodeConstantAsImmediate(HConstant* input_cst, |
| 5308 | Opcode opcode) { |
| 5309 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(input_cst)); |
| 5310 | if (Primitive::Is64BitType(input_cst->GetType())) { |
| 5311 | Opcode high_opcode = opcode; |
| 5312 | SetCc low_set_cc = kCcDontCare; |
| 5313 | switch (opcode) { |
| 5314 | case SUB: |
| 5315 | // Flip the operation to an ADD. |
| 5316 | value = -value; |
| 5317 | opcode = ADD; |
| 5318 | FALLTHROUGH_INTENDED; |
| 5319 | case ADD: |
| 5320 | if (Low32Bits(value) == 0u) { |
| 5321 | return CanEncodeConstantAsImmediate(High32Bits(value), opcode, kCcDontCare); |
| 5322 | } |
| 5323 | high_opcode = ADC; |
| 5324 | low_set_cc = kCcSet; |
| 5325 | break; |
| 5326 | default: |
| 5327 | break; |
| 5328 | } |
| 5329 | return CanEncodeConstantAsImmediate(Low32Bits(value), opcode, low_set_cc) && |
| 5330 | CanEncodeConstantAsImmediate(High32Bits(value), high_opcode, kCcDontCare); |
| 5331 | } else { |
| 5332 | return CanEncodeConstantAsImmediate(Low32Bits(value), opcode); |
| 5333 | } |
| 5334 | } |
| 5335 | |
| 5336 | // TODO(VIXL): Replace art::arm::SetCc` with `vixl32::FlagsUpdate after flags set optimization |
| 5337 | // enabled. |
| 5338 | bool LocationsBuilderARMVIXL::CanEncodeConstantAsImmediate(uint32_t value, |
| 5339 | Opcode opcode, |
| 5340 | SetCc set_cc) { |
| 5341 | ArmVIXLAssembler* assembler = codegen_->GetAssembler(); |
| 5342 | if (assembler->ShifterOperandCanHold(opcode, value, set_cc)) { |
| 5343 | return true; |
| 5344 | } |
| 5345 | Opcode neg_opcode = kNoOperand; |
Anton Kirilov | effd5bf | 2017-02-28 16:59:15 +0000 | [diff] [blame] | 5346 | uint32_t neg_value = 0; |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5347 | switch (opcode) { |
Anton Kirilov | effd5bf | 2017-02-28 16:59:15 +0000 | [diff] [blame] | 5348 | case AND: neg_opcode = BIC; neg_value = ~value; break; |
| 5349 | case ORR: neg_opcode = ORN; neg_value = ~value; break; |
| 5350 | case ADD: neg_opcode = SUB; neg_value = -value; break; |
| 5351 | case ADC: neg_opcode = SBC; neg_value = ~value; break; |
| 5352 | case SUB: neg_opcode = ADD; neg_value = -value; break; |
| 5353 | case SBC: neg_opcode = ADC; neg_value = ~value; break; |
| 5354 | case MOV: neg_opcode = MVN; neg_value = ~value; break; |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5355 | default: |
| 5356 | return false; |
| 5357 | } |
Anton Kirilov | effd5bf | 2017-02-28 16:59:15 +0000 | [diff] [blame] | 5358 | |
| 5359 | if (assembler->ShifterOperandCanHold(neg_opcode, neg_value, set_cc)) { |
| 5360 | return true; |
| 5361 | } |
| 5362 | |
| 5363 | return opcode == AND && IsPowerOfTwo(value + 1); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5364 | } |
| 5365 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5366 | void InstructionCodeGeneratorARMVIXL::HandleFieldGet(HInstruction* instruction, |
| 5367 | const FieldInfo& field_info) { |
| 5368 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 5369 | |
| 5370 | LocationSummary* locations = instruction->GetLocations(); |
| 5371 | vixl32::Register base = InputRegisterAt(instruction, 0); |
| 5372 | Location out = locations->Out(); |
| 5373 | bool is_volatile = field_info.IsVolatile(); |
| 5374 | bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
| 5375 | Primitive::Type field_type = field_info.GetFieldType(); |
| 5376 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 5377 | |
| 5378 | switch (field_type) { |
| 5379 | case Primitive::kPrimBoolean: |
| 5380 | GetAssembler()->LoadFromOffset(kLoadUnsignedByte, RegisterFrom(out), base, offset); |
| 5381 | break; |
| 5382 | |
| 5383 | case Primitive::kPrimByte: |
| 5384 | GetAssembler()->LoadFromOffset(kLoadSignedByte, RegisterFrom(out), base, offset); |
| 5385 | break; |
| 5386 | |
| 5387 | case Primitive::kPrimShort: |
| 5388 | GetAssembler()->LoadFromOffset(kLoadSignedHalfword, RegisterFrom(out), base, offset); |
| 5389 | break; |
| 5390 | |
| 5391 | case Primitive::kPrimChar: |
| 5392 | GetAssembler()->LoadFromOffset(kLoadUnsignedHalfword, RegisterFrom(out), base, offset); |
| 5393 | break; |
| 5394 | |
| 5395 | case Primitive::kPrimInt: |
| 5396 | GetAssembler()->LoadFromOffset(kLoadWord, RegisterFrom(out), base, offset); |
| 5397 | break; |
| 5398 | |
| 5399 | case Primitive::kPrimNot: { |
| 5400 | // /* HeapReference<Object> */ out = *(base + offset) |
| 5401 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 5402 | Location temp_loc = locations->GetTemp(0); |
| 5403 | // Note that a potential implicit null check is handled in this |
| 5404 | // CodeGeneratorARMVIXL::GenerateFieldLoadWithBakerReadBarrier call. |
| 5405 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 5406 | instruction, out, base, offset, temp_loc, /* needs_null_check */ true); |
| 5407 | if (is_volatile) { |
| 5408 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 5409 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5410 | } else { |
| 5411 | GetAssembler()->LoadFromOffset(kLoadWord, RegisterFrom(out), base, offset); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5412 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5413 | if (is_volatile) { |
| 5414 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 5415 | } |
| 5416 | // If read barriers are enabled, emit read barriers other than |
| 5417 | // Baker's using a slow path (and also unpoison the loaded |
| 5418 | // reference, if heap poisoning is enabled). |
| 5419 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, locations->InAt(0), offset); |
| 5420 | } |
| 5421 | break; |
| 5422 | } |
| 5423 | |
| 5424 | case Primitive::kPrimLong: |
| 5425 | if (is_volatile && !atomic_ldrd_strd) { |
| 5426 | GenerateWideAtomicLoad(base, offset, LowRegisterFrom(out), HighRegisterFrom(out)); |
| 5427 | } else { |
| 5428 | GetAssembler()->LoadFromOffset(kLoadWordPair, LowRegisterFrom(out), base, offset); |
| 5429 | } |
| 5430 | break; |
| 5431 | |
| 5432 | case Primitive::kPrimFloat: |
| 5433 | GetAssembler()->LoadSFromOffset(SRegisterFrom(out), base, offset); |
| 5434 | break; |
| 5435 | |
| 5436 | case Primitive::kPrimDouble: { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5437 | vixl32::DRegister out_dreg = DRegisterFrom(out); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5438 | if (is_volatile && !atomic_ldrd_strd) { |
| 5439 | vixl32::Register lo = RegisterFrom(locations->GetTemp(0)); |
| 5440 | vixl32::Register hi = RegisterFrom(locations->GetTemp(1)); |
| 5441 | GenerateWideAtomicLoad(base, offset, lo, hi); |
| 5442 | // TODO(VIXL): Do we need to be immediately after the ldrexd instruction? If so we need a |
| 5443 | // scope. |
| 5444 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5445 | __ Vmov(out_dreg, lo, hi); |
| 5446 | } else { |
| 5447 | GetAssembler()->LoadDFromOffset(out_dreg, base, offset); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5448 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5449 | } |
| 5450 | break; |
| 5451 | } |
| 5452 | |
| 5453 | case Primitive::kPrimVoid: |
| 5454 | LOG(FATAL) << "Unreachable type " << field_type; |
| 5455 | UNREACHABLE(); |
| 5456 | } |
| 5457 | |
| 5458 | if (field_type == Primitive::kPrimNot || field_type == Primitive::kPrimDouble) { |
| 5459 | // Potential implicit null checks, in the case of reference or |
| 5460 | // double fields, are handled in the previous switch statement. |
| 5461 | } else { |
| 5462 | // 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] | 5463 | // TODO(VIXL): Here and for other calls to `MaybeRecordImplicitNullCheck` in this method, we |
| 5464 | // should use a scope and the assembler to emit the load instruction to guarantee that we |
| 5465 | // record the pc at the correct position. But the `Assembler` does not automatically handle |
| 5466 | // unencodable offsets. Practically, everything is fine because the helper and VIXL, at the time |
| 5467 | // of writing, do generate the store instruction last. |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5468 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5469 | } |
| 5470 | |
| 5471 | if (is_volatile) { |
| 5472 | if (field_type == Primitive::kPrimNot) { |
| 5473 | // Memory barriers, in the case of references, are also handled |
| 5474 | // in the previous switch statement. |
| 5475 | } else { |
| 5476 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 5477 | } |
| 5478 | } |
| 5479 | } |
| 5480 | |
| 5481 | void LocationsBuilderARMVIXL::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 5482 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 5483 | } |
| 5484 | |
| 5485 | void InstructionCodeGeneratorARMVIXL::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 5486 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
| 5487 | } |
| 5488 | |
| 5489 | void LocationsBuilderARMVIXL::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 5490 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5491 | } |
| 5492 | |
| 5493 | void InstructionCodeGeneratorARMVIXL::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 5494 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5495 | } |
| 5496 | |
| 5497 | void LocationsBuilderARMVIXL::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 5498 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5499 | } |
| 5500 | |
| 5501 | void InstructionCodeGeneratorARMVIXL::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 5502 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5503 | } |
| 5504 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5505 | void LocationsBuilderARMVIXL::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 5506 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 5507 | } |
| 5508 | |
| 5509 | void InstructionCodeGeneratorARMVIXL::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 5510 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
| 5511 | } |
| 5512 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 5513 | void LocationsBuilderARMVIXL::VisitUnresolvedInstanceFieldGet( |
| 5514 | HUnresolvedInstanceFieldGet* instruction) { |
| 5515 | FieldAccessCallingConventionARMVIXL calling_convention; |
| 5516 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5517 | instruction, instruction->GetFieldType(), calling_convention); |
| 5518 | } |
| 5519 | |
| 5520 | void InstructionCodeGeneratorARMVIXL::VisitUnresolvedInstanceFieldGet( |
| 5521 | HUnresolvedInstanceFieldGet* instruction) { |
| 5522 | FieldAccessCallingConventionARMVIXL calling_convention; |
| 5523 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5524 | instruction->GetFieldType(), |
| 5525 | instruction->GetFieldIndex(), |
| 5526 | instruction->GetDexPc(), |
| 5527 | calling_convention); |
| 5528 | } |
| 5529 | |
| 5530 | void LocationsBuilderARMVIXL::VisitUnresolvedInstanceFieldSet( |
| 5531 | HUnresolvedInstanceFieldSet* instruction) { |
| 5532 | FieldAccessCallingConventionARMVIXL calling_convention; |
| 5533 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5534 | instruction, instruction->GetFieldType(), calling_convention); |
| 5535 | } |
| 5536 | |
| 5537 | void InstructionCodeGeneratorARMVIXL::VisitUnresolvedInstanceFieldSet( |
| 5538 | HUnresolvedInstanceFieldSet* instruction) { |
| 5539 | FieldAccessCallingConventionARMVIXL calling_convention; |
| 5540 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5541 | instruction->GetFieldType(), |
| 5542 | instruction->GetFieldIndex(), |
| 5543 | instruction->GetDexPc(), |
| 5544 | calling_convention); |
| 5545 | } |
| 5546 | |
| 5547 | void LocationsBuilderARMVIXL::VisitUnresolvedStaticFieldGet( |
| 5548 | HUnresolvedStaticFieldGet* instruction) { |
| 5549 | FieldAccessCallingConventionARMVIXL calling_convention; |
| 5550 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5551 | instruction, instruction->GetFieldType(), calling_convention); |
| 5552 | } |
| 5553 | |
| 5554 | void InstructionCodeGeneratorARMVIXL::VisitUnresolvedStaticFieldGet( |
| 5555 | HUnresolvedStaticFieldGet* instruction) { |
| 5556 | FieldAccessCallingConventionARMVIXL calling_convention; |
| 5557 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5558 | instruction->GetFieldType(), |
| 5559 | instruction->GetFieldIndex(), |
| 5560 | instruction->GetDexPc(), |
| 5561 | calling_convention); |
| 5562 | } |
| 5563 | |
| 5564 | void LocationsBuilderARMVIXL::VisitUnresolvedStaticFieldSet( |
| 5565 | HUnresolvedStaticFieldSet* instruction) { |
| 5566 | FieldAccessCallingConventionARMVIXL calling_convention; |
| 5567 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5568 | instruction, instruction->GetFieldType(), calling_convention); |
| 5569 | } |
| 5570 | |
| 5571 | void InstructionCodeGeneratorARMVIXL::VisitUnresolvedStaticFieldSet( |
| 5572 | HUnresolvedStaticFieldSet* instruction) { |
| 5573 | FieldAccessCallingConventionARMVIXL calling_convention; |
| 5574 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5575 | instruction->GetFieldType(), |
| 5576 | instruction->GetFieldIndex(), |
| 5577 | instruction->GetDexPc(), |
| 5578 | calling_convention); |
| 5579 | } |
| 5580 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5581 | void LocationsBuilderARMVIXL::VisitNullCheck(HNullCheck* instruction) { |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 5582 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5583 | locations->SetInAt(0, Location::RequiresRegister()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5584 | } |
| 5585 | |
| 5586 | void CodeGeneratorARMVIXL::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 5587 | if (CanMoveNullCheckToUser(instruction)) { |
| 5588 | return; |
| 5589 | } |
| 5590 | |
| 5591 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 5592 | // Ensure the pc position is recorded immediately after the `ldr` instruction. |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 5593 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 5594 | vixl32::kMaxInstructionSizeInBytes, |
| 5595 | CodeBufferCheckScope::kMaximumSize); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5596 | __ ldr(temps.Acquire(), MemOperand(InputRegisterAt(instruction, 0))); |
| 5597 | RecordPcInfo(instruction, instruction->GetDexPc()); |
| 5598 | } |
| 5599 | |
| 5600 | void CodeGeneratorARMVIXL::GenerateExplicitNullCheck(HNullCheck* instruction) { |
| 5601 | NullCheckSlowPathARMVIXL* slow_path = |
| 5602 | new (GetGraph()->GetArena()) NullCheckSlowPathARMVIXL(instruction); |
| 5603 | AddSlowPath(slow_path); |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 5604 | __ CompareAndBranchIfZero(InputRegisterAt(instruction, 0), slow_path->GetEntryLabel()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5605 | } |
| 5606 | |
| 5607 | void InstructionCodeGeneratorARMVIXL::VisitNullCheck(HNullCheck* instruction) { |
| 5608 | codegen_->GenerateNullCheck(instruction); |
| 5609 | } |
| 5610 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5611 | static LoadOperandType GetLoadOperandType(Primitive::Type type) { |
| 5612 | switch (type) { |
| 5613 | case Primitive::kPrimNot: |
| 5614 | return kLoadWord; |
| 5615 | case Primitive::kPrimBoolean: |
| 5616 | return kLoadUnsignedByte; |
| 5617 | case Primitive::kPrimByte: |
| 5618 | return kLoadSignedByte; |
| 5619 | case Primitive::kPrimChar: |
| 5620 | return kLoadUnsignedHalfword; |
| 5621 | case Primitive::kPrimShort: |
| 5622 | return kLoadSignedHalfword; |
| 5623 | case Primitive::kPrimInt: |
| 5624 | return kLoadWord; |
| 5625 | case Primitive::kPrimLong: |
| 5626 | return kLoadWordPair; |
| 5627 | case Primitive::kPrimFloat: |
| 5628 | return kLoadSWord; |
| 5629 | case Primitive::kPrimDouble: |
| 5630 | return kLoadDWord; |
| 5631 | default: |
| 5632 | LOG(FATAL) << "Unreachable type " << type; |
| 5633 | UNREACHABLE(); |
| 5634 | } |
| 5635 | } |
| 5636 | |
| 5637 | static StoreOperandType GetStoreOperandType(Primitive::Type type) { |
| 5638 | switch (type) { |
| 5639 | case Primitive::kPrimNot: |
| 5640 | return kStoreWord; |
| 5641 | case Primitive::kPrimBoolean: |
| 5642 | case Primitive::kPrimByte: |
| 5643 | return kStoreByte; |
| 5644 | case Primitive::kPrimChar: |
| 5645 | case Primitive::kPrimShort: |
| 5646 | return kStoreHalfword; |
| 5647 | case Primitive::kPrimInt: |
| 5648 | return kStoreWord; |
| 5649 | case Primitive::kPrimLong: |
| 5650 | return kStoreWordPair; |
| 5651 | case Primitive::kPrimFloat: |
| 5652 | return kStoreSWord; |
| 5653 | case Primitive::kPrimDouble: |
| 5654 | return kStoreDWord; |
| 5655 | default: |
| 5656 | LOG(FATAL) << "Unreachable type " << type; |
| 5657 | UNREACHABLE(); |
| 5658 | } |
| 5659 | } |
| 5660 | |
| 5661 | void CodeGeneratorARMVIXL::LoadFromShiftedRegOffset(Primitive::Type type, |
| 5662 | Location out_loc, |
| 5663 | vixl32::Register base, |
| 5664 | vixl32::Register reg_index, |
| 5665 | vixl32::Condition cond) { |
| 5666 | uint32_t shift_count = Primitive::ComponentSizeShift(type); |
| 5667 | MemOperand mem_address(base, reg_index, vixl32::LSL, shift_count); |
| 5668 | |
| 5669 | switch (type) { |
| 5670 | case Primitive::kPrimByte: |
| 5671 | __ Ldrsb(cond, RegisterFrom(out_loc), mem_address); |
| 5672 | break; |
| 5673 | case Primitive::kPrimBoolean: |
| 5674 | __ Ldrb(cond, RegisterFrom(out_loc), mem_address); |
| 5675 | break; |
| 5676 | case Primitive::kPrimShort: |
| 5677 | __ Ldrsh(cond, RegisterFrom(out_loc), mem_address); |
| 5678 | break; |
| 5679 | case Primitive::kPrimChar: |
| 5680 | __ Ldrh(cond, RegisterFrom(out_loc), mem_address); |
| 5681 | break; |
| 5682 | case Primitive::kPrimNot: |
| 5683 | case Primitive::kPrimInt: |
| 5684 | __ Ldr(cond, RegisterFrom(out_loc), mem_address); |
| 5685 | break; |
| 5686 | // T32 doesn't support LoadFromShiftedRegOffset mem address mode for these types. |
| 5687 | case Primitive::kPrimLong: |
| 5688 | case Primitive::kPrimFloat: |
| 5689 | case Primitive::kPrimDouble: |
| 5690 | default: |
| 5691 | LOG(FATAL) << "Unreachable type " << type; |
| 5692 | UNREACHABLE(); |
| 5693 | } |
| 5694 | } |
| 5695 | |
| 5696 | void CodeGeneratorARMVIXL::StoreToShiftedRegOffset(Primitive::Type type, |
| 5697 | Location loc, |
| 5698 | vixl32::Register base, |
| 5699 | vixl32::Register reg_index, |
| 5700 | vixl32::Condition cond) { |
| 5701 | uint32_t shift_count = Primitive::ComponentSizeShift(type); |
| 5702 | MemOperand mem_address(base, reg_index, vixl32::LSL, shift_count); |
| 5703 | |
| 5704 | switch (type) { |
| 5705 | case Primitive::kPrimByte: |
| 5706 | case Primitive::kPrimBoolean: |
| 5707 | __ Strb(cond, RegisterFrom(loc), mem_address); |
| 5708 | break; |
| 5709 | case Primitive::kPrimShort: |
| 5710 | case Primitive::kPrimChar: |
| 5711 | __ Strh(cond, RegisterFrom(loc), mem_address); |
| 5712 | break; |
| 5713 | case Primitive::kPrimNot: |
| 5714 | case Primitive::kPrimInt: |
| 5715 | __ Str(cond, RegisterFrom(loc), mem_address); |
| 5716 | break; |
| 5717 | // T32 doesn't support StoreToShiftedRegOffset mem address mode for these types. |
| 5718 | case Primitive::kPrimLong: |
| 5719 | case Primitive::kPrimFloat: |
| 5720 | case Primitive::kPrimDouble: |
| 5721 | default: |
| 5722 | LOG(FATAL) << "Unreachable type " << type; |
| 5723 | UNREACHABLE(); |
| 5724 | } |
| 5725 | } |
| 5726 | |
| 5727 | void LocationsBuilderARMVIXL::VisitArrayGet(HArrayGet* instruction) { |
| 5728 | bool object_array_get_with_read_barrier = |
| 5729 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
| 5730 | LocationSummary* locations = |
| 5731 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 5732 | object_array_get_with_read_barrier ? |
| 5733 | LocationSummary::kCallOnSlowPath : |
| 5734 | LocationSummary::kNoCall); |
| 5735 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 5736 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5737 | } |
| 5738 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5739 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 5740 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 5741 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 5742 | } else { |
| 5743 | // The output overlaps in the case of an object array get with |
| 5744 | // read barriers enabled: we do not want the move to overwrite the |
| 5745 | // array's location, as we need it to emit the read barrier. |
| 5746 | locations->SetOut( |
| 5747 | Location::RequiresRegister(), |
| 5748 | object_array_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
| 5749 | } |
| 5750 | // We need a temporary register for the read barrier marking slow |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 5751 | // path in CodeGeneratorARMVIXL::GenerateArrayLoadWithBakerReadBarrier. |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5752 | // Also need for String compression feature. |
| 5753 | if ((object_array_get_with_read_barrier && kUseBakerReadBarrier) |
| 5754 | || (mirror::kUseStringCompression && instruction->IsStringCharAt())) { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 5755 | locations->AddTemp(Location::RequiresRegister()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5756 | } |
| 5757 | } |
| 5758 | |
| 5759 | void InstructionCodeGeneratorARMVIXL::VisitArrayGet(HArrayGet* instruction) { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5760 | LocationSummary* locations = instruction->GetLocations(); |
| 5761 | Location obj_loc = locations->InAt(0); |
| 5762 | vixl32::Register obj = InputRegisterAt(instruction, 0); |
| 5763 | Location index = locations->InAt(1); |
| 5764 | Location out_loc = locations->Out(); |
| 5765 | uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction); |
| 5766 | Primitive::Type type = instruction->GetType(); |
| 5767 | const bool maybe_compressed_char_at = mirror::kUseStringCompression && |
| 5768 | instruction->IsStringCharAt(); |
| 5769 | HInstruction* array_instr = instruction->GetArray(); |
| 5770 | bool has_intermediate_address = array_instr->IsIntermediateAddress(); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5771 | |
| 5772 | switch (type) { |
| 5773 | case Primitive::kPrimBoolean: |
| 5774 | case Primitive::kPrimByte: |
| 5775 | case Primitive::kPrimShort: |
| 5776 | case Primitive::kPrimChar: |
| 5777 | case Primitive::kPrimInt: { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5778 | vixl32::Register length; |
| 5779 | if (maybe_compressed_char_at) { |
| 5780 | length = RegisterFrom(locations->GetTemp(0)); |
| 5781 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| 5782 | GetAssembler()->LoadFromOffset(kLoadWord, length, obj, count_offset); |
| 5783 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5784 | } |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5785 | if (index.IsConstant()) { |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 5786 | int32_t const_index = Int32ConstantFrom(index); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5787 | if (maybe_compressed_char_at) { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 5788 | vixl32::Label uncompressed_load, done; |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 5789 | vixl32::Label* final_label = codegen_->GetFinalLabel(instruction, &done); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5790 | __ Lsrs(length, length, 1u); // LSRS has a 16-bit encoding, TST (immediate) does not. |
| 5791 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 5792 | "Expecting 0=compressed, 1=uncompressed"); |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 5793 | __ B(cs, &uncompressed_load, /* far_target */ false); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 5794 | GetAssembler()->LoadFromOffset(kLoadUnsignedByte, |
| 5795 | RegisterFrom(out_loc), |
| 5796 | obj, |
| 5797 | data_offset + const_index); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 5798 | __ B(final_label); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 5799 | __ Bind(&uncompressed_load); |
| 5800 | GetAssembler()->LoadFromOffset(GetLoadOperandType(Primitive::kPrimChar), |
| 5801 | RegisterFrom(out_loc), |
| 5802 | obj, |
| 5803 | data_offset + (const_index << 1)); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 5804 | if (done.IsReferenced()) { |
| 5805 | __ Bind(&done); |
| 5806 | } |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5807 | } else { |
| 5808 | uint32_t full_offset = data_offset + (const_index << Primitive::ComponentSizeShift(type)); |
| 5809 | |
| 5810 | LoadOperandType load_type = GetLoadOperandType(type); |
| 5811 | GetAssembler()->LoadFromOffset(load_type, RegisterFrom(out_loc), obj, full_offset); |
| 5812 | } |
| 5813 | } else { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 5814 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5815 | vixl32::Register temp = temps.Acquire(); |
| 5816 | |
| 5817 | if (has_intermediate_address) { |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 5818 | // We do not need to compute the intermediate address from the array: the |
| 5819 | // input instruction has done it already. See the comment in |
| 5820 | // `TryExtractArrayAccessAddress()`. |
| 5821 | if (kIsDebugBuild) { |
| 5822 | HIntermediateAddress* tmp = array_instr->AsIntermediateAddress(); |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 5823 | DCHECK_EQ(Uint64ConstantFrom(tmp->GetOffset()), data_offset); |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 5824 | } |
| 5825 | temp = obj; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5826 | } else { |
| 5827 | __ Add(temp, obj, data_offset); |
| 5828 | } |
| 5829 | if (maybe_compressed_char_at) { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 5830 | vixl32::Label uncompressed_load, done; |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 5831 | vixl32::Label* final_label = codegen_->GetFinalLabel(instruction, &done); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5832 | __ Lsrs(length, length, 1u); // LSRS has a 16-bit encoding, TST (immediate) does not. |
| 5833 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 5834 | "Expecting 0=compressed, 1=uncompressed"); |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 5835 | __ B(cs, &uncompressed_load, /* far_target */ false); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 5836 | __ Ldrb(RegisterFrom(out_loc), MemOperand(temp, RegisterFrom(index), vixl32::LSL, 0)); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 5837 | __ B(final_label); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 5838 | __ Bind(&uncompressed_load); |
| 5839 | __ Ldrh(RegisterFrom(out_loc), MemOperand(temp, RegisterFrom(index), vixl32::LSL, 1)); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 5840 | if (done.IsReferenced()) { |
| 5841 | __ Bind(&done); |
| 5842 | } |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5843 | } else { |
| 5844 | codegen_->LoadFromShiftedRegOffset(type, out_loc, temp, RegisterFrom(index)); |
| 5845 | } |
| 5846 | } |
| 5847 | break; |
| 5848 | } |
| 5849 | |
| 5850 | case Primitive::kPrimNot: { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 5851 | // The read barrier instrumentation of object ArrayGet |
| 5852 | // instructions does not support the HIntermediateAddress |
| 5853 | // instruction. |
| 5854 | DCHECK(!(has_intermediate_address && kEmitCompilerReadBarrier)); |
| 5855 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5856 | static_assert( |
| 5857 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 5858 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 5859 | // /* HeapReference<Object> */ out = |
| 5860 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 5861 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 5862 | Location temp = locations->GetTemp(0); |
| 5863 | // Note that a potential implicit null check is handled in this |
| 5864 | // CodeGeneratorARMVIXL::GenerateArrayLoadWithBakerReadBarrier call. |
| 5865 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
| 5866 | instruction, out_loc, obj, data_offset, index, temp, /* needs_null_check */ true); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5867 | } else { |
| 5868 | vixl32::Register out = OutputRegister(instruction); |
| 5869 | if (index.IsConstant()) { |
| 5870 | size_t offset = |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 5871 | (Int32ConstantFrom(index) << TIMES_4) + data_offset; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5872 | GetAssembler()->LoadFromOffset(kLoadWord, out, obj, offset); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 5873 | // TODO(VIXL): Here and for other calls to `MaybeRecordImplicitNullCheck` in this method, |
| 5874 | // we should use a scope and the assembler to emit the load instruction to guarantee that |
| 5875 | // we record the pc at the correct position. But the `Assembler` does not automatically |
| 5876 | // handle unencodable offsets. Practically, everything is fine because the helper and |
| 5877 | // VIXL, at the time of writing, do generate the store instruction last. |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5878 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5879 | // If read barriers are enabled, emit read barriers other than |
| 5880 | // Baker's using a slow path (and also unpoison the loaded |
| 5881 | // reference, if heap poisoning is enabled). |
| 5882 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 5883 | } else { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 5884 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5885 | vixl32::Register temp = temps.Acquire(); |
| 5886 | |
| 5887 | if (has_intermediate_address) { |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 5888 | // We do not need to compute the intermediate address from the array: the |
| 5889 | // input instruction has done it already. See the comment in |
| 5890 | // `TryExtractArrayAccessAddress()`. |
| 5891 | if (kIsDebugBuild) { |
| 5892 | HIntermediateAddress* tmp = array_instr->AsIntermediateAddress(); |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 5893 | DCHECK_EQ(Uint64ConstantFrom(tmp->GetOffset()), data_offset); |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 5894 | } |
| 5895 | temp = obj; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5896 | } else { |
| 5897 | __ Add(temp, obj, data_offset); |
| 5898 | } |
| 5899 | codegen_->LoadFromShiftedRegOffset(type, out_loc, temp, RegisterFrom(index)); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 5900 | temps.Close(); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 5901 | // TODO(VIXL): Use a scope to ensure that we record the pc position immediately after the |
| 5902 | // load instruction. Practically, everything is fine because the helper and VIXL, at the |
| 5903 | // time of writing, do generate the store instruction last. |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5904 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5905 | // If read barriers are enabled, emit read barriers other than |
| 5906 | // Baker's using a slow path (and also unpoison the loaded |
| 5907 | // reference, if heap poisoning is enabled). |
| 5908 | codegen_->MaybeGenerateReadBarrierSlow( |
| 5909 | instruction, out_loc, out_loc, obj_loc, data_offset, index); |
| 5910 | } |
| 5911 | } |
| 5912 | break; |
| 5913 | } |
| 5914 | |
| 5915 | case Primitive::kPrimLong: { |
| 5916 | if (index.IsConstant()) { |
| 5917 | size_t offset = |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 5918 | (Int32ConstantFrom(index) << TIMES_8) + data_offset; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5919 | GetAssembler()->LoadFromOffset(kLoadWordPair, LowRegisterFrom(out_loc), obj, offset); |
| 5920 | } else { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 5921 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5922 | vixl32::Register temp = temps.Acquire(); |
| 5923 | __ Add(temp, obj, Operand(RegisterFrom(index), vixl32::LSL, TIMES_8)); |
| 5924 | GetAssembler()->LoadFromOffset(kLoadWordPair, LowRegisterFrom(out_loc), temp, data_offset); |
| 5925 | } |
| 5926 | break; |
| 5927 | } |
| 5928 | |
| 5929 | case Primitive::kPrimFloat: { |
| 5930 | vixl32::SRegister out = SRegisterFrom(out_loc); |
| 5931 | if (index.IsConstant()) { |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 5932 | size_t offset = (Int32ConstantFrom(index) << TIMES_4) + data_offset; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5933 | GetAssembler()->LoadSFromOffset(out, obj, offset); |
| 5934 | } else { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 5935 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5936 | vixl32::Register temp = temps.Acquire(); |
| 5937 | __ Add(temp, obj, Operand(RegisterFrom(index), vixl32::LSL, TIMES_4)); |
| 5938 | GetAssembler()->LoadSFromOffset(out, temp, data_offset); |
| 5939 | } |
| 5940 | break; |
| 5941 | } |
| 5942 | |
| 5943 | case Primitive::kPrimDouble: { |
| 5944 | if (index.IsConstant()) { |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 5945 | size_t offset = (Int32ConstantFrom(index) << TIMES_8) + data_offset; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5946 | GetAssembler()->LoadDFromOffset(DRegisterFrom(out_loc), obj, offset); |
| 5947 | } else { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 5948 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5949 | vixl32::Register temp = temps.Acquire(); |
| 5950 | __ Add(temp, obj, Operand(RegisterFrom(index), vixl32::LSL, TIMES_8)); |
| 5951 | GetAssembler()->LoadDFromOffset(DRegisterFrom(out_loc), temp, data_offset); |
| 5952 | } |
| 5953 | break; |
| 5954 | } |
| 5955 | |
| 5956 | case Primitive::kPrimVoid: |
| 5957 | LOG(FATAL) << "Unreachable type " << type; |
| 5958 | UNREACHABLE(); |
| 5959 | } |
| 5960 | |
| 5961 | if (type == Primitive::kPrimNot) { |
| 5962 | // Potential implicit null checks, in the case of reference |
| 5963 | // arrays, are handled in the previous switch statement. |
| 5964 | } else if (!maybe_compressed_char_at) { |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 5965 | // TODO(VIXL): Use a scope to ensure we record the pc info immediately after |
| 5966 | // the preceding load instruction. |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5967 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5968 | } |
| 5969 | } |
| 5970 | |
| 5971 | void LocationsBuilderARMVIXL::VisitArraySet(HArraySet* instruction) { |
| 5972 | Primitive::Type value_type = instruction->GetComponentType(); |
| 5973 | |
| 5974 | bool needs_write_barrier = |
| 5975 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
| 5976 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
| 5977 | |
| 5978 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 5979 | instruction, |
| 5980 | may_need_runtime_call_for_type_check ? |
| 5981 | LocationSummary::kCallOnSlowPath : |
| 5982 | LocationSummary::kNoCall); |
| 5983 | |
| 5984 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5985 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 5986 | if (Primitive::IsFloatingPointType(value_type)) { |
| 5987 | locations->SetInAt(2, Location::RequiresFpuRegister()); |
| 5988 | } else { |
| 5989 | locations->SetInAt(2, Location::RequiresRegister()); |
| 5990 | } |
| 5991 | if (needs_write_barrier) { |
| 5992 | // Temporary registers for the write barrier. |
| 5993 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
| 5994 | locations->AddTemp(Location::RequiresRegister()); |
| 5995 | } |
| 5996 | } |
| 5997 | |
| 5998 | void InstructionCodeGeneratorARMVIXL::VisitArraySet(HArraySet* instruction) { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5999 | LocationSummary* locations = instruction->GetLocations(); |
| 6000 | vixl32::Register array = InputRegisterAt(instruction, 0); |
| 6001 | Location index = locations->InAt(1); |
| 6002 | Primitive::Type value_type = instruction->GetComponentType(); |
| 6003 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
| 6004 | bool needs_write_barrier = |
| 6005 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
| 6006 | uint32_t data_offset = |
| 6007 | mirror::Array::DataOffset(Primitive::ComponentSize(value_type)).Uint32Value(); |
| 6008 | Location value_loc = locations->InAt(2); |
| 6009 | HInstruction* array_instr = instruction->GetArray(); |
| 6010 | bool has_intermediate_address = array_instr->IsIntermediateAddress(); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6011 | |
| 6012 | switch (value_type) { |
| 6013 | case Primitive::kPrimBoolean: |
| 6014 | case Primitive::kPrimByte: |
| 6015 | case Primitive::kPrimShort: |
| 6016 | case Primitive::kPrimChar: |
| 6017 | case Primitive::kPrimInt: { |
| 6018 | if (index.IsConstant()) { |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6019 | int32_t const_index = Int32ConstantFrom(index); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6020 | uint32_t full_offset = |
| 6021 | data_offset + (const_index << Primitive::ComponentSizeShift(value_type)); |
| 6022 | StoreOperandType store_type = GetStoreOperandType(value_type); |
| 6023 | GetAssembler()->StoreToOffset(store_type, RegisterFrom(value_loc), array, full_offset); |
| 6024 | } else { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6025 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6026 | vixl32::Register temp = temps.Acquire(); |
| 6027 | |
| 6028 | if (has_intermediate_address) { |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6029 | // We do not need to compute the intermediate address from the array: the |
| 6030 | // input instruction has done it already. See the comment in |
| 6031 | // `TryExtractArrayAccessAddress()`. |
| 6032 | if (kIsDebugBuild) { |
| 6033 | HIntermediateAddress* tmp = array_instr->AsIntermediateAddress(); |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6034 | DCHECK_EQ(Uint64ConstantFrom(tmp->GetOffset()), data_offset); |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6035 | } |
| 6036 | temp = array; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6037 | } else { |
| 6038 | __ Add(temp, array, data_offset); |
| 6039 | } |
| 6040 | codegen_->StoreToShiftedRegOffset(value_type, value_loc, temp, RegisterFrom(index)); |
| 6041 | } |
| 6042 | break; |
| 6043 | } |
| 6044 | |
| 6045 | case Primitive::kPrimNot: { |
| 6046 | vixl32::Register value = RegisterFrom(value_loc); |
| 6047 | // TryExtractArrayAccessAddress optimization is never applied for non-primitive ArraySet. |
| 6048 | // See the comment in instruction_simplifier_shared.cc. |
| 6049 | DCHECK(!has_intermediate_address); |
| 6050 | |
| 6051 | if (instruction->InputAt(2)->IsNullConstant()) { |
| 6052 | // Just setting null. |
| 6053 | if (index.IsConstant()) { |
| 6054 | size_t offset = |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6055 | (Int32ConstantFrom(index) << TIMES_4) + data_offset; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6056 | GetAssembler()->StoreToOffset(kStoreWord, value, array, offset); |
| 6057 | } else { |
| 6058 | DCHECK(index.IsRegister()) << index; |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6059 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6060 | vixl32::Register temp = temps.Acquire(); |
| 6061 | __ Add(temp, array, data_offset); |
| 6062 | codegen_->StoreToShiftedRegOffset(value_type, value_loc, temp, RegisterFrom(index)); |
| 6063 | } |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 6064 | // TODO(VIXL): Use a scope to ensure we record the pc info immediately after the preceding |
| 6065 | // store instruction. |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6066 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6067 | DCHECK(!needs_write_barrier); |
| 6068 | DCHECK(!may_need_runtime_call_for_type_check); |
| 6069 | break; |
| 6070 | } |
| 6071 | |
| 6072 | DCHECK(needs_write_barrier); |
| 6073 | Location temp1_loc = locations->GetTemp(0); |
| 6074 | vixl32::Register temp1 = RegisterFrom(temp1_loc); |
| 6075 | Location temp2_loc = locations->GetTemp(1); |
| 6076 | vixl32::Register temp2 = RegisterFrom(temp2_loc); |
| 6077 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 6078 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6079 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6080 | vixl32::Label done; |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 6081 | vixl32::Label* final_label = codegen_->GetFinalLabel(instruction, &done); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6082 | SlowPathCodeARMVIXL* slow_path = nullptr; |
| 6083 | |
| 6084 | if (may_need_runtime_call_for_type_check) { |
| 6085 | slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathARMVIXL(instruction); |
| 6086 | codegen_->AddSlowPath(slow_path); |
| 6087 | if (instruction->GetValueCanBeNull()) { |
| 6088 | vixl32::Label non_zero; |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 6089 | __ CompareAndBranchIfNonZero(value, &non_zero); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6090 | if (index.IsConstant()) { |
| 6091 | size_t offset = |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6092 | (Int32ConstantFrom(index) << TIMES_4) + data_offset; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6093 | GetAssembler()->StoreToOffset(kStoreWord, value, array, offset); |
| 6094 | } else { |
| 6095 | DCHECK(index.IsRegister()) << index; |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6096 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6097 | vixl32::Register temp = temps.Acquire(); |
| 6098 | __ Add(temp, array, data_offset); |
| 6099 | codegen_->StoreToShiftedRegOffset(value_type, value_loc, temp, RegisterFrom(index)); |
| 6100 | } |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 6101 | // TODO(VIXL): Use a scope to ensure we record the pc info immediately after the preceding |
| 6102 | // store instruction. |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6103 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 6104 | __ B(final_label); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6105 | __ Bind(&non_zero); |
| 6106 | } |
| 6107 | |
| 6108 | // Note that when read barriers are enabled, the type checks |
| 6109 | // are performed without read barriers. This is fine, even in |
| 6110 | // the case where a class object is in the from-space after |
| 6111 | // the flip, as a comparison involving such a type would not |
| 6112 | // produce a false positive; it may of course produce a false |
| 6113 | // negative, in which case we would take the ArraySet slow |
| 6114 | // path. |
| 6115 | |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 6116 | { |
| 6117 | // Ensure we record the pc position immediately after the `ldr` instruction. |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 6118 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 6119 | vixl32::kMaxInstructionSizeInBytes, |
| 6120 | CodeBufferCheckScope::kMaximumSize); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 6121 | // /* HeapReference<Class> */ temp1 = array->klass_ |
| 6122 | __ ldr(temp1, MemOperand(array, class_offset)); |
| 6123 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6124 | } |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6125 | GetAssembler()->MaybeUnpoisonHeapReference(temp1); |
| 6126 | |
| 6127 | // /* HeapReference<Class> */ temp1 = temp1->component_type_ |
| 6128 | GetAssembler()->LoadFromOffset(kLoadWord, temp1, temp1, component_offset); |
| 6129 | // /* HeapReference<Class> */ temp2 = value->klass_ |
| 6130 | GetAssembler()->LoadFromOffset(kLoadWord, temp2, value, class_offset); |
| 6131 | // If heap poisoning is enabled, no need to unpoison `temp1` |
| 6132 | // nor `temp2`, as we are comparing two poisoned references. |
| 6133 | __ Cmp(temp1, temp2); |
| 6134 | |
| 6135 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 6136 | vixl32::Label do_put; |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 6137 | __ B(eq, &do_put, /* far_target */ false); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6138 | // If heap poisoning is enabled, the `temp1` reference has |
| 6139 | // not been unpoisoned yet; unpoison it now. |
| 6140 | GetAssembler()->MaybeUnpoisonHeapReference(temp1); |
| 6141 | |
| 6142 | // /* HeapReference<Class> */ temp1 = temp1->super_class_ |
| 6143 | GetAssembler()->LoadFromOffset(kLoadWord, temp1, temp1, super_offset); |
| 6144 | // If heap poisoning is enabled, no need to unpoison |
| 6145 | // `temp1`, as we are comparing against null below. |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 6146 | __ CompareAndBranchIfNonZero(temp1, slow_path->GetEntryLabel()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6147 | __ Bind(&do_put); |
| 6148 | } else { |
| 6149 | __ B(ne, slow_path->GetEntryLabel()); |
| 6150 | } |
| 6151 | } |
| 6152 | |
| 6153 | vixl32::Register source = value; |
| 6154 | if (kPoisonHeapReferences) { |
| 6155 | // Note that in the case where `value` is a null reference, |
| 6156 | // we do not enter this block, as a null reference does not |
| 6157 | // need poisoning. |
| 6158 | DCHECK_EQ(value_type, Primitive::kPrimNot); |
| 6159 | __ Mov(temp1, value); |
| 6160 | GetAssembler()->PoisonHeapReference(temp1); |
| 6161 | source = temp1; |
| 6162 | } |
| 6163 | |
| 6164 | if (index.IsConstant()) { |
| 6165 | size_t offset = |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6166 | (Int32ConstantFrom(index) << TIMES_4) + data_offset; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6167 | GetAssembler()->StoreToOffset(kStoreWord, source, array, offset); |
| 6168 | } else { |
| 6169 | DCHECK(index.IsRegister()) << index; |
| 6170 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6171 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6172 | vixl32::Register temp = temps.Acquire(); |
| 6173 | __ Add(temp, array, data_offset); |
| 6174 | codegen_->StoreToShiftedRegOffset(value_type, |
| 6175 | LocationFrom(source), |
| 6176 | temp, |
| 6177 | RegisterFrom(index)); |
| 6178 | } |
| 6179 | |
| 6180 | if (!may_need_runtime_call_for_type_check) { |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 6181 | // TODO(VIXL): Ensure we record the pc position immediately after the preceding store |
| 6182 | // instruction. |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6183 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6184 | } |
| 6185 | |
| 6186 | codegen_->MarkGCCard(temp1, temp2, array, value, instruction->GetValueCanBeNull()); |
| 6187 | |
| 6188 | if (done.IsReferenced()) { |
| 6189 | __ Bind(&done); |
| 6190 | } |
| 6191 | |
| 6192 | if (slow_path != nullptr) { |
| 6193 | __ Bind(slow_path->GetExitLabel()); |
| 6194 | } |
| 6195 | |
| 6196 | break; |
| 6197 | } |
| 6198 | |
| 6199 | case Primitive::kPrimLong: { |
| 6200 | Location value = locations->InAt(2); |
| 6201 | if (index.IsConstant()) { |
| 6202 | size_t offset = |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6203 | (Int32ConstantFrom(index) << TIMES_8) + data_offset; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6204 | GetAssembler()->StoreToOffset(kStoreWordPair, LowRegisterFrom(value), array, offset); |
| 6205 | } else { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6206 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6207 | vixl32::Register temp = temps.Acquire(); |
| 6208 | __ Add(temp, array, Operand(RegisterFrom(index), vixl32::LSL, TIMES_8)); |
| 6209 | GetAssembler()->StoreToOffset(kStoreWordPair, LowRegisterFrom(value), temp, data_offset); |
| 6210 | } |
| 6211 | break; |
| 6212 | } |
| 6213 | |
| 6214 | case Primitive::kPrimFloat: { |
| 6215 | Location value = locations->InAt(2); |
| 6216 | DCHECK(value.IsFpuRegister()); |
| 6217 | if (index.IsConstant()) { |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6218 | size_t offset = (Int32ConstantFrom(index) << TIMES_4) + data_offset; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6219 | GetAssembler()->StoreSToOffset(SRegisterFrom(value), array, offset); |
| 6220 | } else { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6221 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6222 | vixl32::Register temp = temps.Acquire(); |
| 6223 | __ Add(temp, array, Operand(RegisterFrom(index), vixl32::LSL, TIMES_4)); |
| 6224 | GetAssembler()->StoreSToOffset(SRegisterFrom(value), temp, data_offset); |
| 6225 | } |
| 6226 | break; |
| 6227 | } |
| 6228 | |
| 6229 | case Primitive::kPrimDouble: { |
| 6230 | Location value = locations->InAt(2); |
| 6231 | DCHECK(value.IsFpuRegisterPair()); |
| 6232 | if (index.IsConstant()) { |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6233 | size_t offset = (Int32ConstantFrom(index) << TIMES_8) + data_offset; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6234 | GetAssembler()->StoreDToOffset(DRegisterFrom(value), array, offset); |
| 6235 | } else { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6236 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6237 | vixl32::Register temp = temps.Acquire(); |
| 6238 | __ Add(temp, array, Operand(RegisterFrom(index), vixl32::LSL, TIMES_8)); |
| 6239 | GetAssembler()->StoreDToOffset(DRegisterFrom(value), temp, data_offset); |
| 6240 | } |
| 6241 | break; |
| 6242 | } |
| 6243 | |
| 6244 | case Primitive::kPrimVoid: |
| 6245 | LOG(FATAL) << "Unreachable type " << value_type; |
| 6246 | UNREACHABLE(); |
| 6247 | } |
| 6248 | |
| 6249 | // Objects are handled in the switch. |
| 6250 | if (value_type != Primitive::kPrimNot) { |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 6251 | // TODO(VIXL): Ensure we record the pc position immediately after the preceding store |
| 6252 | // instruction. |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6253 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6254 | } |
| 6255 | } |
| 6256 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6257 | void LocationsBuilderARMVIXL::VisitArrayLength(HArrayLength* instruction) { |
| 6258 | LocationSummary* locations = |
| 6259 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 6260 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6261 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6262 | } |
| 6263 | |
| 6264 | void InstructionCodeGeneratorARMVIXL::VisitArrayLength(HArrayLength* instruction) { |
| 6265 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
| 6266 | vixl32::Register obj = InputRegisterAt(instruction, 0); |
| 6267 | vixl32::Register out = OutputRegister(instruction); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 6268 | { |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 6269 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 6270 | vixl32::kMaxInstructionSizeInBytes, |
| 6271 | CodeBufferCheckScope::kMaximumSize); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 6272 | __ ldr(out, MemOperand(obj, offset)); |
| 6273 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6274 | } |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6275 | // Mask out compression flag from String's array length. |
| 6276 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 6277 | __ Lsr(out, out, 1u); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6278 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6279 | } |
| 6280 | |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6281 | void LocationsBuilderARMVIXL::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6282 | LocationSummary* locations = |
| 6283 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 6284 | |
| 6285 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6286 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->GetOffset())); |
| 6287 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6288 | } |
| 6289 | |
| 6290 | void InstructionCodeGeneratorARMVIXL::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
| 6291 | vixl32::Register out = OutputRegister(instruction); |
| 6292 | vixl32::Register first = InputRegisterAt(instruction, 0); |
| 6293 | Location second = instruction->GetLocations()->InAt(1); |
| 6294 | |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6295 | if (second.IsRegister()) { |
| 6296 | __ Add(out, first, RegisterFrom(second)); |
| 6297 | } else { |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6298 | __ Add(out, first, Int32ConstantFrom(second)); |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6299 | } |
| 6300 | } |
| 6301 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6302 | void LocationsBuilderARMVIXL::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 6303 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 6304 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 6305 | caller_saves.Add(LocationFrom(calling_convention.GetRegisterAt(0))); |
| 6306 | caller_saves.Add(LocationFrom(calling_convention.GetRegisterAt(1))); |
| 6307 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
Artem Serov | 2dd053d | 2017-03-08 14:54:06 +0000 | [diff] [blame] | 6308 | |
| 6309 | HInstruction* index = instruction->InputAt(0); |
| 6310 | HInstruction* length = instruction->InputAt(1); |
| 6311 | // If both index and length are constants we can statically check the bounds. But if at least one |
| 6312 | // of them is not encodable ArmEncodableConstantOrRegister will create |
| 6313 | // Location::RequiresRegister() which is not desired to happen. Instead we create constant |
| 6314 | // locations. |
| 6315 | bool both_const = index->IsConstant() && length->IsConstant(); |
| 6316 | locations->SetInAt(0, both_const |
| 6317 | ? Location::ConstantLocation(index->AsConstant()) |
| 6318 | : ArmEncodableConstantOrRegister(index, CMP)); |
| 6319 | locations->SetInAt(1, both_const |
| 6320 | ? Location::ConstantLocation(length->AsConstant()) |
| 6321 | : ArmEncodableConstantOrRegister(length, CMP)); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6322 | } |
| 6323 | |
| 6324 | void InstructionCodeGeneratorARMVIXL::VisitBoundsCheck(HBoundsCheck* instruction) { |
Artem Serov | 2dd053d | 2017-03-08 14:54:06 +0000 | [diff] [blame] | 6325 | LocationSummary* locations = instruction->GetLocations(); |
| 6326 | Location index_loc = locations->InAt(0); |
| 6327 | Location length_loc = locations->InAt(1); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6328 | |
Artem Serov | 2dd053d | 2017-03-08 14:54:06 +0000 | [diff] [blame] | 6329 | if (length_loc.IsConstant()) { |
| 6330 | int32_t length = Int32ConstantFrom(length_loc); |
| 6331 | if (index_loc.IsConstant()) { |
| 6332 | // BCE will remove the bounds check if we are guaranteed to pass. |
| 6333 | int32_t index = Int32ConstantFrom(index_loc); |
| 6334 | if (index < 0 || index >= length) { |
| 6335 | SlowPathCodeARMVIXL* slow_path = |
| 6336 | new (GetGraph()->GetArena()) BoundsCheckSlowPathARMVIXL(instruction); |
| 6337 | codegen_->AddSlowPath(slow_path); |
| 6338 | __ B(slow_path->GetEntryLabel()); |
| 6339 | } else { |
| 6340 | // Some optimization after BCE may have generated this, and we should not |
| 6341 | // generate a bounds check if it is a valid range. |
| 6342 | } |
| 6343 | return; |
| 6344 | } |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6345 | |
Artem Serov | 2dd053d | 2017-03-08 14:54:06 +0000 | [diff] [blame] | 6346 | SlowPathCodeARMVIXL* slow_path = |
| 6347 | new (GetGraph()->GetArena()) BoundsCheckSlowPathARMVIXL(instruction); |
| 6348 | __ Cmp(RegisterFrom(index_loc), length); |
| 6349 | codegen_->AddSlowPath(slow_path); |
| 6350 | __ B(hs, slow_path->GetEntryLabel()); |
| 6351 | } else { |
| 6352 | SlowPathCodeARMVIXL* slow_path = |
| 6353 | new (GetGraph()->GetArena()) BoundsCheckSlowPathARMVIXL(instruction); |
| 6354 | __ Cmp(RegisterFrom(length_loc), InputOperandAt(instruction, 0)); |
| 6355 | codegen_->AddSlowPath(slow_path); |
| 6356 | __ B(ls, slow_path->GetEntryLabel()); |
| 6357 | } |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6358 | } |
| 6359 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6360 | void CodeGeneratorARMVIXL::MarkGCCard(vixl32::Register temp, |
| 6361 | vixl32::Register card, |
| 6362 | vixl32::Register object, |
| 6363 | vixl32::Register value, |
| 6364 | bool can_be_null) { |
| 6365 | vixl32::Label is_null; |
| 6366 | if (can_be_null) { |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 6367 | __ CompareAndBranchIfZero(value, &is_null); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6368 | } |
| 6369 | GetAssembler()->LoadFromOffset( |
| 6370 | kLoadWord, card, tr, Thread::CardTableOffset<kArmPointerSize>().Int32Value()); |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 6371 | __ Lsr(temp, object, Operand::From(gc::accounting::CardTable::kCardShift)); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6372 | __ Strb(card, MemOperand(card, temp)); |
| 6373 | if (can_be_null) { |
| 6374 | __ Bind(&is_null); |
| 6375 | } |
| 6376 | } |
| 6377 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6378 | void LocationsBuilderARMVIXL::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
| 6379 | LOG(FATAL) << "Unreachable"; |
| 6380 | } |
| 6381 | |
| 6382 | void InstructionCodeGeneratorARMVIXL::VisitParallelMove(HParallelMove* instruction) { |
| 6383 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 6384 | } |
| 6385 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6386 | void LocationsBuilderARMVIXL::VisitSuspendCheck(HSuspendCheck* instruction) { |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 6387 | LocationSummary* locations = |
| 6388 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
| 6389 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6390 | } |
| 6391 | |
| 6392 | void InstructionCodeGeneratorARMVIXL::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 6393 | HBasicBlock* block = instruction->GetBlock(); |
| 6394 | if (block->GetLoopInformation() != nullptr) { |
| 6395 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 6396 | // The back edge will generate the suspend check. |
| 6397 | return; |
| 6398 | } |
| 6399 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 6400 | // The goto will generate the suspend check. |
| 6401 | return; |
| 6402 | } |
| 6403 | GenerateSuspendCheck(instruction, nullptr); |
| 6404 | } |
| 6405 | |
| 6406 | void InstructionCodeGeneratorARMVIXL::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 6407 | HBasicBlock* successor) { |
| 6408 | SuspendCheckSlowPathARMVIXL* slow_path = |
| 6409 | down_cast<SuspendCheckSlowPathARMVIXL*>(instruction->GetSlowPath()); |
| 6410 | if (slow_path == nullptr) { |
| 6411 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathARMVIXL(instruction, successor); |
| 6412 | instruction->SetSlowPath(slow_path); |
| 6413 | codegen_->AddSlowPath(slow_path); |
| 6414 | if (successor != nullptr) { |
| 6415 | DCHECK(successor->IsLoopHeader()); |
| 6416 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 6417 | } |
| 6418 | } else { |
| 6419 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 6420 | } |
| 6421 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6422 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6423 | vixl32::Register temp = temps.Acquire(); |
| 6424 | GetAssembler()->LoadFromOffset( |
| 6425 | kLoadUnsignedHalfword, temp, tr, Thread::ThreadFlagsOffset<kArmPointerSize>().Int32Value()); |
| 6426 | if (successor == nullptr) { |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 6427 | __ CompareAndBranchIfNonZero(temp, slow_path->GetEntryLabel()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6428 | __ Bind(slow_path->GetReturnLabel()); |
| 6429 | } else { |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 6430 | __ CompareAndBranchIfZero(temp, codegen_->GetLabelOf(successor)); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6431 | __ B(slow_path->GetEntryLabel()); |
| 6432 | } |
| 6433 | } |
| 6434 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6435 | ArmVIXLAssembler* ParallelMoveResolverARMVIXL::GetAssembler() const { |
| 6436 | return codegen_->GetAssembler(); |
| 6437 | } |
| 6438 | |
| 6439 | void ParallelMoveResolverARMVIXL::EmitMove(size_t index) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6440 | UseScratchRegisterScope temps(GetAssembler()->GetVIXLAssembler()); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6441 | MoveOperands* move = moves_[index]; |
| 6442 | Location source = move->GetSource(); |
| 6443 | Location destination = move->GetDestination(); |
| 6444 | |
| 6445 | if (source.IsRegister()) { |
| 6446 | if (destination.IsRegister()) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6447 | __ Mov(RegisterFrom(destination), RegisterFrom(source)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6448 | } else if (destination.IsFpuRegister()) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6449 | __ Vmov(SRegisterFrom(destination), RegisterFrom(source)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6450 | } else { |
| 6451 | DCHECK(destination.IsStackSlot()); |
| 6452 | GetAssembler()->StoreToOffset(kStoreWord, |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6453 | RegisterFrom(source), |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6454 | sp, |
| 6455 | destination.GetStackIndex()); |
| 6456 | } |
| 6457 | } else if (source.IsStackSlot()) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6458 | if (destination.IsRegister()) { |
| 6459 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 6460 | RegisterFrom(destination), |
| 6461 | sp, |
| 6462 | source.GetStackIndex()); |
| 6463 | } else if (destination.IsFpuRegister()) { |
| 6464 | GetAssembler()->LoadSFromOffset(SRegisterFrom(destination), sp, source.GetStackIndex()); |
| 6465 | } else { |
| 6466 | DCHECK(destination.IsStackSlot()); |
| 6467 | vixl32::Register temp = temps.Acquire(); |
| 6468 | GetAssembler()->LoadFromOffset(kLoadWord, temp, sp, source.GetStackIndex()); |
| 6469 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, destination.GetStackIndex()); |
| 6470 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6471 | } else if (source.IsFpuRegister()) { |
Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 6472 | if (destination.IsRegister()) { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6473 | __ Vmov(RegisterFrom(destination), SRegisterFrom(source)); |
Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 6474 | } else if (destination.IsFpuRegister()) { |
| 6475 | __ Vmov(SRegisterFrom(destination), SRegisterFrom(source)); |
| 6476 | } else { |
| 6477 | DCHECK(destination.IsStackSlot()); |
| 6478 | GetAssembler()->StoreSToOffset(SRegisterFrom(source), sp, destination.GetStackIndex()); |
| 6479 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6480 | } else if (source.IsDoubleStackSlot()) { |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 6481 | if (destination.IsDoubleStackSlot()) { |
| 6482 | vixl32::DRegister temp = temps.AcquireD(); |
| 6483 | GetAssembler()->LoadDFromOffset(temp, sp, source.GetStackIndex()); |
| 6484 | GetAssembler()->StoreDToOffset(temp, sp, destination.GetStackIndex()); |
| 6485 | } else if (destination.IsRegisterPair()) { |
| 6486 | DCHECK(ExpectedPairLayout(destination)); |
| 6487 | GetAssembler()->LoadFromOffset( |
| 6488 | kLoadWordPair, LowRegisterFrom(destination), sp, source.GetStackIndex()); |
| 6489 | } else { |
Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 6490 | DCHECK(destination.IsFpuRegisterPair()) << destination; |
| 6491 | GetAssembler()->LoadDFromOffset(DRegisterFrom(destination), sp, source.GetStackIndex()); |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 6492 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6493 | } else if (source.IsRegisterPair()) { |
| 6494 | if (destination.IsRegisterPair()) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6495 | __ Mov(LowRegisterFrom(destination), LowRegisterFrom(source)); |
| 6496 | __ Mov(HighRegisterFrom(destination), HighRegisterFrom(source)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6497 | } else if (destination.IsFpuRegisterPair()) { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6498 | __ Vmov(DRegisterFrom(destination), LowRegisterFrom(source), HighRegisterFrom(source)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6499 | } else { |
| 6500 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 6501 | DCHECK(ExpectedPairLayout(source)); |
| 6502 | GetAssembler()->StoreToOffset(kStoreWordPair, |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6503 | LowRegisterFrom(source), |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6504 | sp, |
| 6505 | destination.GetStackIndex()); |
| 6506 | } |
| 6507 | } else if (source.IsFpuRegisterPair()) { |
Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 6508 | if (destination.IsRegisterPair()) { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6509 | __ Vmov(LowRegisterFrom(destination), HighRegisterFrom(destination), DRegisterFrom(source)); |
Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 6510 | } else if (destination.IsFpuRegisterPair()) { |
| 6511 | __ Vmov(DRegisterFrom(destination), DRegisterFrom(source)); |
| 6512 | } else { |
| 6513 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 6514 | GetAssembler()->StoreDToOffset(DRegisterFrom(source), sp, destination.GetStackIndex()); |
| 6515 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6516 | } else { |
| 6517 | DCHECK(source.IsConstant()) << source; |
| 6518 | HConstant* constant = source.GetConstant(); |
| 6519 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
| 6520 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
| 6521 | if (destination.IsRegister()) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6522 | __ Mov(RegisterFrom(destination), value); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6523 | } else { |
| 6524 | DCHECK(destination.IsStackSlot()); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6525 | vixl32::Register temp = temps.Acquire(); |
| 6526 | __ Mov(temp, value); |
| 6527 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, destination.GetStackIndex()); |
| 6528 | } |
| 6529 | } else if (constant->IsLongConstant()) { |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6530 | int64_t value = Int64ConstantFrom(source); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6531 | if (destination.IsRegisterPair()) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6532 | __ Mov(LowRegisterFrom(destination), Low32Bits(value)); |
| 6533 | __ Mov(HighRegisterFrom(destination), High32Bits(value)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6534 | } else { |
| 6535 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6536 | vixl32::Register temp = temps.Acquire(); |
| 6537 | __ Mov(temp, Low32Bits(value)); |
| 6538 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, destination.GetStackIndex()); |
| 6539 | __ Mov(temp, High32Bits(value)); |
| 6540 | GetAssembler()->StoreToOffset(kStoreWord, |
| 6541 | temp, |
| 6542 | sp, |
| 6543 | destination.GetHighStackIndex(kArmWordSize)); |
| 6544 | } |
| 6545 | } else if (constant->IsDoubleConstant()) { |
| 6546 | double value = constant->AsDoubleConstant()->GetValue(); |
| 6547 | if (destination.IsFpuRegisterPair()) { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6548 | __ Vmov(DRegisterFrom(destination), value); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6549 | } else { |
| 6550 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 6551 | uint64_t int_value = bit_cast<uint64_t, double>(value); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6552 | vixl32::Register temp = temps.Acquire(); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6553 | __ Mov(temp, Low32Bits(int_value)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6554 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, destination.GetStackIndex()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6555 | __ Mov(temp, High32Bits(int_value)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6556 | GetAssembler()->StoreToOffset(kStoreWord, |
| 6557 | temp, |
| 6558 | sp, |
| 6559 | destination.GetHighStackIndex(kArmWordSize)); |
| 6560 | } |
| 6561 | } else { |
| 6562 | DCHECK(constant->IsFloatConstant()) << constant->DebugName(); |
| 6563 | float value = constant->AsFloatConstant()->GetValue(); |
| 6564 | if (destination.IsFpuRegister()) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6565 | __ Vmov(SRegisterFrom(destination), value); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6566 | } else { |
| 6567 | DCHECK(destination.IsStackSlot()); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6568 | vixl32::Register temp = temps.Acquire(); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6569 | __ Mov(temp, bit_cast<int32_t, float>(value)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6570 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, destination.GetStackIndex()); |
| 6571 | } |
| 6572 | } |
| 6573 | } |
| 6574 | } |
| 6575 | |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 6576 | void ParallelMoveResolverARMVIXL::Exchange(vixl32::Register reg, int mem) { |
| 6577 | UseScratchRegisterScope temps(GetAssembler()->GetVIXLAssembler()); |
| 6578 | vixl32::Register temp = temps.Acquire(); |
| 6579 | __ Mov(temp, reg); |
| 6580 | GetAssembler()->LoadFromOffset(kLoadWord, reg, sp, mem); |
| 6581 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, mem); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6582 | } |
| 6583 | |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 6584 | void ParallelMoveResolverARMVIXL::Exchange(int mem1, int mem2) { |
| 6585 | // TODO(VIXL32): Double check the performance of this implementation. |
| 6586 | UseScratchRegisterScope temps(GetAssembler()->GetVIXLAssembler()); |
Nicolas Geoffray | 13a797b | 2017-03-15 16:41:31 +0000 | [diff] [blame] | 6587 | vixl32::Register temp1 = temps.Acquire(); |
| 6588 | ScratchRegisterScope ensure_scratch( |
| 6589 | this, temp1.GetCode(), r0.GetCode(), codegen_->GetNumberOfCoreRegisters()); |
| 6590 | vixl32::Register temp2(ensure_scratch.GetRegister()); |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 6591 | |
Nicolas Geoffray | 13a797b | 2017-03-15 16:41:31 +0000 | [diff] [blame] | 6592 | int stack_offset = ensure_scratch.IsSpilled() ? kArmWordSize : 0; |
| 6593 | GetAssembler()->LoadFromOffset(kLoadWord, temp1, sp, mem1 + stack_offset); |
| 6594 | GetAssembler()->LoadFromOffset(kLoadWord, temp2, sp, mem2 + stack_offset); |
| 6595 | GetAssembler()->StoreToOffset(kStoreWord, temp1, sp, mem2 + stack_offset); |
| 6596 | GetAssembler()->StoreToOffset(kStoreWord, temp2, sp, mem1 + stack_offset); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6597 | } |
| 6598 | |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 6599 | void ParallelMoveResolverARMVIXL::EmitSwap(size_t index) { |
| 6600 | MoveOperands* move = moves_[index]; |
| 6601 | Location source = move->GetSource(); |
| 6602 | Location destination = move->GetDestination(); |
| 6603 | UseScratchRegisterScope temps(GetAssembler()->GetVIXLAssembler()); |
| 6604 | |
| 6605 | if (source.IsRegister() && destination.IsRegister()) { |
| 6606 | vixl32::Register temp = temps.Acquire(); |
| 6607 | DCHECK(!RegisterFrom(source).Is(temp)); |
| 6608 | DCHECK(!RegisterFrom(destination).Is(temp)); |
| 6609 | __ Mov(temp, RegisterFrom(destination)); |
| 6610 | __ Mov(RegisterFrom(destination), RegisterFrom(source)); |
| 6611 | __ Mov(RegisterFrom(source), temp); |
| 6612 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
| 6613 | Exchange(RegisterFrom(source), destination.GetStackIndex()); |
| 6614 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
| 6615 | Exchange(RegisterFrom(destination), source.GetStackIndex()); |
| 6616 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 6617 | Exchange(source.GetStackIndex(), destination.GetStackIndex()); |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 6618 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
Nicolas Geoffray | 13a797b | 2017-03-15 16:41:31 +0000 | [diff] [blame] | 6619 | vixl32::Register temp = temps.Acquire(); |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 6620 | __ Vmov(temp, SRegisterFrom(source)); |
| 6621 | __ Vmov(SRegisterFrom(source), SRegisterFrom(destination)); |
| 6622 | __ Vmov(SRegisterFrom(destination), temp); |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 6623 | } else if (source.IsRegisterPair() && destination.IsRegisterPair()) { |
| 6624 | vixl32::DRegister temp = temps.AcquireD(); |
| 6625 | __ Vmov(temp, LowRegisterFrom(source), HighRegisterFrom(source)); |
| 6626 | __ Mov(LowRegisterFrom(source), LowRegisterFrom(destination)); |
| 6627 | __ Mov(HighRegisterFrom(source), HighRegisterFrom(destination)); |
| 6628 | __ Vmov(LowRegisterFrom(destination), HighRegisterFrom(destination), temp); |
| 6629 | } else if (source.IsRegisterPair() || destination.IsRegisterPair()) { |
| 6630 | vixl32::Register low_reg = LowRegisterFrom(source.IsRegisterPair() ? source : destination); |
| 6631 | int mem = source.IsRegisterPair() ? destination.GetStackIndex() : source.GetStackIndex(); |
| 6632 | DCHECK(ExpectedPairLayout(source.IsRegisterPair() ? source : destination)); |
| 6633 | vixl32::DRegister temp = temps.AcquireD(); |
| 6634 | __ Vmov(temp, low_reg, vixl32::Register(low_reg.GetCode() + 1)); |
| 6635 | GetAssembler()->LoadFromOffset(kLoadWordPair, low_reg, sp, mem); |
| 6636 | GetAssembler()->StoreDToOffset(temp, sp, mem); |
| 6637 | } else if (source.IsFpuRegisterPair() && destination.IsFpuRegisterPair()) { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6638 | vixl32::DRegister first = DRegisterFrom(source); |
| 6639 | vixl32::DRegister second = DRegisterFrom(destination); |
| 6640 | vixl32::DRegister temp = temps.AcquireD(); |
| 6641 | __ Vmov(temp, first); |
| 6642 | __ Vmov(first, second); |
| 6643 | __ Vmov(second, temp); |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 6644 | } else if (source.IsFpuRegisterPair() || destination.IsFpuRegisterPair()) { |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 6645 | vixl32::DRegister reg = source.IsFpuRegisterPair() |
| 6646 | ? DRegisterFrom(source) |
| 6647 | : DRegisterFrom(destination); |
| 6648 | int mem = source.IsFpuRegisterPair() |
| 6649 | ? destination.GetStackIndex() |
| 6650 | : source.GetStackIndex(); |
| 6651 | vixl32::DRegister temp = temps.AcquireD(); |
| 6652 | __ Vmov(temp, reg); |
| 6653 | GetAssembler()->LoadDFromOffset(reg, sp, mem); |
| 6654 | GetAssembler()->StoreDToOffset(temp, sp, mem); |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 6655 | } else if (source.IsFpuRegister() || destination.IsFpuRegister()) { |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 6656 | vixl32::SRegister reg = source.IsFpuRegister() |
| 6657 | ? SRegisterFrom(source) |
| 6658 | : SRegisterFrom(destination); |
| 6659 | int mem = source.IsFpuRegister() |
| 6660 | ? destination.GetStackIndex() |
| 6661 | : source.GetStackIndex(); |
| 6662 | vixl32::Register temp = temps.Acquire(); |
| 6663 | __ Vmov(temp, reg); |
| 6664 | GetAssembler()->LoadSFromOffset(reg, sp, mem); |
| 6665 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, mem); |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 6666 | } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) { |
| 6667 | vixl32::DRegister temp1 = temps.AcquireD(); |
| 6668 | vixl32::DRegister temp2 = temps.AcquireD(); |
| 6669 | __ Vldr(temp1, MemOperand(sp, source.GetStackIndex())); |
| 6670 | __ Vldr(temp2, MemOperand(sp, destination.GetStackIndex())); |
| 6671 | __ Vstr(temp1, MemOperand(sp, destination.GetStackIndex())); |
| 6672 | __ Vstr(temp2, MemOperand(sp, source.GetStackIndex())); |
| 6673 | } else { |
| 6674 | LOG(FATAL) << "Unimplemented" << source << " <-> " << destination; |
| 6675 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6676 | } |
| 6677 | |
Nicolas Geoffray | 13a797b | 2017-03-15 16:41:31 +0000 | [diff] [blame] | 6678 | void ParallelMoveResolverARMVIXL::SpillScratch(int reg) { |
| 6679 | __ Push(vixl32::Register(reg)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6680 | } |
| 6681 | |
Nicolas Geoffray | 13a797b | 2017-03-15 16:41:31 +0000 | [diff] [blame] | 6682 | void ParallelMoveResolverARMVIXL::RestoreScratch(int reg) { |
| 6683 | __ Pop(vixl32::Register(reg)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6684 | } |
| 6685 | |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 6686 | HLoadClass::LoadKind CodeGeneratorARMVIXL::GetSupportedLoadClassKind( |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 6687 | HLoadClass::LoadKind desired_class_load_kind) { |
| 6688 | switch (desired_class_load_kind) { |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 6689 | case HLoadClass::LoadKind::kInvalid: |
| 6690 | LOG(FATAL) << "UNREACHABLE"; |
| 6691 | UNREACHABLE(); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 6692 | case HLoadClass::LoadKind::kReferrersClass: |
| 6693 | break; |
| 6694 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 6695 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 6696 | break; |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 6697 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
| 6698 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 6699 | break; |
| 6700 | case HLoadClass::LoadKind::kBootImageAddress: |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 6701 | break; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6702 | case HLoadClass::LoadKind::kBssEntry: |
| 6703 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| 6704 | break; |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6705 | case HLoadClass::LoadKind::kJitTableAddress: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6706 | DCHECK(Runtime::Current()->UseJitCompilation()); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 6707 | break; |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 6708 | case HLoadClass::LoadKind::kDexCacheViaMethod: |
| 6709 | break; |
| 6710 | } |
| 6711 | return desired_class_load_kind; |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 6712 | } |
| 6713 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6714 | void LocationsBuilderARMVIXL::VisitLoadClass(HLoadClass* cls) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6715 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
| 6716 | if (load_kind == HLoadClass::LoadKind::kDexCacheViaMethod) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6717 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6718 | CodeGenerator::CreateLoadClassRuntimeCallLocationSummary( |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6719 | cls, |
| 6720 | LocationFrom(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6721 | LocationFrom(r0)); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6722 | DCHECK(calling_convention.GetRegisterAt(0).Is(r0)); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6723 | return; |
| 6724 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6725 | DCHECK(!cls->NeedsAccessCheck()); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6726 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 6727 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
| 6728 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6729 | ? LocationSummary::kCallOnSlowPath |
| 6730 | : LocationSummary::kNoCall; |
| 6731 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(cls, call_kind); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 6732 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6733 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 6734 | } |
| 6735 | |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6736 | if (load_kind == HLoadClass::LoadKind::kReferrersClass) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6737 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6738 | } |
| 6739 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6740 | if (load_kind == HLoadClass::LoadKind::kBssEntry) { |
| 6741 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 6742 | // Rely on the type resolution or initialization and marking to save everything we need. |
| 6743 | // Note that IP may be clobbered by saving/restoring the live register (only one thanks |
| 6744 | // to the custom calling convention) or by marking, so we request a different temp. |
| 6745 | locations->AddTemp(Location::RequiresRegister()); |
| 6746 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 6747 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 6748 | caller_saves.Add(LocationFrom(calling_convention.GetRegisterAt(0))); |
| 6749 | // TODO: Add GetReturnLocation() to the calling convention so that we can DCHECK() |
| 6750 | // that the the kPrimNot result register is the same as the first argument register. |
| 6751 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 6752 | } else { |
| 6753 | // For non-Baker read barrier we have a temp-clobbering call. |
| 6754 | } |
| 6755 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6756 | } |
| 6757 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6758 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 6759 | // move. |
| 6760 | void InstructionCodeGeneratorARMVIXL::VisitLoadClass(HLoadClass* cls) NO_THREAD_SAFETY_ANALYSIS { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6761 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
| 6762 | if (load_kind == HLoadClass::LoadKind::kDexCacheViaMethod) { |
| 6763 | codegen_->GenerateLoadClassRuntimeCall(cls); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6764 | return; |
| 6765 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6766 | DCHECK(!cls->NeedsAccessCheck()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6767 | |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6768 | LocationSummary* locations = cls->GetLocations(); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6769 | Location out_loc = locations->Out(); |
| 6770 | vixl32::Register out = OutputRegister(cls); |
| 6771 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 6772 | const ReadBarrierOption read_barrier_option = cls->IsInBootImage() |
| 6773 | ? kWithoutReadBarrier |
| 6774 | : kCompilerReadBarrierOption; |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6775 | bool generate_null_check = false; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6776 | switch (load_kind) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6777 | case HLoadClass::LoadKind::kReferrersClass: { |
| 6778 | DCHECK(!cls->CanCallRuntime()); |
| 6779 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 6780 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 6781 | vixl32::Register current_method = InputRegisterAt(cls, 0); |
| 6782 | GenerateGcRootFieldLoad(cls, |
| 6783 | out_loc, |
| 6784 | current_method, |
Roland Levillain | 00468f3 | 2016-10-27 18:02:48 +0100 | [diff] [blame] | 6785 | ArtMethod::DeclaringClassOffset().Int32Value(), |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 6786 | read_barrier_option); |
| 6787 | break; |
| 6788 | } |
| 6789 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6790 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 6791 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
| 6792 | __ Ldr(out, codegen_->DeduplicateBootImageTypeLiteral(cls->GetDexFile(), |
| 6793 | cls->GetTypeIndex())); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 6794 | break; |
| 6795 | } |
| 6796 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6797 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 6798 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
| 6799 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels = |
| 6800 | codegen_->NewPcRelativeTypePatch(cls->GetDexFile(), cls->GetTypeIndex()); |
| 6801 | codegen_->EmitMovwMovtPlaceholder(labels, out); |
| 6802 | break; |
| 6803 | } |
| 6804 | case HLoadClass::LoadKind::kBootImageAddress: { |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 6805 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6806 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 6807 | reinterpret_cast<uintptr_t>(cls->GetClass().Get())); |
| 6808 | DCHECK_NE(address, 0u); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 6809 | __ Ldr(out, codegen_->DeduplicateBootImageAddressLiteral(address)); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 6810 | break; |
| 6811 | } |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6812 | case HLoadClass::LoadKind::kBssEntry: { |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6813 | vixl32::Register temp = (!kUseReadBarrier || kUseBakerReadBarrier) |
| 6814 | ? RegisterFrom(locations->GetTemp(0)) |
| 6815 | : out; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6816 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels = |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 6817 | codegen_->NewTypeBssEntryPatch(cls->GetDexFile(), cls->GetTypeIndex()); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6818 | codegen_->EmitMovwMovtPlaceholder(labels, temp); |
| 6819 | GenerateGcRootFieldLoad(cls, out_loc, temp, /* offset */ 0, read_barrier_option); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6820 | generate_null_check = true; |
| 6821 | break; |
| 6822 | } |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6823 | case HLoadClass::LoadKind::kJitTableAddress: { |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 6824 | __ Ldr(out, codegen_->DeduplicateJitClassLiteral(cls->GetDexFile(), |
| 6825 | cls->GetTypeIndex(), |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6826 | cls->GetClass())); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 6827 | // /* GcRoot<mirror::Class> */ out = *out |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6828 | GenerateGcRootFieldLoad(cls, out_loc, out, /* offset */ 0, read_barrier_option); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 6829 | break; |
| 6830 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6831 | case HLoadClass::LoadKind::kDexCacheViaMethod: |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 6832 | case HLoadClass::LoadKind::kInvalid: |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6833 | LOG(FATAL) << "UNREACHABLE"; |
| 6834 | UNREACHABLE(); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6835 | } |
| 6836 | |
| 6837 | if (generate_null_check || cls->MustGenerateClinitCheck()) { |
| 6838 | DCHECK(cls->CanCallRuntime()); |
| 6839 | LoadClassSlowPathARMVIXL* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARMVIXL( |
| 6840 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 6841 | codegen_->AddSlowPath(slow_path); |
| 6842 | if (generate_null_check) { |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 6843 | __ CompareAndBranchIfZero(out, slow_path->GetEntryLabel()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6844 | } |
| 6845 | if (cls->MustGenerateClinitCheck()) { |
| 6846 | GenerateClassInitializationCheck(slow_path, out); |
| 6847 | } else { |
| 6848 | __ Bind(slow_path->GetExitLabel()); |
| 6849 | } |
| 6850 | } |
| 6851 | } |
| 6852 | |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 6853 | void LocationsBuilderARMVIXL::VisitClinitCheck(HClinitCheck* check) { |
| 6854 | LocationSummary* locations = |
| 6855 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 6856 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6857 | if (check->HasUses()) { |
| 6858 | locations->SetOut(Location::SameAsFirstInput()); |
| 6859 | } |
| 6860 | } |
| 6861 | |
| 6862 | void InstructionCodeGeneratorARMVIXL::VisitClinitCheck(HClinitCheck* check) { |
| 6863 | // We assume the class is not null. |
| 6864 | LoadClassSlowPathARMVIXL* slow_path = |
| 6865 | new (GetGraph()->GetArena()) LoadClassSlowPathARMVIXL(check->GetLoadClass(), |
| 6866 | check, |
| 6867 | check->GetDexPc(), |
| 6868 | /* do_clinit */ true); |
| 6869 | codegen_->AddSlowPath(slow_path); |
| 6870 | GenerateClassInitializationCheck(slow_path, InputRegisterAt(check, 0)); |
| 6871 | } |
| 6872 | |
| 6873 | void InstructionCodeGeneratorARMVIXL::GenerateClassInitializationCheck( |
| 6874 | LoadClassSlowPathARMVIXL* slow_path, vixl32::Register class_reg) { |
| 6875 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 6876 | vixl32::Register temp = temps.Acquire(); |
| 6877 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 6878 | temp, |
| 6879 | class_reg, |
| 6880 | mirror::Class::StatusOffset().Int32Value()); |
| 6881 | __ Cmp(temp, mirror::Class::kStatusInitialized); |
| 6882 | __ B(lt, slow_path->GetEntryLabel()); |
| 6883 | // Even if the initialized flag is set, we may be in a situation where caches are not synced |
| 6884 | // properly. Therefore, we do a memory fence. |
| 6885 | __ Dmb(ISH); |
| 6886 | __ Bind(slow_path->GetExitLabel()); |
| 6887 | } |
| 6888 | |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 6889 | HLoadString::LoadKind CodeGeneratorARMVIXL::GetSupportedLoadStringKind( |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 6890 | HLoadString::LoadKind desired_string_load_kind) { |
| 6891 | switch (desired_string_load_kind) { |
| 6892 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 6893 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 6894 | break; |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 6895 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
| 6896 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 6897 | break; |
| 6898 | case HLoadString::LoadKind::kBootImageAddress: |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 6899 | break; |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 6900 | case HLoadString::LoadKind::kBssEntry: |
| 6901 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| 6902 | break; |
| 6903 | case HLoadString::LoadKind::kJitTableAddress: |
| 6904 | DCHECK(Runtime::Current()->UseJitCompilation()); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 6905 | break; |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 6906 | case HLoadString::LoadKind::kDexCacheViaMethod: |
| 6907 | break; |
| 6908 | } |
| 6909 | return desired_string_load_kind; |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 6910 | } |
| 6911 | |
| 6912 | void LocationsBuilderARMVIXL::VisitLoadString(HLoadString* load) { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 6913 | LocationSummary::CallKind call_kind = CodeGenerator::GetLoadStringCallKind(load); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 6914 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 6915 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
| 6916 | if (load_kind == HLoadString::LoadKind::kDexCacheViaMethod) { |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 6917 | locations->SetOut(LocationFrom(r0)); |
| 6918 | } else { |
| 6919 | locations->SetOut(Location::RequiresRegister()); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 6920 | if (load_kind == HLoadString::LoadKind::kBssEntry) { |
| 6921 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6922 | // Rely on the pResolveString and marking to save everything we need, including temps. |
| 6923 | // Note that IP may be clobbered by saving/restoring the live register (only one thanks |
| 6924 | // to the custom calling convention) or by marking, so we request a different temp. |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 6925 | locations->AddTemp(Location::RequiresRegister()); |
| 6926 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 6927 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 6928 | caller_saves.Add(LocationFrom(calling_convention.GetRegisterAt(0))); |
| 6929 | // TODO: Add GetReturnLocation() to the calling convention so that we can DCHECK() |
| 6930 | // that the the kPrimNot result register is the same as the first argument register. |
| 6931 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 6932 | } else { |
| 6933 | // For non-Baker read barrier we have a temp-clobbering call. |
| 6934 | } |
| 6935 | } |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 6936 | } |
| 6937 | } |
| 6938 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6939 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 6940 | // move. |
| 6941 | void InstructionCodeGeneratorARMVIXL::VisitLoadString(HLoadString* load) NO_THREAD_SAFETY_ANALYSIS { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 6942 | LocationSummary* locations = load->GetLocations(); |
| 6943 | Location out_loc = locations->Out(); |
| 6944 | vixl32::Register out = OutputRegister(load); |
| 6945 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
| 6946 | |
| 6947 | switch (load_kind) { |
| 6948 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: { |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 6949 | __ Ldr(out, codegen_->DeduplicateBootImageStringLiteral(load->GetDexFile(), |
| 6950 | load->GetStringIndex())); |
| 6951 | return; // No dex cache slow path. |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 6952 | } |
| 6953 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
| 6954 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
| 6955 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels = |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6956 | codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex()); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 6957 | codegen_->EmitMovwMovtPlaceholder(labels, out); |
| 6958 | return; // No dex cache slow path. |
| 6959 | } |
| 6960 | case HLoadString::LoadKind::kBootImageAddress: { |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6961 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 6962 | reinterpret_cast<uintptr_t>(load->GetString().Get())); |
| 6963 | DCHECK_NE(address, 0u); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 6964 | __ Ldr(out, codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 6965 | return; // No dex cache slow path. |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 6966 | } |
| 6967 | case HLoadString::LoadKind::kBssEntry: { |
| 6968 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6969 | vixl32::Register temp = (!kUseReadBarrier || kUseBakerReadBarrier) |
| 6970 | ? RegisterFrom(locations->GetTemp(0)) |
| 6971 | : out; |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 6972 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels = |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6973 | codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex()); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 6974 | codegen_->EmitMovwMovtPlaceholder(labels, temp); |
| 6975 | GenerateGcRootFieldLoad(load, out_loc, temp, /* offset */ 0, kCompilerReadBarrierOption); |
| 6976 | LoadStringSlowPathARMVIXL* slow_path = |
| 6977 | new (GetGraph()->GetArena()) LoadStringSlowPathARMVIXL(load); |
| 6978 | codegen_->AddSlowPath(slow_path); |
| 6979 | __ CompareAndBranchIfZero(out, slow_path->GetEntryLabel()); |
| 6980 | __ Bind(slow_path->GetExitLabel()); |
| 6981 | return; |
| 6982 | } |
| 6983 | case HLoadString::LoadKind::kJitTableAddress: { |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 6984 | __ Ldr(out, codegen_->DeduplicateJitStringLiteral(load->GetDexFile(), |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6985 | load->GetStringIndex(), |
| 6986 | load->GetString())); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 6987 | // /* GcRoot<mirror::String> */ out = *out |
| 6988 | GenerateGcRootFieldLoad(load, out_loc, out, /* offset */ 0, kCompilerReadBarrierOption); |
| 6989 | return; |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 6990 | } |
| 6991 | default: |
| 6992 | break; |
| 6993 | } |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 6994 | |
| 6995 | // TODO: Re-add the compiler code to do string dex cache lookup again. |
| 6996 | DCHECK_EQ(load->GetLoadKind(), HLoadString::LoadKind::kDexCacheViaMethod); |
| 6997 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 6998 | __ Mov(calling_convention.GetRegisterAt(0), load->GetStringIndex().index_); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 6999 | codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc()); |
| 7000 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
| 7001 | } |
| 7002 | |
| 7003 | static int32_t GetExceptionTlsOffset() { |
| 7004 | return Thread::ExceptionOffset<kArmPointerSize>().Int32Value(); |
| 7005 | } |
| 7006 | |
| 7007 | void LocationsBuilderARMVIXL::VisitLoadException(HLoadException* load) { |
| 7008 | LocationSummary* locations = |
| 7009 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 7010 | locations->SetOut(Location::RequiresRegister()); |
| 7011 | } |
| 7012 | |
| 7013 | void InstructionCodeGeneratorARMVIXL::VisitLoadException(HLoadException* load) { |
| 7014 | vixl32::Register out = OutputRegister(load); |
| 7015 | GetAssembler()->LoadFromOffset(kLoadWord, out, tr, GetExceptionTlsOffset()); |
| 7016 | } |
| 7017 | |
| 7018 | |
| 7019 | void LocationsBuilderARMVIXL::VisitClearException(HClearException* clear) { |
| 7020 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 7021 | } |
| 7022 | |
| 7023 | void InstructionCodeGeneratorARMVIXL::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 7024 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 7025 | vixl32::Register temp = temps.Acquire(); |
| 7026 | __ Mov(temp, 0); |
| 7027 | GetAssembler()->StoreToOffset(kStoreWord, temp, tr, GetExceptionTlsOffset()); |
| 7028 | } |
| 7029 | |
| 7030 | void LocationsBuilderARMVIXL::VisitThrow(HThrow* instruction) { |
| 7031 | LocationSummary* locations = |
| 7032 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
| 7033 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 7034 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 7035 | } |
| 7036 | |
| 7037 | void InstructionCodeGeneratorARMVIXL::VisitThrow(HThrow* instruction) { |
| 7038 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
| 7039 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
| 7040 | } |
| 7041 | |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7042 | // Temp is used for read barrier. |
| 7043 | static size_t NumberOfInstanceOfTemps(TypeCheckKind type_check_kind) { |
| 7044 | if (kEmitCompilerReadBarrier && |
| 7045 | (kUseBakerReadBarrier || |
| 7046 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 7047 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 7048 | type_check_kind == TypeCheckKind::kArrayObjectCheck)) { |
| 7049 | return 1; |
| 7050 | } |
| 7051 | return 0; |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7052 | } |
| 7053 | |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7054 | // Interface case has 3 temps, one for holding the number of interfaces, one for the current |
| 7055 | // interface pointer, one for loading the current interface. |
| 7056 | // The other checks have one temp for loading the object's class. |
| 7057 | static size_t NumberOfCheckCastTemps(TypeCheckKind type_check_kind) { |
| 7058 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { |
| 7059 | return 3; |
| 7060 | } |
| 7061 | return 1 + NumberOfInstanceOfTemps(type_check_kind); |
| 7062 | } |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7063 | |
| 7064 | void LocationsBuilderARMVIXL::VisitInstanceOf(HInstanceOf* instruction) { |
| 7065 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 7066 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 7067 | bool baker_read_barrier_slow_path = false; |
| 7068 | switch (type_check_kind) { |
| 7069 | case TypeCheckKind::kExactCheck: |
| 7070 | case TypeCheckKind::kAbstractClassCheck: |
| 7071 | case TypeCheckKind::kClassHierarchyCheck: |
| 7072 | case TypeCheckKind::kArrayObjectCheck: |
| 7073 | call_kind = |
| 7074 | kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
| 7075 | baker_read_barrier_slow_path = kUseBakerReadBarrier; |
| 7076 | break; |
| 7077 | case TypeCheckKind::kArrayCheck: |
| 7078 | case TypeCheckKind::kUnresolvedCheck: |
| 7079 | case TypeCheckKind::kInterfaceCheck: |
| 7080 | call_kind = LocationSummary::kCallOnSlowPath; |
| 7081 | break; |
| 7082 | } |
| 7083 | |
| 7084 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 7085 | if (baker_read_barrier_slow_path) { |
| 7086 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| 7087 | } |
| 7088 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7089 | locations->SetInAt(1, Location::RequiresRegister()); |
| 7090 | // The "out" register is used as a temporary, so it overlaps with the inputs. |
| 7091 | // Note that TypeCheckSlowPathARM uses this register too. |
| 7092 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7093 | locations->AddRegisterTemps(NumberOfInstanceOfTemps(type_check_kind)); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7094 | } |
| 7095 | |
| 7096 | void InstructionCodeGeneratorARMVIXL::VisitInstanceOf(HInstanceOf* instruction) { |
| 7097 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 7098 | LocationSummary* locations = instruction->GetLocations(); |
| 7099 | Location obj_loc = locations->InAt(0); |
| 7100 | vixl32::Register obj = InputRegisterAt(instruction, 0); |
| 7101 | vixl32::Register cls = InputRegisterAt(instruction, 1); |
| 7102 | Location out_loc = locations->Out(); |
| 7103 | vixl32::Register out = OutputRegister(instruction); |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7104 | const size_t num_temps = NumberOfInstanceOfTemps(type_check_kind); |
| 7105 | DCHECK_LE(num_temps, 1u); |
| 7106 | Location maybe_temp_loc = (num_temps >= 1) ? locations->GetTemp(0) : Location::NoLocation(); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7107 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 7108 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 7109 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 7110 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7111 | vixl32::Label done; |
| 7112 | vixl32::Label* const final_label = codegen_->GetFinalLabel(instruction, &done); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7113 | SlowPathCodeARMVIXL* slow_path = nullptr; |
| 7114 | |
| 7115 | // Return 0 if `obj` is null. |
| 7116 | // avoid null check if we know obj is not null. |
| 7117 | if (instruction->MustDoNullCheck()) { |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7118 | DCHECK(!out.Is(obj)); |
| 7119 | __ Mov(out, 0); |
| 7120 | __ CompareAndBranchIfZero(obj, final_label, /* far_target */ false); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7121 | } |
| 7122 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7123 | switch (type_check_kind) { |
| 7124 | case TypeCheckKind::kExactCheck: { |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 7125 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7126 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7127 | out_loc, |
| 7128 | obj_loc, |
| 7129 | class_offset, |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7130 | maybe_temp_loc, |
| 7131 | kCompilerReadBarrierOption); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7132 | // Classes must be equal for the instanceof to succeed. |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7133 | __ Cmp(out, cls); |
| 7134 | // We speculatively set the result to false without changing the condition |
| 7135 | // flags, which allows us to avoid some branching later. |
| 7136 | __ Mov(LeaveFlags, out, 0); |
| 7137 | |
| 7138 | // Since IT blocks longer than a 16-bit instruction are deprecated by ARMv8, |
| 7139 | // we check that the output is in a low register, so that a 16-bit MOV |
| 7140 | // encoding can be used. |
| 7141 | if (out.IsLow()) { |
| 7142 | // We use the scope because of the IT block that follows. |
| 7143 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 7144 | 2 * vixl32::k16BitT32InstructionSizeInBytes, |
| 7145 | CodeBufferCheckScope::kExactSize); |
| 7146 | |
| 7147 | __ it(eq); |
| 7148 | __ mov(eq, out, 1); |
| 7149 | } else { |
| 7150 | __ B(ne, final_label, /* far_target */ false); |
| 7151 | __ Mov(out, 1); |
| 7152 | } |
| 7153 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7154 | break; |
| 7155 | } |
| 7156 | |
| 7157 | case TypeCheckKind::kAbstractClassCheck: { |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 7158 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7159 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7160 | out_loc, |
| 7161 | obj_loc, |
| 7162 | class_offset, |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7163 | maybe_temp_loc, |
| 7164 | kCompilerReadBarrierOption); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7165 | // If the class is abstract, we eagerly fetch the super class of the |
| 7166 | // object to avoid doing a comparison we know will fail. |
| 7167 | vixl32::Label loop; |
| 7168 | __ Bind(&loop); |
| 7169 | // /* HeapReference<Class> */ out = out->super_class_ |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7170 | GenerateReferenceLoadOneRegister(instruction, |
| 7171 | out_loc, |
| 7172 | super_offset, |
| 7173 | maybe_temp_loc, |
| 7174 | kCompilerReadBarrierOption); |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7175 | // If `out` is null, we use it for the result, and jump to the final label. |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 7176 | __ CompareAndBranchIfZero(out, final_label, /* far_target */ false); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7177 | __ Cmp(out, cls); |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 7178 | __ B(ne, &loop, /* far_target */ false); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7179 | __ Mov(out, 1); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7180 | break; |
| 7181 | } |
| 7182 | |
| 7183 | case TypeCheckKind::kClassHierarchyCheck: { |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 7184 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7185 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7186 | out_loc, |
| 7187 | obj_loc, |
| 7188 | class_offset, |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7189 | maybe_temp_loc, |
| 7190 | kCompilerReadBarrierOption); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7191 | // Walk over the class hierarchy to find a match. |
| 7192 | vixl32::Label loop, success; |
| 7193 | __ Bind(&loop); |
| 7194 | __ Cmp(out, cls); |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 7195 | __ B(eq, &success, /* far_target */ false); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7196 | // /* HeapReference<Class> */ out = out->super_class_ |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7197 | GenerateReferenceLoadOneRegister(instruction, |
| 7198 | out_loc, |
| 7199 | super_offset, |
| 7200 | maybe_temp_loc, |
| 7201 | kCompilerReadBarrierOption); |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7202 | // This is essentially a null check, but it sets the condition flags to the |
| 7203 | // proper value for the code that follows the loop, i.e. not `eq`. |
| 7204 | __ Cmp(out, 1); |
| 7205 | __ B(hs, &loop, /* far_target */ false); |
| 7206 | |
| 7207 | // Since IT blocks longer than a 16-bit instruction are deprecated by ARMv8, |
| 7208 | // we check that the output is in a low register, so that a 16-bit MOV |
| 7209 | // encoding can be used. |
| 7210 | if (out.IsLow()) { |
| 7211 | // If `out` is null, we use it for the result, and the condition flags |
| 7212 | // have already been set to `ne`, so the IT block that comes afterwards |
| 7213 | // (and which handles the successful case) turns into a NOP (instead of |
| 7214 | // overwriting `out`). |
| 7215 | __ Bind(&success); |
| 7216 | |
| 7217 | // We use the scope because of the IT block that follows. |
| 7218 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 7219 | 2 * vixl32::k16BitT32InstructionSizeInBytes, |
| 7220 | CodeBufferCheckScope::kExactSize); |
| 7221 | |
| 7222 | // There is only one branch to the `success` label (which is bound to this |
| 7223 | // IT block), and it has the same condition, `eq`, so in that case the MOV |
| 7224 | // is executed. |
| 7225 | __ it(eq); |
| 7226 | __ mov(eq, out, 1); |
| 7227 | } else { |
| 7228 | // If `out` is null, we use it for the result, and jump to the final label. |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 7229 | __ B(final_label); |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7230 | __ Bind(&success); |
| 7231 | __ Mov(out, 1); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7232 | } |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7233 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7234 | break; |
| 7235 | } |
| 7236 | |
| 7237 | case TypeCheckKind::kArrayObjectCheck: { |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 7238 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7239 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7240 | out_loc, |
| 7241 | obj_loc, |
| 7242 | class_offset, |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7243 | maybe_temp_loc, |
| 7244 | kCompilerReadBarrierOption); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7245 | // Do an exact check. |
| 7246 | vixl32::Label exact_check; |
| 7247 | __ Cmp(out, cls); |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 7248 | __ B(eq, &exact_check, /* far_target */ false); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7249 | // Otherwise, we need to check that the object's class is a non-primitive array. |
| 7250 | // /* HeapReference<Class> */ out = out->component_type_ |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7251 | GenerateReferenceLoadOneRegister(instruction, |
| 7252 | out_loc, |
| 7253 | component_offset, |
| 7254 | maybe_temp_loc, |
| 7255 | kCompilerReadBarrierOption); |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7256 | // If `out` is null, we use it for the result, and jump to the final label. |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 7257 | __ CompareAndBranchIfZero(out, final_label, /* far_target */ false); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7258 | GetAssembler()->LoadFromOffset(kLoadUnsignedHalfword, out, out, primitive_offset); |
| 7259 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7260 | __ Cmp(out, 0); |
| 7261 | // We speculatively set the result to false without changing the condition |
| 7262 | // flags, which allows us to avoid some branching later. |
| 7263 | __ Mov(LeaveFlags, out, 0); |
| 7264 | |
| 7265 | // Since IT blocks longer than a 16-bit instruction are deprecated by ARMv8, |
| 7266 | // we check that the output is in a low register, so that a 16-bit MOV |
| 7267 | // encoding can be used. |
| 7268 | if (out.IsLow()) { |
| 7269 | __ Bind(&exact_check); |
| 7270 | |
| 7271 | // We use the scope because of the IT block that follows. |
| 7272 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 7273 | 2 * vixl32::k16BitT32InstructionSizeInBytes, |
| 7274 | CodeBufferCheckScope::kExactSize); |
| 7275 | |
| 7276 | __ it(eq); |
| 7277 | __ mov(eq, out, 1); |
| 7278 | } else { |
| 7279 | __ B(ne, final_label, /* far_target */ false); |
| 7280 | __ Bind(&exact_check); |
| 7281 | __ Mov(out, 1); |
| 7282 | } |
| 7283 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7284 | break; |
| 7285 | } |
| 7286 | |
| 7287 | case TypeCheckKind::kArrayCheck: { |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7288 | // No read barrier since the slow path will retry upon failure. |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 7289 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7290 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7291 | out_loc, |
| 7292 | obj_loc, |
| 7293 | class_offset, |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7294 | maybe_temp_loc, |
| 7295 | kWithoutReadBarrier); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7296 | __ Cmp(out, cls); |
| 7297 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 7298 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARMVIXL(instruction, |
| 7299 | /* is_fatal */ false); |
| 7300 | codegen_->AddSlowPath(slow_path); |
| 7301 | __ B(ne, slow_path->GetEntryLabel()); |
| 7302 | __ Mov(out, 1); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7303 | break; |
| 7304 | } |
| 7305 | |
| 7306 | case TypeCheckKind::kUnresolvedCheck: |
| 7307 | case TypeCheckKind::kInterfaceCheck: { |
| 7308 | // Note that we indeed only call on slow path, but we always go |
| 7309 | // into the slow path for the unresolved and interface check |
| 7310 | // cases. |
| 7311 | // |
| 7312 | // We cannot directly call the InstanceofNonTrivial runtime |
| 7313 | // entry point without resorting to a type checking slow path |
| 7314 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 7315 | // require to assign fixed registers for the inputs of this |
| 7316 | // HInstanceOf instruction (following the runtime calling |
| 7317 | // convention), which might be cluttered by the potential first |
| 7318 | // read barrier emission at the beginning of this method. |
| 7319 | // |
| 7320 | // TODO: Introduce a new runtime entry point taking the object |
| 7321 | // to test (instead of its class) as argument, and let it deal |
| 7322 | // with the read barrier issues. This will let us refactor this |
| 7323 | // case of the `switch` code as it was previously (with a direct |
| 7324 | // call to the runtime not using a type checking slow path). |
| 7325 | // This should also be beneficial for the other cases above. |
| 7326 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 7327 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARMVIXL(instruction, |
| 7328 | /* is_fatal */ false); |
| 7329 | codegen_->AddSlowPath(slow_path); |
| 7330 | __ B(slow_path->GetEntryLabel()); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7331 | break; |
| 7332 | } |
| 7333 | } |
| 7334 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7335 | if (done.IsReferenced()) { |
| 7336 | __ Bind(&done); |
| 7337 | } |
| 7338 | |
| 7339 | if (slow_path != nullptr) { |
| 7340 | __ Bind(slow_path->GetExitLabel()); |
| 7341 | } |
| 7342 | } |
| 7343 | |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7344 | void LocationsBuilderARMVIXL::VisitCheckCast(HCheckCast* instruction) { |
| 7345 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 7346 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
| 7347 | |
| 7348 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 7349 | switch (type_check_kind) { |
| 7350 | case TypeCheckKind::kExactCheck: |
| 7351 | case TypeCheckKind::kAbstractClassCheck: |
| 7352 | case TypeCheckKind::kClassHierarchyCheck: |
| 7353 | case TypeCheckKind::kArrayObjectCheck: |
| 7354 | call_kind = (throws_into_catch || kEmitCompilerReadBarrier) ? |
| 7355 | LocationSummary::kCallOnSlowPath : |
| 7356 | LocationSummary::kNoCall; // In fact, call on a fatal (non-returning) slow path. |
| 7357 | break; |
| 7358 | case TypeCheckKind::kArrayCheck: |
| 7359 | case TypeCheckKind::kUnresolvedCheck: |
| 7360 | case TypeCheckKind::kInterfaceCheck: |
| 7361 | call_kind = LocationSummary::kCallOnSlowPath; |
| 7362 | break; |
| 7363 | } |
| 7364 | |
| 7365 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 7366 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7367 | locations->SetInAt(1, Location::RequiresRegister()); |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7368 | locations->AddRegisterTemps(NumberOfCheckCastTemps(type_check_kind)); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7369 | } |
| 7370 | |
| 7371 | void InstructionCodeGeneratorARMVIXL::VisitCheckCast(HCheckCast* instruction) { |
| 7372 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 7373 | LocationSummary* locations = instruction->GetLocations(); |
| 7374 | Location obj_loc = locations->InAt(0); |
| 7375 | vixl32::Register obj = InputRegisterAt(instruction, 0); |
| 7376 | vixl32::Register cls = InputRegisterAt(instruction, 1); |
| 7377 | Location temp_loc = locations->GetTemp(0); |
| 7378 | vixl32::Register temp = RegisterFrom(temp_loc); |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7379 | const size_t num_temps = NumberOfCheckCastTemps(type_check_kind); |
| 7380 | DCHECK_LE(num_temps, 3u); |
| 7381 | Location maybe_temp2_loc = (num_temps >= 2) ? locations->GetTemp(1) : Location::NoLocation(); |
| 7382 | Location maybe_temp3_loc = (num_temps >= 3) ? locations->GetTemp(2) : Location::NoLocation(); |
| 7383 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 7384 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 7385 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 7386 | const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 7387 | const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value(); |
| 7388 | const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value(); |
| 7389 | const uint32_t object_array_data_offset = |
| 7390 | mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value(); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7391 | |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7392 | // Always false for read barriers since we may need to go to the entrypoint for non-fatal cases |
| 7393 | // from false negatives. The false negatives may come from avoiding read barriers below. Avoiding |
| 7394 | // read barriers is done for performance and code size reasons. |
| 7395 | bool is_type_check_slow_path_fatal = false; |
| 7396 | if (!kEmitCompilerReadBarrier) { |
| 7397 | is_type_check_slow_path_fatal = |
| 7398 | (type_check_kind == TypeCheckKind::kExactCheck || |
| 7399 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 7400 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 7401 | type_check_kind == TypeCheckKind::kArrayObjectCheck) && |
| 7402 | !instruction->CanThrowIntoCatchBlock(); |
| 7403 | } |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7404 | SlowPathCodeARMVIXL* type_check_slow_path = |
| 7405 | new (GetGraph()->GetArena()) TypeCheckSlowPathARMVIXL(instruction, |
| 7406 | is_type_check_slow_path_fatal); |
| 7407 | codegen_->AddSlowPath(type_check_slow_path); |
| 7408 | |
| 7409 | vixl32::Label done; |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 7410 | vixl32::Label* final_label = codegen_->GetFinalLabel(instruction, &done); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7411 | // Avoid null check if we know obj is not null. |
| 7412 | if (instruction->MustDoNullCheck()) { |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 7413 | __ CompareAndBranchIfZero(obj, final_label, /* far_target */ false); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7414 | } |
| 7415 | |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7416 | switch (type_check_kind) { |
| 7417 | case TypeCheckKind::kExactCheck: |
| 7418 | case TypeCheckKind::kArrayCheck: { |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7419 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7420 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7421 | temp_loc, |
| 7422 | obj_loc, |
| 7423 | class_offset, |
| 7424 | maybe_temp2_loc, |
| 7425 | kWithoutReadBarrier); |
| 7426 | |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7427 | __ Cmp(temp, cls); |
| 7428 | // Jump to slow path for throwing the exception or doing a |
| 7429 | // more involved array check. |
| 7430 | __ B(ne, type_check_slow_path->GetEntryLabel()); |
| 7431 | break; |
| 7432 | } |
| 7433 | |
| 7434 | case TypeCheckKind::kAbstractClassCheck: { |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7435 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7436 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7437 | temp_loc, |
| 7438 | obj_loc, |
| 7439 | class_offset, |
| 7440 | maybe_temp2_loc, |
| 7441 | kWithoutReadBarrier); |
| 7442 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7443 | // If the class is abstract, we eagerly fetch the super class of the |
| 7444 | // object to avoid doing a comparison we know will fail. |
| 7445 | vixl32::Label loop; |
| 7446 | __ Bind(&loop); |
| 7447 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7448 | GenerateReferenceLoadOneRegister(instruction, |
| 7449 | temp_loc, |
| 7450 | super_offset, |
| 7451 | maybe_temp2_loc, |
| 7452 | kWithoutReadBarrier); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7453 | |
| 7454 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 7455 | // exception. |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 7456 | __ CompareAndBranchIfZero(temp, type_check_slow_path->GetEntryLabel()); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7457 | |
| 7458 | // Otherwise, compare the classes. |
| 7459 | __ Cmp(temp, cls); |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 7460 | __ B(ne, &loop, /* far_target */ false); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7461 | break; |
| 7462 | } |
| 7463 | |
| 7464 | case TypeCheckKind::kClassHierarchyCheck: { |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7465 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7466 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7467 | temp_loc, |
| 7468 | obj_loc, |
| 7469 | class_offset, |
| 7470 | maybe_temp2_loc, |
| 7471 | kWithoutReadBarrier); |
| 7472 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7473 | // Walk over the class hierarchy to find a match. |
| 7474 | vixl32::Label loop; |
| 7475 | __ Bind(&loop); |
| 7476 | __ Cmp(temp, cls); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 7477 | __ B(eq, final_label, /* far_target */ false); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7478 | |
| 7479 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7480 | GenerateReferenceLoadOneRegister(instruction, |
| 7481 | temp_loc, |
| 7482 | super_offset, |
| 7483 | maybe_temp2_loc, |
| 7484 | kWithoutReadBarrier); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7485 | |
| 7486 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 7487 | // exception. |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 7488 | __ CompareAndBranchIfZero(temp, type_check_slow_path->GetEntryLabel()); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7489 | // Otherwise, jump to the beginning of the loop. |
| 7490 | __ B(&loop); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7491 | break; |
| 7492 | } |
| 7493 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7494 | case TypeCheckKind::kArrayObjectCheck: { |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7495 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7496 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7497 | temp_loc, |
| 7498 | obj_loc, |
| 7499 | class_offset, |
| 7500 | maybe_temp2_loc, |
| 7501 | kWithoutReadBarrier); |
| 7502 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7503 | // Do an exact check. |
| 7504 | __ Cmp(temp, cls); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 7505 | __ B(eq, final_label, /* far_target */ false); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7506 | |
| 7507 | // Otherwise, we need to check that the object's class is a non-primitive array. |
| 7508 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7509 | GenerateReferenceLoadOneRegister(instruction, |
| 7510 | temp_loc, |
| 7511 | component_offset, |
| 7512 | maybe_temp2_loc, |
| 7513 | kWithoutReadBarrier); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7514 | // 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] | 7515 | __ CompareAndBranchIfZero(temp, type_check_slow_path->GetEntryLabel()); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7516 | // Otherwise,the object is indeed an array, jump to label `check_non_primitive_component_type` |
| 7517 | // to further check that this component type is not a primitive type. |
| 7518 | GetAssembler()->LoadFromOffset(kLoadUnsignedHalfword, temp, temp, primitive_offset); |
| 7519 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for art::Primitive::kPrimNot"); |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 7520 | __ CompareAndBranchIfNonZero(temp, type_check_slow_path->GetEntryLabel()); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7521 | break; |
| 7522 | } |
| 7523 | |
| 7524 | case TypeCheckKind::kUnresolvedCheck: |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7525 | // 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] | 7526 | // We cannot directly call the CheckCast runtime entry point |
| 7527 | // without resorting to a type checking slow path here (i.e. by |
| 7528 | // calling InvokeRuntime directly), as it would require to |
| 7529 | // assign fixed registers for the inputs of this HInstanceOf |
| 7530 | // instruction (following the runtime calling convention), which |
| 7531 | // might be cluttered by the potential first read barrier |
| 7532 | // emission at the beginning of this method. |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7533 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7534 | __ B(type_check_slow_path->GetEntryLabel()); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7535 | break; |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7536 | |
| 7537 | case TypeCheckKind::kInterfaceCheck: { |
| 7538 | // Avoid read barriers to improve performance of the fast path. We can not get false |
| 7539 | // positives by doing this. |
| 7540 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7541 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7542 | temp_loc, |
| 7543 | obj_loc, |
| 7544 | class_offset, |
| 7545 | maybe_temp2_loc, |
| 7546 | kWithoutReadBarrier); |
| 7547 | |
| 7548 | // /* HeapReference<Class> */ temp = temp->iftable_ |
| 7549 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7550 | temp_loc, |
| 7551 | temp_loc, |
| 7552 | iftable_offset, |
| 7553 | maybe_temp2_loc, |
| 7554 | kWithoutReadBarrier); |
| 7555 | // Iftable is never null. |
| 7556 | __ Ldr(RegisterFrom(maybe_temp2_loc), MemOperand(temp, array_length_offset)); |
| 7557 | // Loop through the iftable and check if any class matches. |
| 7558 | vixl32::Label start_loop; |
| 7559 | __ Bind(&start_loop); |
| 7560 | __ CompareAndBranchIfZero(RegisterFrom(maybe_temp2_loc), |
| 7561 | type_check_slow_path->GetEntryLabel()); |
| 7562 | __ Ldr(RegisterFrom(maybe_temp3_loc), MemOperand(temp, object_array_data_offset)); |
| 7563 | GetAssembler()->MaybeUnpoisonHeapReference(RegisterFrom(maybe_temp3_loc)); |
| 7564 | // Go to next interface. |
| 7565 | __ Add(temp, temp, Operand::From(2 * kHeapReferenceSize)); |
| 7566 | __ Sub(RegisterFrom(maybe_temp2_loc), RegisterFrom(maybe_temp2_loc), 2); |
| 7567 | // Compare the classes and continue the loop if they do not match. |
| 7568 | __ Cmp(cls, RegisterFrom(maybe_temp3_loc)); |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 7569 | __ B(ne, &start_loop, /* far_target */ false); |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7570 | break; |
| 7571 | } |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7572 | } |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 7573 | if (done.IsReferenced()) { |
| 7574 | __ Bind(&done); |
| 7575 | } |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7576 | |
| 7577 | __ Bind(type_check_slow_path->GetExitLabel()); |
| 7578 | } |
| 7579 | |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 7580 | void LocationsBuilderARMVIXL::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 7581 | LocationSummary* locations = |
| 7582 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
| 7583 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 7584 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 7585 | } |
| 7586 | |
| 7587 | void InstructionCodeGeneratorARMVIXL::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 7588 | codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject : kQuickUnlockObject, |
| 7589 | instruction, |
| 7590 | instruction->GetDexPc()); |
| 7591 | if (instruction->IsEnter()) { |
| 7592 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 7593 | } else { |
| 7594 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 7595 | } |
| 7596 | } |
| 7597 | |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 7598 | void LocationsBuilderARMVIXL::VisitAnd(HAnd* instruction) { |
| 7599 | HandleBitwiseOperation(instruction, AND); |
| 7600 | } |
| 7601 | |
| 7602 | void LocationsBuilderARMVIXL::VisitOr(HOr* instruction) { |
| 7603 | HandleBitwiseOperation(instruction, ORR); |
| 7604 | } |
| 7605 | |
| 7606 | void LocationsBuilderARMVIXL::VisitXor(HXor* instruction) { |
| 7607 | HandleBitwiseOperation(instruction, EOR); |
| 7608 | } |
| 7609 | |
| 7610 | void LocationsBuilderARMVIXL::HandleBitwiseOperation(HBinaryOperation* instruction, Opcode opcode) { |
| 7611 | LocationSummary* locations = |
| 7612 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 7613 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 7614 | || instruction->GetResultType() == Primitive::kPrimLong); |
| 7615 | // Note: GVN reorders commutative operations to have the constant on the right hand side. |
| 7616 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7617 | locations->SetInAt(1, ArmEncodableConstantOrRegister(instruction->InputAt(1), opcode)); |
| 7618 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 7619 | } |
| 7620 | |
| 7621 | void InstructionCodeGeneratorARMVIXL::VisitAnd(HAnd* instruction) { |
| 7622 | HandleBitwiseOperation(instruction); |
| 7623 | } |
| 7624 | |
| 7625 | void InstructionCodeGeneratorARMVIXL::VisitOr(HOr* instruction) { |
| 7626 | HandleBitwiseOperation(instruction); |
| 7627 | } |
| 7628 | |
| 7629 | void InstructionCodeGeneratorARMVIXL::VisitXor(HXor* instruction) { |
| 7630 | HandleBitwiseOperation(instruction); |
| 7631 | } |
| 7632 | |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 7633 | void LocationsBuilderARMVIXL::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instruction) { |
| 7634 | LocationSummary* locations = |
| 7635 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 7636 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 7637 | || instruction->GetResultType() == Primitive::kPrimLong); |
| 7638 | |
| 7639 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7640 | locations->SetInAt(1, Location::RequiresRegister()); |
| 7641 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 7642 | } |
| 7643 | |
| 7644 | void InstructionCodeGeneratorARMVIXL::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instruction) { |
| 7645 | LocationSummary* locations = instruction->GetLocations(); |
| 7646 | Location first = locations->InAt(0); |
| 7647 | Location second = locations->InAt(1); |
| 7648 | Location out = locations->Out(); |
| 7649 | |
| 7650 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 7651 | vixl32::Register first_reg = RegisterFrom(first); |
| 7652 | vixl32::Register second_reg = RegisterFrom(second); |
| 7653 | vixl32::Register out_reg = RegisterFrom(out); |
| 7654 | |
| 7655 | switch (instruction->GetOpKind()) { |
| 7656 | case HInstruction::kAnd: |
| 7657 | __ Bic(out_reg, first_reg, second_reg); |
| 7658 | break; |
| 7659 | case HInstruction::kOr: |
| 7660 | __ Orn(out_reg, first_reg, second_reg); |
| 7661 | break; |
| 7662 | // There is no EON on arm. |
| 7663 | case HInstruction::kXor: |
| 7664 | default: |
| 7665 | LOG(FATAL) << "Unexpected instruction " << instruction->DebugName(); |
| 7666 | UNREACHABLE(); |
| 7667 | } |
| 7668 | return; |
| 7669 | |
| 7670 | } else { |
| 7671 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 7672 | vixl32::Register first_low = LowRegisterFrom(first); |
| 7673 | vixl32::Register first_high = HighRegisterFrom(first); |
| 7674 | vixl32::Register second_low = LowRegisterFrom(second); |
| 7675 | vixl32::Register second_high = HighRegisterFrom(second); |
| 7676 | vixl32::Register out_low = LowRegisterFrom(out); |
| 7677 | vixl32::Register out_high = HighRegisterFrom(out); |
| 7678 | |
| 7679 | switch (instruction->GetOpKind()) { |
| 7680 | case HInstruction::kAnd: |
| 7681 | __ Bic(out_low, first_low, second_low); |
| 7682 | __ Bic(out_high, first_high, second_high); |
| 7683 | break; |
| 7684 | case HInstruction::kOr: |
| 7685 | __ Orn(out_low, first_low, second_low); |
| 7686 | __ Orn(out_high, first_high, second_high); |
| 7687 | break; |
| 7688 | // There is no EON on arm. |
| 7689 | case HInstruction::kXor: |
| 7690 | default: |
| 7691 | LOG(FATAL) << "Unexpected instruction " << instruction->DebugName(); |
| 7692 | UNREACHABLE(); |
| 7693 | } |
| 7694 | } |
| 7695 | } |
| 7696 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 7697 | void LocationsBuilderARMVIXL::VisitDataProcWithShifterOp( |
| 7698 | HDataProcWithShifterOp* instruction) { |
| 7699 | DCHECK(instruction->GetType() == Primitive::kPrimInt || |
| 7700 | instruction->GetType() == Primitive::kPrimLong); |
| 7701 | LocationSummary* locations = |
| 7702 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 7703 | const bool overlap = instruction->GetType() == Primitive::kPrimLong && |
| 7704 | HDataProcWithShifterOp::IsExtensionOp(instruction->GetOpKind()); |
| 7705 | |
| 7706 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7707 | locations->SetInAt(1, Location::RequiresRegister()); |
| 7708 | locations->SetOut(Location::RequiresRegister(), |
| 7709 | overlap ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
| 7710 | } |
| 7711 | |
| 7712 | void InstructionCodeGeneratorARMVIXL::VisitDataProcWithShifterOp( |
| 7713 | HDataProcWithShifterOp* instruction) { |
| 7714 | const LocationSummary* const locations = instruction->GetLocations(); |
| 7715 | const HInstruction::InstructionKind kind = instruction->GetInstrKind(); |
| 7716 | const HDataProcWithShifterOp::OpKind op_kind = instruction->GetOpKind(); |
| 7717 | |
| 7718 | if (instruction->GetType() == Primitive::kPrimInt) { |
| 7719 | DCHECK(!HDataProcWithShifterOp::IsExtensionOp(op_kind)); |
| 7720 | |
| 7721 | const vixl32::Register second = instruction->InputAt(1)->GetType() == Primitive::kPrimLong |
| 7722 | ? LowRegisterFrom(locations->InAt(1)) |
| 7723 | : InputRegisterAt(instruction, 1); |
| 7724 | |
| 7725 | GenerateDataProcInstruction(kind, |
| 7726 | OutputRegister(instruction), |
| 7727 | InputRegisterAt(instruction, 0), |
| 7728 | Operand(second, |
| 7729 | ShiftFromOpKind(op_kind), |
| 7730 | instruction->GetShiftAmount()), |
| 7731 | codegen_); |
| 7732 | } else { |
| 7733 | DCHECK_EQ(instruction->GetType(), Primitive::kPrimLong); |
| 7734 | |
| 7735 | if (HDataProcWithShifterOp::IsExtensionOp(op_kind)) { |
| 7736 | const vixl32::Register second = InputRegisterAt(instruction, 1); |
| 7737 | |
| 7738 | DCHECK(!LowRegisterFrom(locations->Out()).Is(second)); |
| 7739 | GenerateDataProc(kind, |
| 7740 | locations->Out(), |
| 7741 | locations->InAt(0), |
| 7742 | second, |
| 7743 | Operand(second, ShiftType::ASR, 31), |
| 7744 | codegen_); |
| 7745 | } else { |
| 7746 | GenerateLongDataProc(instruction, codegen_); |
| 7747 | } |
| 7748 | } |
| 7749 | } |
| 7750 | |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 7751 | // TODO(VIXL): Remove optimizations in the helper when they are implemented in vixl. |
| 7752 | void InstructionCodeGeneratorARMVIXL::GenerateAndConst(vixl32::Register out, |
| 7753 | vixl32::Register first, |
| 7754 | uint32_t value) { |
| 7755 | // Optimize special cases for individual halfs of `and-long` (`and` is simplified earlier). |
| 7756 | if (value == 0xffffffffu) { |
| 7757 | if (!out.Is(first)) { |
| 7758 | __ Mov(out, first); |
| 7759 | } |
| 7760 | return; |
| 7761 | } |
| 7762 | if (value == 0u) { |
| 7763 | __ Mov(out, 0); |
| 7764 | return; |
| 7765 | } |
| 7766 | if (GetAssembler()->ShifterOperandCanHold(AND, value)) { |
Anton Kirilov | effd5bf | 2017-02-28 16:59:15 +0000 | [diff] [blame] | 7767 | __ And(out, first, value); |
| 7768 | } else if (GetAssembler()->ShifterOperandCanHold(BIC, ~value)) { |
| 7769 | __ Bic(out, first, ~value); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 7770 | } else { |
Anton Kirilov | effd5bf | 2017-02-28 16:59:15 +0000 | [diff] [blame] | 7771 | DCHECK(IsPowerOfTwo(value + 1)); |
| 7772 | __ Ubfx(out, first, 0, WhichPowerOf2(value + 1)); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 7773 | } |
| 7774 | } |
| 7775 | |
| 7776 | // TODO(VIXL): Remove optimizations in the helper when they are implemented in vixl. |
| 7777 | void InstructionCodeGeneratorARMVIXL::GenerateOrrConst(vixl32::Register out, |
| 7778 | vixl32::Register first, |
| 7779 | uint32_t value) { |
| 7780 | // Optimize special cases for individual halfs of `or-long` (`or` is simplified earlier). |
| 7781 | if (value == 0u) { |
| 7782 | if (!out.Is(first)) { |
| 7783 | __ Mov(out, first); |
| 7784 | } |
| 7785 | return; |
| 7786 | } |
| 7787 | if (value == 0xffffffffu) { |
| 7788 | __ Mvn(out, 0); |
| 7789 | return; |
| 7790 | } |
| 7791 | if (GetAssembler()->ShifterOperandCanHold(ORR, value)) { |
| 7792 | __ Orr(out, first, value); |
| 7793 | } else { |
| 7794 | DCHECK(GetAssembler()->ShifterOperandCanHold(ORN, ~value)); |
| 7795 | __ Orn(out, first, ~value); |
| 7796 | } |
| 7797 | } |
| 7798 | |
| 7799 | // TODO(VIXL): Remove optimizations in the helper when they are implemented in vixl. |
| 7800 | void InstructionCodeGeneratorARMVIXL::GenerateEorConst(vixl32::Register out, |
| 7801 | vixl32::Register first, |
| 7802 | uint32_t value) { |
| 7803 | // Optimize special case for individual halfs of `xor-long` (`xor` is simplified earlier). |
| 7804 | if (value == 0u) { |
| 7805 | if (!out.Is(first)) { |
| 7806 | __ Mov(out, first); |
| 7807 | } |
| 7808 | return; |
| 7809 | } |
| 7810 | __ Eor(out, first, value); |
| 7811 | } |
| 7812 | |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 7813 | void InstructionCodeGeneratorARMVIXL::GenerateAddLongConst(Location out, |
| 7814 | Location first, |
| 7815 | uint64_t value) { |
| 7816 | vixl32::Register out_low = LowRegisterFrom(out); |
| 7817 | vixl32::Register out_high = HighRegisterFrom(out); |
| 7818 | vixl32::Register first_low = LowRegisterFrom(first); |
| 7819 | vixl32::Register first_high = HighRegisterFrom(first); |
| 7820 | uint32_t value_low = Low32Bits(value); |
| 7821 | uint32_t value_high = High32Bits(value); |
| 7822 | if (value_low == 0u) { |
| 7823 | if (!out_low.Is(first_low)) { |
| 7824 | __ Mov(out_low, first_low); |
| 7825 | } |
| 7826 | __ Add(out_high, first_high, value_high); |
| 7827 | return; |
| 7828 | } |
| 7829 | __ Adds(out_low, first_low, value_low); |
Scott Wakeling | bffdc70 | 2016-12-07 17:46:03 +0000 | [diff] [blame] | 7830 | if (GetAssembler()->ShifterOperandCanHold(ADC, value_high, kCcDontCare)) { |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 7831 | __ Adc(out_high, first_high, value_high); |
Scott Wakeling | bffdc70 | 2016-12-07 17:46:03 +0000 | [diff] [blame] | 7832 | } else if (GetAssembler()->ShifterOperandCanHold(SBC, ~value_high, kCcDontCare)) { |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 7833 | __ Sbc(out_high, first_high, ~value_high); |
| 7834 | } else { |
| 7835 | LOG(FATAL) << "Unexpected constant " << value_high; |
| 7836 | UNREACHABLE(); |
| 7837 | } |
| 7838 | } |
| 7839 | |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 7840 | void InstructionCodeGeneratorARMVIXL::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 7841 | LocationSummary* locations = instruction->GetLocations(); |
| 7842 | Location first = locations->InAt(0); |
| 7843 | Location second = locations->InAt(1); |
| 7844 | Location out = locations->Out(); |
| 7845 | |
| 7846 | if (second.IsConstant()) { |
| 7847 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant())); |
| 7848 | uint32_t value_low = Low32Bits(value); |
| 7849 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 7850 | vixl32::Register first_reg = InputRegisterAt(instruction, 0); |
| 7851 | vixl32::Register out_reg = OutputRegister(instruction); |
| 7852 | if (instruction->IsAnd()) { |
| 7853 | GenerateAndConst(out_reg, first_reg, value_low); |
| 7854 | } else if (instruction->IsOr()) { |
| 7855 | GenerateOrrConst(out_reg, first_reg, value_low); |
| 7856 | } else { |
| 7857 | DCHECK(instruction->IsXor()); |
| 7858 | GenerateEorConst(out_reg, first_reg, value_low); |
| 7859 | } |
| 7860 | } else { |
| 7861 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 7862 | uint32_t value_high = High32Bits(value); |
| 7863 | vixl32::Register first_low = LowRegisterFrom(first); |
| 7864 | vixl32::Register first_high = HighRegisterFrom(first); |
| 7865 | vixl32::Register out_low = LowRegisterFrom(out); |
| 7866 | vixl32::Register out_high = HighRegisterFrom(out); |
| 7867 | if (instruction->IsAnd()) { |
| 7868 | GenerateAndConst(out_low, first_low, value_low); |
| 7869 | GenerateAndConst(out_high, first_high, value_high); |
| 7870 | } else if (instruction->IsOr()) { |
| 7871 | GenerateOrrConst(out_low, first_low, value_low); |
| 7872 | GenerateOrrConst(out_high, first_high, value_high); |
| 7873 | } else { |
| 7874 | DCHECK(instruction->IsXor()); |
| 7875 | GenerateEorConst(out_low, first_low, value_low); |
| 7876 | GenerateEorConst(out_high, first_high, value_high); |
| 7877 | } |
| 7878 | } |
| 7879 | return; |
| 7880 | } |
| 7881 | |
| 7882 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 7883 | vixl32::Register first_reg = InputRegisterAt(instruction, 0); |
| 7884 | vixl32::Register second_reg = InputRegisterAt(instruction, 1); |
| 7885 | vixl32::Register out_reg = OutputRegister(instruction); |
| 7886 | if (instruction->IsAnd()) { |
| 7887 | __ And(out_reg, first_reg, second_reg); |
| 7888 | } else if (instruction->IsOr()) { |
| 7889 | __ Orr(out_reg, first_reg, second_reg); |
| 7890 | } else { |
| 7891 | DCHECK(instruction->IsXor()); |
| 7892 | __ Eor(out_reg, first_reg, second_reg); |
| 7893 | } |
| 7894 | } else { |
| 7895 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 7896 | vixl32::Register first_low = LowRegisterFrom(first); |
| 7897 | vixl32::Register first_high = HighRegisterFrom(first); |
| 7898 | vixl32::Register second_low = LowRegisterFrom(second); |
| 7899 | vixl32::Register second_high = HighRegisterFrom(second); |
| 7900 | vixl32::Register out_low = LowRegisterFrom(out); |
| 7901 | vixl32::Register out_high = HighRegisterFrom(out); |
| 7902 | if (instruction->IsAnd()) { |
| 7903 | __ And(out_low, first_low, second_low); |
| 7904 | __ And(out_high, first_high, second_high); |
| 7905 | } else if (instruction->IsOr()) { |
| 7906 | __ Orr(out_low, first_low, second_low); |
| 7907 | __ Orr(out_high, first_high, second_high); |
| 7908 | } else { |
| 7909 | DCHECK(instruction->IsXor()); |
| 7910 | __ Eor(out_low, first_low, second_low); |
| 7911 | __ Eor(out_high, first_high, second_high); |
| 7912 | } |
| 7913 | } |
| 7914 | } |
| 7915 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7916 | void InstructionCodeGeneratorARMVIXL::GenerateReferenceLoadOneRegister( |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 7917 | HInstruction* instruction, |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7918 | Location out, |
| 7919 | uint32_t offset, |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 7920 | Location maybe_temp, |
| 7921 | ReadBarrierOption read_barrier_option) { |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7922 | vixl32::Register out_reg = RegisterFrom(out); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 7923 | if (read_barrier_option == kWithReadBarrier) { |
| 7924 | CHECK(kEmitCompilerReadBarrier); |
| 7925 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
| 7926 | if (kUseBakerReadBarrier) { |
| 7927 | // Load with fast path based Baker's read barrier. |
| 7928 | // /* HeapReference<Object> */ out = *(out + offset) |
| 7929 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 7930 | instruction, out, out_reg, offset, maybe_temp, /* needs_null_check */ false); |
| 7931 | } else { |
| 7932 | // Load with slow path based read barrier. |
| 7933 | // Save the value of `out` into `maybe_temp` before overwriting it |
| 7934 | // in the following move operation, as we will need it for the |
| 7935 | // read barrier below. |
| 7936 | __ Mov(RegisterFrom(maybe_temp), out_reg); |
| 7937 | // /* HeapReference<Object> */ out = *(out + offset) |
| 7938 | GetAssembler()->LoadFromOffset(kLoadWord, out_reg, out_reg, offset); |
| 7939 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
| 7940 | } |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7941 | } else { |
| 7942 | // Plain load with no read barrier. |
| 7943 | // /* HeapReference<Object> */ out = *(out + offset) |
| 7944 | GetAssembler()->LoadFromOffset(kLoadWord, out_reg, out_reg, offset); |
| 7945 | GetAssembler()->MaybeUnpoisonHeapReference(out_reg); |
| 7946 | } |
| 7947 | } |
| 7948 | |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7949 | void InstructionCodeGeneratorARMVIXL::GenerateReferenceLoadTwoRegisters( |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 7950 | HInstruction* instruction, |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7951 | Location out, |
| 7952 | Location obj, |
| 7953 | uint32_t offset, |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 7954 | Location maybe_temp, |
| 7955 | ReadBarrierOption read_barrier_option) { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7956 | vixl32::Register out_reg = RegisterFrom(out); |
| 7957 | vixl32::Register obj_reg = RegisterFrom(obj); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 7958 | if (read_barrier_option == kWithReadBarrier) { |
| 7959 | CHECK(kEmitCompilerReadBarrier); |
| 7960 | if (kUseBakerReadBarrier) { |
| 7961 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
| 7962 | // Load with fast path based Baker's read barrier. |
| 7963 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 7964 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 7965 | instruction, out, obj_reg, offset, maybe_temp, /* needs_null_check */ false); |
| 7966 | } else { |
| 7967 | // Load with slow path based read barrier. |
| 7968 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 7969 | GetAssembler()->LoadFromOffset(kLoadWord, out_reg, obj_reg, offset); |
| 7970 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 7971 | } |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7972 | } else { |
| 7973 | // Plain load with no read barrier. |
| 7974 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 7975 | GetAssembler()->LoadFromOffset(kLoadWord, out_reg, obj_reg, offset); |
| 7976 | GetAssembler()->MaybeUnpoisonHeapReference(out_reg); |
| 7977 | } |
| 7978 | } |
| 7979 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7980 | void InstructionCodeGeneratorARMVIXL::GenerateGcRootFieldLoad( |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 7981 | HInstruction* instruction, |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7982 | Location root, |
| 7983 | vixl32::Register obj, |
| 7984 | uint32_t offset, |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7985 | ReadBarrierOption read_barrier_option) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7986 | vixl32::Register root_reg = RegisterFrom(root); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7987 | if (read_barrier_option == kWithReadBarrier) { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 7988 | DCHECK(kEmitCompilerReadBarrier); |
| 7989 | if (kUseBakerReadBarrier) { |
| 7990 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 7991 | // Baker's read barrier are used. |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 7992 | // |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 7993 | // Note that we do not actually check the value of |
| 7994 | // `GetIsGcMarking()` to decide whether to mark the loaded GC |
| 7995 | // root or not. Instead, we load into `temp` the read barrier |
| 7996 | // mark entry point corresponding to register `root`. If `temp` |
| 7997 | // is null, it means that `GetIsGcMarking()` is false, and vice |
| 7998 | // versa. |
| 7999 | // |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8000 | // temp = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8001 | // GcRoot<mirror::Object> root = *(obj+offset); // Original reference load. |
| 8002 | // if (temp != nullptr) { // <=> Thread::Current()->GetIsGcMarking() |
| 8003 | // // Slow path. |
| 8004 | // root = temp(root); // root = ReadBarrier::Mark(root); // Runtime entry point call. |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8005 | // } |
| 8006 | |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8007 | // Slow path marking the GC root `root`. The entrypoint will already be loaded in `temp`. |
| 8008 | Location temp = LocationFrom(lr); |
| 8009 | SlowPathCodeARMVIXL* slow_path = new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathARMVIXL( |
| 8010 | instruction, root, /* entrypoint */ temp); |
| 8011 | codegen_->AddSlowPath(slow_path); |
| 8012 | |
| 8013 | // temp = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 8014 | const int32_t entry_point_offset = |
| 8015 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArmPointerSize>(root.reg()); |
| 8016 | // Loading the entrypoint does not require a load acquire since it is only changed when |
| 8017 | // threads are suspended or running a checkpoint. |
| 8018 | GetAssembler()->LoadFromOffset(kLoadWord, RegisterFrom(temp), tr, entry_point_offset); |
| 8019 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8020 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 8021 | GetAssembler()->LoadFromOffset(kLoadWord, root_reg, obj, offset); |
| 8022 | static_assert( |
| 8023 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 8024 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 8025 | "have different sizes."); |
| 8026 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 8027 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 8028 | "have different sizes."); |
| 8029 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8030 | // The entrypoint is null when the GC is not marking, this prevents one load compared to |
| 8031 | // checking GetIsGcMarking. |
| 8032 | __ CompareAndBranchIfNonZero(RegisterFrom(temp), slow_path->GetEntryLabel()); |
| 8033 | __ Bind(slow_path->GetExitLabel()); |
| 8034 | } else { |
| 8035 | // GC root loaded through a slow path for read barriers other |
| 8036 | // than Baker's. |
| 8037 | // /* GcRoot<mirror::Object>* */ root = obj + offset |
| 8038 | __ Add(root_reg, obj, offset); |
| 8039 | // /* mirror::Object* */ root = root->Read() |
| 8040 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 8041 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 8042 | } else { |
| 8043 | // Plain GC root load with no read barrier. |
| 8044 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 8045 | GetAssembler()->LoadFromOffset(kLoadWord, root_reg, obj, offset); |
| 8046 | // Note that GC roots are not affected by heap poisoning, thus we |
| 8047 | // do not have to unpoison `root_reg` here. |
| 8048 | } |
| 8049 | } |
| 8050 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8051 | void CodeGeneratorARMVIXL::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 8052 | Location ref, |
| 8053 | vixl32::Register obj, |
| 8054 | uint32_t offset, |
| 8055 | Location temp, |
| 8056 | bool needs_null_check) { |
| 8057 | DCHECK(kEmitCompilerReadBarrier); |
| 8058 | DCHECK(kUseBakerReadBarrier); |
| 8059 | |
| 8060 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 8061 | Location no_index = Location::NoLocation(); |
| 8062 | ScaleFactor no_scale_factor = TIMES_1; |
| 8063 | GenerateReferenceLoadWithBakerReadBarrier( |
| 8064 | 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] | 8065 | } |
| 8066 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8067 | void CodeGeneratorARMVIXL::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 8068 | Location ref, |
| 8069 | vixl32::Register obj, |
| 8070 | uint32_t data_offset, |
| 8071 | Location index, |
| 8072 | Location temp, |
| 8073 | bool needs_null_check) { |
| 8074 | DCHECK(kEmitCompilerReadBarrier); |
| 8075 | DCHECK(kUseBakerReadBarrier); |
| 8076 | |
| 8077 | static_assert( |
| 8078 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 8079 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 8080 | // /* HeapReference<Object> */ ref = |
| 8081 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 8082 | ScaleFactor scale_factor = TIMES_4; |
| 8083 | GenerateReferenceLoadWithBakerReadBarrier( |
| 8084 | instruction, ref, obj, data_offset, index, scale_factor, temp, needs_null_check); |
Roland Levillain | 6070e88 | 2016-11-03 17:51:58 +0000 | [diff] [blame] | 8085 | } |
| 8086 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8087 | void CodeGeneratorARMVIXL::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 8088 | Location ref, |
| 8089 | vixl32::Register obj, |
| 8090 | uint32_t offset, |
| 8091 | Location index, |
| 8092 | ScaleFactor scale_factor, |
| 8093 | Location temp, |
| 8094 | bool needs_null_check, |
| 8095 | bool always_update_field, |
| 8096 | vixl32::Register* temp2) { |
| 8097 | DCHECK(kEmitCompilerReadBarrier); |
| 8098 | DCHECK(kUseBakerReadBarrier); |
| 8099 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 8100 | // Query `art::Thread::Current()->GetIsGcMarking()` to decide |
| 8101 | // whether we need to enter the slow path to mark the reference. |
| 8102 | // Then, in the slow path, check the gray bit in the lock word of |
| 8103 | // the reference's holder (`obj`) to decide whether to mark `ref` or |
| 8104 | // not. |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8105 | // |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8106 | // Note that we do not actually check the value of `GetIsGcMarking()`; |
| 8107 | // instead, we load into `temp3` the read barrier mark entry point |
| 8108 | // corresponding to register `ref`. If `temp3` is null, it means |
| 8109 | // that `GetIsGcMarking()` is false, and vice versa. |
| 8110 | // |
| 8111 | // temp3 = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8112 | // if (temp3 != nullptr) { // <=> Thread::Current()->GetIsGcMarking() |
| 8113 | // // Slow path. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 8114 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 8115 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 8116 | // HeapReference<mirror::Object> ref = *src; // Original reference load. |
| 8117 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 8118 | // if (is_gray) { |
| 8119 | // ref = temp3(ref); // ref = ReadBarrier::Mark(ref); // Runtime entry point call. |
| 8120 | // } |
| 8121 | // } else { |
| 8122 | // HeapReference<mirror::Object> ref = *src; // Original reference load. |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8123 | // } |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8124 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8125 | vixl32::Register temp_reg = RegisterFrom(temp); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8126 | |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8127 | // Slow path marking the object `ref` when the GC is marking. The |
| 8128 | // entrypoint will already be loaded in `temp3`. |
| 8129 | Location temp3 = LocationFrom(lr); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8130 | SlowPathCodeARMVIXL* slow_path; |
| 8131 | if (always_update_field) { |
| 8132 | DCHECK(temp2 != nullptr); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 8133 | // LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARMVIXL |
| 8134 | // only supports address of the form `obj + field_offset`, where |
| 8135 | // `obj` is a register and `field_offset` is a register pair (of |
| 8136 | // which only the lower half is used). Thus `offset` and |
| 8137 | // `scale_factor` above are expected to be null in this code path. |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8138 | DCHECK_EQ(offset, 0u); |
| 8139 | DCHECK_EQ(scale_factor, ScaleFactor::TIMES_1); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 8140 | Location field_offset = index; |
| 8141 | slow_path = |
| 8142 | new (GetGraph()->GetArena()) LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARMVIXL( |
| 8143 | instruction, |
| 8144 | ref, |
| 8145 | obj, |
| 8146 | offset, |
| 8147 | /* index */ field_offset, |
| 8148 | scale_factor, |
| 8149 | needs_null_check, |
| 8150 | temp_reg, |
| 8151 | *temp2, |
| 8152 | /* entrypoint */ temp3); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8153 | } else { |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 8154 | slow_path = new (GetGraph()->GetArena()) LoadReferenceWithBakerReadBarrierSlowPathARMVIXL( |
| 8155 | instruction, |
| 8156 | ref, |
| 8157 | obj, |
| 8158 | offset, |
| 8159 | index, |
| 8160 | scale_factor, |
| 8161 | needs_null_check, |
| 8162 | temp_reg, |
| 8163 | /* entrypoint */ temp3); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8164 | } |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8165 | AddSlowPath(slow_path); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8166 | |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8167 | // temp3 = Thread::Current()->pReadBarrierMarkReg ## ref.reg() |
| 8168 | const int32_t entry_point_offset = |
| 8169 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArmPointerSize>(ref.reg()); |
| 8170 | // Loading the entrypoint does not require a load acquire since it is only changed when |
| 8171 | // threads are suspended or running a checkpoint. |
| 8172 | GetAssembler()->LoadFromOffset(kLoadWord, RegisterFrom(temp3), tr, entry_point_offset); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8173 | // The entrypoint is null when the GC is not marking, this prevents one load compared to |
| 8174 | // checking GetIsGcMarking. |
| 8175 | __ CompareAndBranchIfNonZero(RegisterFrom(temp3), slow_path->GetEntryLabel()); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 8176 | // Fast path: just load the reference. |
| 8177 | GenerateRawReferenceLoad(instruction, ref, obj, offset, index, scale_factor, needs_null_check); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8178 | __ Bind(slow_path->GetExitLabel()); |
Roland Levillain | 844e653 | 2016-11-03 16:09:47 +0000 | [diff] [blame] | 8179 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8180 | |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8181 | void CodeGeneratorARMVIXL::GenerateRawReferenceLoad(HInstruction* instruction, |
| 8182 | Location ref, |
| 8183 | vixl::aarch32::Register obj, |
| 8184 | uint32_t offset, |
| 8185 | Location index, |
| 8186 | ScaleFactor scale_factor, |
| 8187 | bool needs_null_check) { |
| 8188 | Primitive::Type type = Primitive::kPrimNot; |
| 8189 | vixl32::Register ref_reg = RegisterFrom(ref, type); |
| 8190 | |
| 8191 | // If needed, vixl::EmissionCheckScope guards are used to ensure |
| 8192 | // that no pools are emitted between the load (macro) instruction |
| 8193 | // and MaybeRecordImplicitNullCheck. |
| 8194 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8195 | if (index.IsValid()) { |
| 8196 | // Load types involving an "index": ArrayGet, |
| 8197 | // UnsafeGetObject/UnsafeGetObjectVolatile and UnsafeCASObject |
| 8198 | // intrinsics. |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8199 | // /* HeapReference<mirror::Object> */ ref = *(obj + offset + (index << scale_factor)) |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8200 | if (index.IsConstant()) { |
| 8201 | size_t computed_offset = |
| 8202 | (Int32ConstantFrom(index) << scale_factor) + offset; |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8203 | vixl::EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8204 | GetAssembler()->LoadFromOffset(kLoadWord, ref_reg, obj, computed_offset); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8205 | if (needs_null_check) { |
| 8206 | MaybeRecordImplicitNullCheck(instruction); |
| 8207 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8208 | } else { |
| 8209 | // Handle the special case of the |
| 8210 | // UnsafeGetObject/UnsafeGetObjectVolatile and UnsafeCASObject |
| 8211 | // intrinsics, which use a register pair as index ("long |
| 8212 | // offset"), of which only the low part contains data. |
| 8213 | vixl32::Register index_reg = index.IsRegisterPair() |
| 8214 | ? LowRegisterFrom(index) |
| 8215 | : RegisterFrom(index); |
| 8216 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8217 | vixl32::Register temp = temps.Acquire(); |
| 8218 | __ Add(temp, obj, Operand(index_reg, ShiftType::LSL, scale_factor)); |
| 8219 | { |
| 8220 | vixl::EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 8221 | GetAssembler()->LoadFromOffset(kLoadWord, ref_reg, temp, offset); |
| 8222 | if (needs_null_check) { |
| 8223 | MaybeRecordImplicitNullCheck(instruction); |
| 8224 | } |
| 8225 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8226 | } |
| 8227 | } else { |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8228 | // /* HeapReference<mirror::Object> */ ref = *(obj + offset) |
| 8229 | vixl::EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8230 | GetAssembler()->LoadFromOffset(kLoadWord, ref_reg, obj, offset); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8231 | if (needs_null_check) { |
| 8232 | MaybeRecordImplicitNullCheck(instruction); |
| 8233 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8234 | } |
| 8235 | |
Roland Levillain | 844e653 | 2016-11-03 16:09:47 +0000 | [diff] [blame] | 8236 | // Object* ref = ref_addr->AsMirrorPtr() |
| 8237 | GetAssembler()->MaybeUnpoisonHeapReference(ref_reg); |
Roland Levillain | 844e653 | 2016-11-03 16:09:47 +0000 | [diff] [blame] | 8238 | } |
| 8239 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8240 | void CodeGeneratorARMVIXL::GenerateReadBarrierSlow(HInstruction* instruction, |
| 8241 | Location out, |
| 8242 | Location ref, |
| 8243 | Location obj, |
| 8244 | uint32_t offset, |
| 8245 | Location index) { |
| 8246 | DCHECK(kEmitCompilerReadBarrier); |
| 8247 | |
| 8248 | // Insert a slow path based read barrier *after* the reference load. |
| 8249 | // |
| 8250 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 8251 | // reference will be carried out by the runtime within the slow |
| 8252 | // path. |
| 8253 | // |
| 8254 | // Note that `ref` currently does not get unpoisoned (when heap |
| 8255 | // poisoning is enabled), which is alright as the `ref` argument is |
| 8256 | // not used by the artReadBarrierSlow entry point. |
| 8257 | // |
| 8258 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
| 8259 | SlowPathCodeARMVIXL* slow_path = new (GetGraph()->GetArena()) |
| 8260 | ReadBarrierForHeapReferenceSlowPathARMVIXL(instruction, out, ref, obj, offset, index); |
| 8261 | AddSlowPath(slow_path); |
| 8262 | |
| 8263 | __ B(slow_path->GetEntryLabel()); |
| 8264 | __ Bind(slow_path->GetExitLabel()); |
| 8265 | } |
| 8266 | |
| 8267 | void CodeGeneratorARMVIXL::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 8268 | Location out, |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8269 | Location ref, |
| 8270 | Location obj, |
| 8271 | uint32_t offset, |
| 8272 | Location index) { |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 8273 | if (kEmitCompilerReadBarrier) { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8274 | // Baker's read barriers shall be handled by the fast path |
| 8275 | // (CodeGeneratorARM::GenerateReferenceLoadWithBakerReadBarrier). |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 8276 | DCHECK(!kUseBakerReadBarrier); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8277 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 8278 | // by the runtime within the slow path. |
| 8279 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 8280 | } else if (kPoisonHeapReferences) { |
| 8281 | GetAssembler()->UnpoisonHeapReference(RegisterFrom(out)); |
| 8282 | } |
| 8283 | } |
| 8284 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8285 | void CodeGeneratorARMVIXL::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 8286 | Location out, |
| 8287 | Location root) { |
| 8288 | DCHECK(kEmitCompilerReadBarrier); |
| 8289 | |
| 8290 | // Insert a slow path based read barrier *after* the GC root load. |
| 8291 | // |
| 8292 | // Note that GC roots are not affected by heap poisoning, so we do |
| 8293 | // not need to do anything special for this here. |
| 8294 | SlowPathCodeARMVIXL* slow_path = |
| 8295 | new (GetGraph()->GetArena()) ReadBarrierForRootSlowPathARMVIXL(instruction, out, root); |
| 8296 | AddSlowPath(slow_path); |
| 8297 | |
| 8298 | __ B(slow_path->GetEntryLabel()); |
| 8299 | __ Bind(slow_path->GetExitLabel()); |
| 8300 | } |
| 8301 | |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 8302 | // Check if the desired_dispatch_info is supported. If it is, return it, |
| 8303 | // otherwise return a fall-back info that should be used instead. |
| 8304 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorARMVIXL::GetSupportedInvokeStaticOrDirectDispatch( |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8305 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
Nicolas Geoffray | c1a42cf | 2016-12-18 15:52:36 +0000 | [diff] [blame] | 8306 | HInvokeStaticOrDirect* invoke ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | e807ff7 | 2017-01-23 09:03:12 +0000 | [diff] [blame] | 8307 | return desired_dispatch_info; |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 8308 | } |
| 8309 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8310 | vixl32::Register CodeGeneratorARMVIXL::GetInvokeStaticOrDirectExtraParameter( |
| 8311 | HInvokeStaticOrDirect* invoke, vixl32::Register temp) { |
| 8312 | DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
| 8313 | Location location = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
| 8314 | if (!invoke->GetLocations()->Intrinsified()) { |
| 8315 | return RegisterFrom(location); |
| 8316 | } |
| 8317 | // For intrinsics we allow any location, so it may be on the stack. |
| 8318 | if (!location.IsRegister()) { |
| 8319 | GetAssembler()->LoadFromOffset(kLoadWord, temp, sp, location.GetStackIndex()); |
| 8320 | return temp; |
| 8321 | } |
| 8322 | // For register locations, check if the register was saved. If so, get it from the stack. |
| 8323 | // Note: There is a chance that the register was saved but not overwritten, so we could |
| 8324 | // save one load. However, since this is just an intrinsic slow path we prefer this |
| 8325 | // simple and more robust approach rather that trying to determine if that's the case. |
| 8326 | SlowPathCode* slow_path = GetCurrentSlowPath(); |
Scott Wakeling | d5cd497 | 2017-02-03 11:38:35 +0000 | [diff] [blame] | 8327 | if (slow_path != nullptr && slow_path->IsCoreRegisterSaved(RegisterFrom(location).GetCode())) { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8328 | int stack_offset = slow_path->GetStackOffsetOfCoreRegister(RegisterFrom(location).GetCode()); |
| 8329 | GetAssembler()->LoadFromOffset(kLoadWord, temp, sp, stack_offset); |
| 8330 | return temp; |
| 8331 | } |
| 8332 | return RegisterFrom(location); |
| 8333 | } |
| 8334 | |
TatWai Chong | d8c052a | 2016-11-02 16:12:48 +0800 | [diff] [blame] | 8335 | Location CodeGeneratorARMVIXL::GenerateCalleeMethodStaticOrDirectCall( |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8336 | HInvokeStaticOrDirect* invoke, Location temp) { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8337 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8338 | switch (invoke->GetMethodLoadKind()) { |
| 8339 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: { |
| 8340 | uint32_t offset = |
| 8341 | GetThreadOffset<kArmPointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
| 8342 | // temp = thread->string_init_entrypoint |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8343 | GetAssembler()->LoadFromOffset(kLoadWord, RegisterFrom(temp), tr, offset); |
| 8344 | break; |
| 8345 | } |
| 8346 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
| 8347 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
| 8348 | break; |
| 8349 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 8350 | __ Mov(RegisterFrom(temp), Operand::From(invoke->GetMethodAddress())); |
| 8351 | break; |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8352 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: { |
| 8353 | HArmDexCacheArraysBase* base = |
| 8354 | invoke->InputAt(invoke->GetSpecialInputIndex())->AsArmDexCacheArraysBase(); |
| 8355 | vixl32::Register base_reg = GetInvokeStaticOrDirectExtraParameter(invoke, RegisterFrom(temp)); |
| 8356 | int32_t offset = invoke->GetDexCacheArrayOffset() - base->GetElementOffset(); |
| 8357 | GetAssembler()->LoadFromOffset(kLoadWord, RegisterFrom(temp), base_reg, offset); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8358 | break; |
| 8359 | } |
| 8360 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: { |
| 8361 | Location current_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
| 8362 | vixl32::Register method_reg; |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8363 | vixl32::Register reg = RegisterFrom(temp); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8364 | if (current_method.IsRegister()) { |
| 8365 | method_reg = RegisterFrom(current_method); |
| 8366 | } else { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8367 | DCHECK(invoke->GetLocations()->Intrinsified()); |
| 8368 | DCHECK(!current_method.IsValid()); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8369 | method_reg = reg; |
| 8370 | GetAssembler()->LoadFromOffset(kLoadWord, reg, sp, kCurrentMethodStackOffset); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8371 | } |
| 8372 | // /* ArtMethod*[] */ temp = temp.ptr_sized_fields_->dex_cache_resolved_methods_; |
| 8373 | GetAssembler()->LoadFromOffset( |
| 8374 | kLoadWord, |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8375 | reg, |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8376 | method_reg, |
| 8377 | ArtMethod::DexCacheResolvedMethodsOffset(kArmPointerSize).Int32Value()); |
| 8378 | // temp = temp[index_in_cache]; |
| 8379 | // Note: Don't use invoke->GetTargetMethod() as it may point to a different dex file. |
| 8380 | uint32_t index_in_cache = invoke->GetDexMethodIndex(); |
| 8381 | GetAssembler()->LoadFromOffset( |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8382 | kLoadWord, reg, reg, CodeGenerator::GetCachePointerOffset(index_in_cache)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8383 | break; |
| 8384 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8385 | } |
TatWai Chong | d8c052a | 2016-11-02 16:12:48 +0800 | [diff] [blame] | 8386 | return callee_method; |
| 8387 | } |
| 8388 | |
| 8389 | void CodeGeneratorARMVIXL::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, |
| 8390 | Location temp) { |
| 8391 | Location callee_method = GenerateCalleeMethodStaticOrDirectCall(invoke, temp); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8392 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8393 | switch (invoke->GetCodePtrLocation()) { |
| 8394 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 8395 | __ Bl(GetFrameEntryLabel()); |
| 8396 | break; |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8397 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 8398 | // LR = callee_method->entry_point_from_quick_compiled_code_ |
| 8399 | GetAssembler()->LoadFromOffset( |
| 8400 | kLoadWord, |
| 8401 | lr, |
| 8402 | RegisterFrom(callee_method), |
| 8403 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize).Int32Value()); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 8404 | { |
| 8405 | // 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] | 8406 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 8407 | vixl32::k16BitT32InstructionSizeInBytes, |
| 8408 | CodeBufferCheckScope::kExactSize); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 8409 | // LR() |
| 8410 | __ blx(lr); |
| 8411 | } |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8412 | break; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8413 | } |
| 8414 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8415 | DCHECK(!IsLeafMethod()); |
| 8416 | } |
| 8417 | |
| 8418 | void CodeGeneratorARMVIXL::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_location) { |
| 8419 | vixl32::Register temp = RegisterFrom(temp_location); |
| 8420 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 8421 | invoke->GetVTableIndex(), kArmPointerSize).Uint32Value(); |
| 8422 | |
| 8423 | // Use the calling convention instead of the location of the receiver, as |
| 8424 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 8425 | // slow path, the arguments have been moved to the right place, so here we are |
| 8426 | // guaranteed that the receiver is the first register of the calling convention. |
| 8427 | InvokeDexCallingConventionARMVIXL calling_convention; |
| 8428 | vixl32::Register receiver = calling_convention.GetRegisterAt(0); |
| 8429 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 8430 | { |
| 8431 | // Make sure the pc is recorded immediately after the `ldr` instruction. |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 8432 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 8433 | vixl32::kMaxInstructionSizeInBytes, |
| 8434 | CodeBufferCheckScope::kMaximumSize); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 8435 | // /* HeapReference<Class> */ temp = receiver->klass_ |
| 8436 | __ ldr(temp, MemOperand(receiver, class_offset)); |
| 8437 | MaybeRecordImplicitNullCheck(invoke); |
| 8438 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8439 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 8440 | // emit a read barrier for the previous class reference load. |
| 8441 | // However this is not required in practice, as this is an |
| 8442 | // intermediate/temporary reference and because the current |
| 8443 | // concurrent copying collector keeps the from-space memory |
| 8444 | // intact/accessible until the end of the marking phase (the |
| 8445 | // concurrent copying collector may not in the future). |
| 8446 | GetAssembler()->MaybeUnpoisonHeapReference(temp); |
| 8447 | |
| 8448 | // temp = temp->GetMethodAt(method_offset); |
| 8449 | uint32_t entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
| 8450 | kArmPointerSize).Int32Value(); |
| 8451 | GetAssembler()->LoadFromOffset(kLoadWord, temp, temp, method_offset); |
| 8452 | // LR = temp->GetEntryPoint(); |
| 8453 | GetAssembler()->LoadFromOffset(kLoadWord, lr, temp, entry_point); |
| 8454 | // LR(); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 8455 | // This `blx` *must* be the *last* instruction generated by this stub, so that calls to |
| 8456 | // `RecordPcInfo()` immediately following record the correct pc. Use a scope to help guarantee |
| 8457 | // that. |
| 8458 | // 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] | 8459 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 8460 | vixl32::k16BitT32InstructionSizeInBytes, |
| 8461 | CodeBufferCheckScope::kExactSize); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 8462 | __ blx(lr); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8463 | } |
| 8464 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8465 | CodeGeneratorARMVIXL::PcRelativePatchInfo* CodeGeneratorARMVIXL::NewPcRelativeStringPatch( |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 8466 | const DexFile& dex_file, dex::StringIndex string_index) { |
| 8467 | return NewPcRelativePatch(dex_file, string_index.index_, &pc_relative_string_patches_); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8468 | } |
| 8469 | |
| 8470 | CodeGeneratorARMVIXL::PcRelativePatchInfo* CodeGeneratorARMVIXL::NewPcRelativeTypePatch( |
| 8471 | const DexFile& dex_file, dex::TypeIndex type_index) { |
| 8472 | return NewPcRelativePatch(dex_file, type_index.index_, &pc_relative_type_patches_); |
| 8473 | } |
| 8474 | |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 8475 | CodeGeneratorARMVIXL::PcRelativePatchInfo* CodeGeneratorARMVIXL::NewTypeBssEntryPatch( |
| 8476 | const DexFile& dex_file, dex::TypeIndex type_index) { |
| 8477 | return NewPcRelativePatch(dex_file, type_index.index_, &type_bss_entry_patches_); |
| 8478 | } |
| 8479 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8480 | CodeGeneratorARMVIXL::PcRelativePatchInfo* CodeGeneratorARMVIXL::NewPcRelativeDexCacheArrayPatch( |
| 8481 | const DexFile& dex_file, uint32_t element_offset) { |
| 8482 | return NewPcRelativePatch(dex_file, element_offset, &pc_relative_dex_cache_patches_); |
| 8483 | } |
| 8484 | |
| 8485 | CodeGeneratorARMVIXL::PcRelativePatchInfo* CodeGeneratorARMVIXL::NewPcRelativePatch( |
| 8486 | const DexFile& dex_file, uint32_t offset_or_index, ArenaDeque<PcRelativePatchInfo>* patches) { |
| 8487 | patches->emplace_back(dex_file, offset_or_index); |
| 8488 | return &patches->back(); |
| 8489 | } |
| 8490 | |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 8491 | VIXLUInt32Literal* CodeGeneratorARMVIXL::DeduplicateBootImageStringLiteral( |
| 8492 | const DexFile& dex_file, |
| 8493 | dex::StringIndex string_index) { |
| 8494 | return boot_image_string_patches_.GetOrCreate( |
| 8495 | StringReference(&dex_file, string_index), |
| 8496 | [this]() { |
| 8497 | return GetAssembler()->CreateLiteralDestroyedWithPool<uint32_t>(/* placeholder */ 0u); |
| 8498 | }); |
| 8499 | } |
| 8500 | |
| 8501 | VIXLUInt32Literal* CodeGeneratorARMVIXL::DeduplicateBootImageTypeLiteral( |
| 8502 | const DexFile& dex_file, |
| 8503 | dex::TypeIndex type_index) { |
| 8504 | return boot_image_type_patches_.GetOrCreate( |
| 8505 | TypeReference(&dex_file, type_index), |
| 8506 | [this]() { |
| 8507 | return GetAssembler()->CreateLiteralDestroyedWithPool<uint32_t>(/* placeholder */ 0u); |
| 8508 | }); |
| 8509 | } |
| 8510 | |
| 8511 | VIXLUInt32Literal* CodeGeneratorARMVIXL::DeduplicateBootImageAddressLiteral(uint32_t address) { |
Richard Uhler | c52f303 | 2017-03-02 13:45:45 +0000 | [diff] [blame] | 8512 | return DeduplicateUint32Literal(dchecked_integral_cast<uint32_t>(address), &uint32_literals_); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 8513 | } |
| 8514 | |
| 8515 | VIXLUInt32Literal* CodeGeneratorARMVIXL::DeduplicateDexCacheAddressLiteral(uint32_t address) { |
| 8516 | return DeduplicateUint32Literal(address, &uint32_literals_); |
| 8517 | } |
| 8518 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 8519 | VIXLUInt32Literal* CodeGeneratorARMVIXL::DeduplicateJitStringLiteral( |
| 8520 | const DexFile& dex_file, |
| 8521 | dex::StringIndex string_index, |
| 8522 | Handle<mirror::String> handle) { |
| 8523 | jit_string_roots_.Overwrite(StringReference(&dex_file, string_index), |
| 8524 | reinterpret_cast64<uint64_t>(handle.GetReference())); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 8525 | return jit_string_patches_.GetOrCreate( |
| 8526 | StringReference(&dex_file, string_index), |
| 8527 | [this]() { |
| 8528 | return GetAssembler()->CreateLiteralDestroyedWithPool<uint32_t>(/* placeholder */ 0u); |
| 8529 | }); |
| 8530 | } |
| 8531 | |
| 8532 | VIXLUInt32Literal* CodeGeneratorARMVIXL::DeduplicateJitClassLiteral(const DexFile& dex_file, |
| 8533 | dex::TypeIndex type_index, |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 8534 | Handle<mirror::Class> handle) { |
| 8535 | jit_class_roots_.Overwrite(TypeReference(&dex_file, type_index), |
| 8536 | reinterpret_cast64<uint64_t>(handle.GetReference())); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 8537 | return jit_class_patches_.GetOrCreate( |
| 8538 | TypeReference(&dex_file, type_index), |
| 8539 | [this]() { |
| 8540 | return GetAssembler()->CreateLiteralDestroyedWithPool<uint32_t>(/* placeholder */ 0u); |
| 8541 | }); |
| 8542 | } |
| 8543 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8544 | template <LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
| 8545 | inline void CodeGeneratorARMVIXL::EmitPcRelativeLinkerPatches( |
| 8546 | const ArenaDeque<PcRelativePatchInfo>& infos, |
| 8547 | ArenaVector<LinkerPatch>* linker_patches) { |
| 8548 | for (const PcRelativePatchInfo& info : infos) { |
| 8549 | const DexFile& dex_file = info.target_dex_file; |
| 8550 | size_t offset_or_index = info.offset_or_index; |
| 8551 | DCHECK(info.add_pc_label.IsBound()); |
| 8552 | uint32_t add_pc_offset = dchecked_integral_cast<uint32_t>(info.add_pc_label.GetLocation()); |
| 8553 | // Add MOVW patch. |
| 8554 | DCHECK(info.movw_label.IsBound()); |
| 8555 | uint32_t movw_offset = dchecked_integral_cast<uint32_t>(info.movw_label.GetLocation()); |
| 8556 | linker_patches->push_back(Factory(movw_offset, &dex_file, add_pc_offset, offset_or_index)); |
| 8557 | // Add MOVT patch. |
| 8558 | DCHECK(info.movt_label.IsBound()); |
| 8559 | uint32_t movt_offset = dchecked_integral_cast<uint32_t>(info.movt_label.GetLocation()); |
| 8560 | linker_patches->push_back(Factory(movt_offset, &dex_file, add_pc_offset, offset_or_index)); |
| 8561 | } |
| 8562 | } |
| 8563 | |
| 8564 | void CodeGeneratorARMVIXL::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) { |
| 8565 | DCHECK(linker_patches->empty()); |
| 8566 | size_t size = |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8567 | /* MOVW+MOVT for each entry */ 2u * pc_relative_dex_cache_patches_.size() + |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 8568 | boot_image_string_patches_.size() + |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8569 | /* MOVW+MOVT for each entry */ 2u * pc_relative_string_patches_.size() + |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 8570 | boot_image_type_patches_.size() + |
| 8571 | /* MOVW+MOVT for each entry */ 2u * pc_relative_type_patches_.size() + |
Richard Uhler | c52f303 | 2017-03-02 13:45:45 +0000 | [diff] [blame] | 8572 | /* MOVW+MOVT for each entry */ 2u * type_bss_entry_patches_.size(); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8573 | linker_patches->reserve(size); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8574 | EmitPcRelativeLinkerPatches<LinkerPatch::DexCacheArrayPatch>(pc_relative_dex_cache_patches_, |
| 8575 | linker_patches); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 8576 | for (const auto& entry : boot_image_string_patches_) { |
| 8577 | const StringReference& target_string = entry.first; |
| 8578 | VIXLUInt32Literal* literal = entry.second; |
| 8579 | DCHECK(literal->IsBound()); |
| 8580 | uint32_t literal_offset = literal->GetLocation(); |
| 8581 | linker_patches->push_back(LinkerPatch::StringPatch(literal_offset, |
| 8582 | target_string.dex_file, |
| 8583 | target_string.string_index.index_)); |
| 8584 | } |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8585 | if (!GetCompilerOptions().IsBootImage()) { |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 8586 | DCHECK(pc_relative_type_patches_.empty()); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8587 | EmitPcRelativeLinkerPatches<LinkerPatch::StringBssEntryPatch>(pc_relative_string_patches_, |
| 8588 | linker_patches); |
| 8589 | } else { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 8590 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeTypePatch>(pc_relative_type_patches_, |
| 8591 | linker_patches); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8592 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeStringPatch>(pc_relative_string_patches_, |
| 8593 | linker_patches); |
| 8594 | } |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 8595 | EmitPcRelativeLinkerPatches<LinkerPatch::TypeBssEntryPatch>(type_bss_entry_patches_, |
| 8596 | linker_patches); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 8597 | for (const auto& entry : boot_image_type_patches_) { |
| 8598 | const TypeReference& target_type = entry.first; |
| 8599 | VIXLUInt32Literal* literal = entry.second; |
| 8600 | DCHECK(literal->IsBound()); |
| 8601 | uint32_t literal_offset = literal->GetLocation(); |
| 8602 | linker_patches->push_back(LinkerPatch::TypePatch(literal_offset, |
| 8603 | target_type.dex_file, |
| 8604 | target_type.type_index.index_)); |
| 8605 | } |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 8606 | DCHECK_EQ(size, linker_patches->size()); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 8607 | } |
| 8608 | |
| 8609 | VIXLUInt32Literal* CodeGeneratorARMVIXL::DeduplicateUint32Literal( |
| 8610 | uint32_t value, |
| 8611 | Uint32ToLiteralMap* map) { |
| 8612 | return map->GetOrCreate( |
| 8613 | value, |
| 8614 | [this, value]() { |
| 8615 | return GetAssembler()->CreateLiteralDestroyedWithPool<uint32_t>(/* placeholder */ value); |
| 8616 | }); |
| 8617 | } |
| 8618 | |
| 8619 | VIXLUInt32Literal* CodeGeneratorARMVIXL::DeduplicateMethodLiteral( |
| 8620 | MethodReference target_method, |
| 8621 | MethodToLiteralMap* map) { |
| 8622 | return map->GetOrCreate( |
| 8623 | target_method, |
| 8624 | [this]() { |
| 8625 | return GetAssembler()->CreateLiteralDestroyedWithPool<uint32_t>(/* placeholder */ 0u); |
| 8626 | }); |
| 8627 | } |
| 8628 | |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 8629 | void LocationsBuilderARMVIXL::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
| 8630 | LocationSummary* locations = |
| 8631 | new (GetGraph()->GetArena()) LocationSummary(instr, LocationSummary::kNoCall); |
| 8632 | locations->SetInAt(HMultiplyAccumulate::kInputAccumulatorIndex, |
| 8633 | Location::RequiresRegister()); |
| 8634 | locations->SetInAt(HMultiplyAccumulate::kInputMulLeftIndex, Location::RequiresRegister()); |
| 8635 | locations->SetInAt(HMultiplyAccumulate::kInputMulRightIndex, Location::RequiresRegister()); |
| 8636 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 8637 | } |
| 8638 | |
| 8639 | void InstructionCodeGeneratorARMVIXL::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
| 8640 | vixl32::Register res = OutputRegister(instr); |
| 8641 | vixl32::Register accumulator = |
| 8642 | InputRegisterAt(instr, HMultiplyAccumulate::kInputAccumulatorIndex); |
| 8643 | vixl32::Register mul_left = |
| 8644 | InputRegisterAt(instr, HMultiplyAccumulate::kInputMulLeftIndex); |
| 8645 | vixl32::Register mul_right = |
| 8646 | InputRegisterAt(instr, HMultiplyAccumulate::kInputMulRightIndex); |
| 8647 | |
| 8648 | if (instr->GetOpKind() == HInstruction::kAdd) { |
| 8649 | __ Mla(res, mul_left, mul_right, accumulator); |
| 8650 | } else { |
| 8651 | __ Mls(res, mul_left, mul_right, accumulator); |
| 8652 | } |
| 8653 | } |
| 8654 | |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 8655 | void LocationsBuilderARMVIXL::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
| 8656 | // Nothing to do, this should be removed during prepare for register allocator. |
| 8657 | LOG(FATAL) << "Unreachable"; |
| 8658 | } |
| 8659 | |
| 8660 | void InstructionCodeGeneratorARMVIXL::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
| 8661 | // Nothing to do, this should be removed during prepare for register allocator. |
| 8662 | LOG(FATAL) << "Unreachable"; |
| 8663 | } |
| 8664 | |
| 8665 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 8666 | void LocationsBuilderARMVIXL::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 8667 | LocationSummary* locations = |
| 8668 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 8669 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8670 | if (switch_instr->GetNumEntries() > kPackedSwitchCompareJumpThreshold && |
| 8671 | codegen_->GetAssembler()->GetVIXLAssembler()->IsUsingT32()) { |
| 8672 | locations->AddTemp(Location::RequiresRegister()); // We need a temp for the table base. |
| 8673 | if (switch_instr->GetStartValue() != 0) { |
| 8674 | locations->AddTemp(Location::RequiresRegister()); // We need a temp for the bias. |
| 8675 | } |
| 8676 | } |
| 8677 | } |
| 8678 | |
| 8679 | // TODO(VIXL): Investigate and reach the parity with old arm codegen. |
| 8680 | void InstructionCodeGeneratorARMVIXL::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 8681 | int32_t lower_bound = switch_instr->GetStartValue(); |
| 8682 | uint32_t num_entries = switch_instr->GetNumEntries(); |
| 8683 | LocationSummary* locations = switch_instr->GetLocations(); |
| 8684 | vixl32::Register value_reg = InputRegisterAt(switch_instr, 0); |
| 8685 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 8686 | |
| 8687 | if (num_entries <= kPackedSwitchCompareJumpThreshold || |
| 8688 | !codegen_->GetAssembler()->GetVIXLAssembler()->IsUsingT32()) { |
| 8689 | // Create a series of compare/jumps. |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8690 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 8691 | vixl32::Register temp_reg = temps.Acquire(); |
| 8692 | // Note: It is fine for the below AddConstantSetFlags() using IP register to temporarily store |
| 8693 | // the immediate, because IP is used as the destination register. For the other |
| 8694 | // AddConstantSetFlags() and GenerateCompareWithImmediate(), the immediate values are constant, |
| 8695 | // and they can be encoded in the instruction without making use of IP register. |
| 8696 | __ Adds(temp_reg, value_reg, -lower_bound); |
| 8697 | |
| 8698 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
| 8699 | // Jump to successors[0] if value == lower_bound. |
| 8700 | __ B(eq, codegen_->GetLabelOf(successors[0])); |
| 8701 | int32_t last_index = 0; |
| 8702 | for (; num_entries - last_index > 2; last_index += 2) { |
| 8703 | __ Adds(temp_reg, temp_reg, -2); |
| 8704 | // Jump to successors[last_index + 1] if value < case_value[last_index + 2]. |
| 8705 | __ B(lo, codegen_->GetLabelOf(successors[last_index + 1])); |
| 8706 | // Jump to successors[last_index + 2] if value == case_value[last_index + 2]. |
| 8707 | __ B(eq, codegen_->GetLabelOf(successors[last_index + 2])); |
| 8708 | } |
| 8709 | if (num_entries - last_index == 2) { |
| 8710 | // The last missing case_value. |
| 8711 | __ Cmp(temp_reg, 1); |
| 8712 | __ B(eq, codegen_->GetLabelOf(successors[last_index + 1])); |
| 8713 | } |
| 8714 | |
| 8715 | // And the default for any other value. |
| 8716 | if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) { |
| 8717 | __ B(codegen_->GetLabelOf(default_block)); |
| 8718 | } |
| 8719 | } else { |
| 8720 | // Create a table lookup. |
| 8721 | vixl32::Register table_base = RegisterFrom(locations->GetTemp(0)); |
| 8722 | |
| 8723 | JumpTableARMVIXL* jump_table = codegen_->CreateJumpTable(switch_instr); |
| 8724 | |
| 8725 | // Remove the bias. |
| 8726 | vixl32::Register key_reg; |
| 8727 | if (lower_bound != 0) { |
| 8728 | key_reg = RegisterFrom(locations->GetTemp(1)); |
| 8729 | __ Sub(key_reg, value_reg, lower_bound); |
| 8730 | } else { |
| 8731 | key_reg = value_reg; |
| 8732 | } |
| 8733 | |
| 8734 | // Check whether the value is in the table, jump to default block if not. |
| 8735 | __ Cmp(key_reg, num_entries - 1); |
| 8736 | __ B(hi, codegen_->GetLabelOf(default_block)); |
| 8737 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8738 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 8739 | vixl32::Register jump_offset = temps.Acquire(); |
| 8740 | |
| 8741 | // Load jump offset from the table. |
Scott Wakeling | 86e9d26 | 2017-01-18 15:59:24 +0000 | [diff] [blame] | 8742 | { |
| 8743 | const size_t jump_size = switch_instr->GetNumEntries() * sizeof(int32_t); |
| 8744 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 8745 | (vixl32::kMaxInstructionSizeInBytes * 4) + jump_size, |
| 8746 | CodeBufferCheckScope::kMaximumSize); |
| 8747 | __ adr(table_base, jump_table->GetTableStartLabel()); |
| 8748 | __ ldr(jump_offset, MemOperand(table_base, key_reg, vixl32::LSL, 2)); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 8749 | |
Scott Wakeling | 86e9d26 | 2017-01-18 15:59:24 +0000 | [diff] [blame] | 8750 | // Jump to target block by branching to table_base(pc related) + offset. |
| 8751 | vixl32::Register target_address = table_base; |
| 8752 | __ add(target_address, table_base, jump_offset); |
| 8753 | __ bx(target_address); |
Artem Serov | 09a940d | 2016-11-11 16:15:11 +0000 | [diff] [blame] | 8754 | |
Scott Wakeling | 86e9d26 | 2017-01-18 15:59:24 +0000 | [diff] [blame] | 8755 | jump_table->EmitTable(codegen_); |
| 8756 | } |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 8757 | } |
| 8758 | } |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8759 | void LocationsBuilderARMVIXL::VisitArmDexCacheArraysBase(HArmDexCacheArraysBase* base) { |
| 8760 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(base); |
| 8761 | locations->SetOut(Location::RequiresRegister()); |
| 8762 | } |
| 8763 | |
| 8764 | void InstructionCodeGeneratorARMVIXL::VisitArmDexCacheArraysBase(HArmDexCacheArraysBase* base) { |
| 8765 | vixl32::Register base_reg = OutputRegister(base); |
| 8766 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels = |
| 8767 | codegen_->NewPcRelativeDexCacheArrayPatch(base->GetDexFile(), base->GetElementOffset()); |
| 8768 | codegen_->EmitMovwMovtPlaceholder(labels, base_reg); |
| 8769 | } |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 8770 | |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 8771 | // Copy the result of a call into the given target. |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8772 | void CodeGeneratorARMVIXL::MoveFromReturnRegister(Location trg, Primitive::Type type) { |
| 8773 | if (!trg.IsValid()) { |
| 8774 | DCHECK_EQ(type, Primitive::kPrimVoid); |
| 8775 | return; |
| 8776 | } |
| 8777 | |
| 8778 | DCHECK_NE(type, Primitive::kPrimVoid); |
| 8779 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8780 | Location return_loc = InvokeDexCallingConventionVisitorARMVIXL().GetReturnLocation(type); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8781 | if (return_loc.Equals(trg)) { |
| 8782 | return; |
| 8783 | } |
| 8784 | |
| 8785 | // TODO: Consider pairs in the parallel move resolver, then this could be nicely merged |
| 8786 | // with the last branch. |
| 8787 | if (type == Primitive::kPrimLong) { |
| 8788 | TODO_VIXL32(FATAL); |
| 8789 | } else if (type == Primitive::kPrimDouble) { |
| 8790 | TODO_VIXL32(FATAL); |
| 8791 | } else { |
| 8792 | // Let the parallel move resolver take care of all of this. |
| 8793 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 8794 | parallel_move.AddMove(return_loc, trg, type, nullptr); |
| 8795 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 8796 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8797 | } |
| 8798 | |
xueliang.zhong | 8d2c459 | 2016-11-23 17:05:25 +0000 | [diff] [blame] | 8799 | void LocationsBuilderARMVIXL::VisitClassTableGet(HClassTableGet* instruction) { |
| 8800 | LocationSummary* locations = |
| 8801 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 8802 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8803 | locations->SetOut(Location::RequiresRegister()); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 8804 | } |
| 8805 | |
xueliang.zhong | 8d2c459 | 2016-11-23 17:05:25 +0000 | [diff] [blame] | 8806 | void InstructionCodeGeneratorARMVIXL::VisitClassTableGet(HClassTableGet* instruction) { |
| 8807 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
| 8808 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 8809 | instruction->GetIndex(), kArmPointerSize).SizeValue(); |
| 8810 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 8811 | OutputRegister(instruction), |
| 8812 | InputRegisterAt(instruction, 0), |
| 8813 | method_offset); |
| 8814 | } else { |
| 8815 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
| 8816 | instruction->GetIndex(), kArmPointerSize)); |
| 8817 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 8818 | OutputRegister(instruction), |
| 8819 | InputRegisterAt(instruction, 0), |
| 8820 | mirror::Class::ImtPtrOffset(kArmPointerSize).Uint32Value()); |
| 8821 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 8822 | OutputRegister(instruction), |
| 8823 | OutputRegister(instruction), |
| 8824 | method_offset); |
| 8825 | } |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 8826 | } |
| 8827 | |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 8828 | static void PatchJitRootUse(uint8_t* code, |
| 8829 | const uint8_t* roots_data, |
| 8830 | VIXLUInt32Literal* literal, |
| 8831 | uint64_t index_in_table) { |
| 8832 | DCHECK(literal->IsBound()); |
| 8833 | uint32_t literal_offset = literal->GetLocation(); |
| 8834 | uintptr_t address = |
| 8835 | reinterpret_cast<uintptr_t>(roots_data) + index_in_table * sizeof(GcRoot<mirror::Object>); |
| 8836 | uint8_t* data = code + literal_offset; |
| 8837 | reinterpret_cast<uint32_t*>(data)[0] = dchecked_integral_cast<uint32_t>(address); |
| 8838 | } |
| 8839 | |
| 8840 | void CodeGeneratorARMVIXL::EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) { |
| 8841 | for (const auto& entry : jit_string_patches_) { |
| 8842 | const auto& it = jit_string_roots_.find(entry.first); |
| 8843 | DCHECK(it != jit_string_roots_.end()); |
| 8844 | PatchJitRootUse(code, roots_data, entry.second, it->second); |
| 8845 | } |
| 8846 | for (const auto& entry : jit_class_patches_) { |
| 8847 | const auto& it = jit_class_roots_.find(entry.first); |
| 8848 | DCHECK(it != jit_class_roots_.end()); |
| 8849 | PatchJitRootUse(code, roots_data, entry.second, it->second); |
| 8850 | } |
| 8851 | } |
| 8852 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8853 | void CodeGeneratorARMVIXL::EmitMovwMovtPlaceholder( |
| 8854 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels, |
| 8855 | vixl32::Register out) { |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 8856 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 8857 | 3 * vixl32::kMaxInstructionSizeInBytes, |
| 8858 | CodeBufferCheckScope::kMaximumSize); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8859 | // TODO(VIXL): Think about using mov instead of movw. |
| 8860 | __ bind(&labels->movw_label); |
| 8861 | __ movw(out, /* placeholder */ 0u); |
| 8862 | __ bind(&labels->movt_label); |
| 8863 | __ movt(out, /* placeholder */ 0u); |
| 8864 | __ bind(&labels->add_pc_label); |
| 8865 | __ add(out, out, pc); |
| 8866 | } |
| 8867 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 8868 | #undef __ |
| 8869 | #undef QUICK_ENTRY_POINT |
| 8870 | #undef TODO_VIXL32 |
| 8871 | |
| 8872 | } // namespace arm |
| 8873 | } // namespace art |