Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 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_arm64.h" |
| 18 | |
Serban Constantinescu | 579885a | 2015-02-22 20:51:33 +0000 | [diff] [blame] | 19 | #include "arch/arm64/instruction_set_features_arm64.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 20 | #include "art_method.h" |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 21 | #include "code_generator_utils.h" |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 22 | #include "compiled_method.h" |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 23 | #include "entrypoints/quick/quick_entrypoints.h" |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 24 | #include "entrypoints/quick/quick_entrypoints_enum.h" |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 25 | #include "gc/accounting/card_table.h" |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 26 | #include "intrinsics.h" |
| 27 | #include "intrinsics_arm64.h" |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 28 | #include "mirror/array-inl.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 29 | #include "mirror/class-inl.h" |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 30 | #include "offsets.h" |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 31 | #include "thread.h" |
| 32 | #include "utils/arm64/assembler_arm64.h" |
| 33 | #include "utils/assembler.h" |
| 34 | #include "utils/stack_checks.h" |
| 35 | |
| 36 | |
| 37 | using namespace vixl; // NOLINT(build/namespaces) |
| 38 | |
| 39 | #ifdef __ |
| 40 | #error "ARM64 Codegen VIXL macro-assembler macro already defined." |
| 41 | #endif |
| 42 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 43 | namespace art { |
| 44 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 45 | template<class MirrorType> |
| 46 | class GcRoot; |
| 47 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 48 | namespace arm64 { |
| 49 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 50 | using helpers::CPURegisterFrom; |
| 51 | using helpers::DRegisterFrom; |
| 52 | using helpers::FPRegisterFrom; |
| 53 | using helpers::HeapOperand; |
| 54 | using helpers::HeapOperandFrom; |
| 55 | using helpers::InputCPURegisterAt; |
| 56 | using helpers::InputFPRegisterAt; |
| 57 | using helpers::InputRegisterAt; |
| 58 | using helpers::InputOperandAt; |
| 59 | using helpers::Int64ConstantFrom; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 60 | using helpers::LocationFrom; |
| 61 | using helpers::OperandFromMemOperand; |
| 62 | using helpers::OutputCPURegister; |
| 63 | using helpers::OutputFPRegister; |
| 64 | using helpers::OutputRegister; |
| 65 | using helpers::RegisterFrom; |
| 66 | using helpers::StackOperandFrom; |
| 67 | using helpers::VIXLRegCodeFromART; |
| 68 | using helpers::WRegisterFrom; |
| 69 | using helpers::XRegisterFrom; |
Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 70 | using helpers::ARM64EncodableConstantOrRegister; |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 71 | using helpers::ArtVixlRegCodeCoherentForRegSet; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 72 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 73 | static constexpr int kCurrentMethodStackOffset = 0; |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 74 | // The compare/jump sequence will generate about (1.5 * num_entries + 3) instructions. While jump |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 75 | // table version generates 7 instructions and num_entries literals. Compare/jump sequence will |
| 76 | // generates less code/data with a small num_entries. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 77 | static constexpr uint32_t kPackedSwitchCompareJumpThreshold = 7; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 78 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 79 | inline Condition ARM64Condition(IfCondition cond) { |
| 80 | switch (cond) { |
| 81 | case kCondEQ: return eq; |
| 82 | case kCondNE: return ne; |
| 83 | case kCondLT: return lt; |
| 84 | case kCondLE: return le; |
| 85 | case kCondGT: return gt; |
| 86 | case kCondGE: return ge; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 87 | case kCondB: return lo; |
| 88 | case kCondBE: return ls; |
| 89 | case kCondA: return hi; |
| 90 | case kCondAE: return hs; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 91 | } |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 92 | LOG(FATAL) << "Unreachable"; |
| 93 | UNREACHABLE(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 94 | } |
| 95 | |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 96 | inline Condition ARM64FPCondition(IfCondition cond, bool gt_bias) { |
| 97 | // The ARM64 condition codes can express all the necessary branches, see the |
| 98 | // "Meaning (floating-point)" column in the table C1-1 in the ARMv8 reference manual. |
| 99 | // There is no dex instruction or HIR that would need the missing conditions |
| 100 | // "equal or unordered" or "not equal". |
| 101 | switch (cond) { |
| 102 | case kCondEQ: return eq; |
| 103 | case kCondNE: return ne /* unordered */; |
| 104 | case kCondLT: return gt_bias ? cc : lt /* unordered */; |
| 105 | case kCondLE: return gt_bias ? ls : le /* unordered */; |
| 106 | case kCondGT: return gt_bias ? hi /* unordered */ : gt; |
| 107 | case kCondGE: return gt_bias ? cs /* unordered */ : ge; |
| 108 | default: |
| 109 | LOG(FATAL) << "UNREACHABLE"; |
| 110 | UNREACHABLE(); |
| 111 | } |
| 112 | } |
| 113 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 114 | Location ARM64ReturnLocation(Primitive::Type return_type) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 115 | // Note that in practice, `LocationFrom(x0)` and `LocationFrom(w0)` create the |
| 116 | // same Location object, and so do `LocationFrom(d0)` and `LocationFrom(s0)`, |
| 117 | // but we use the exact registers for clarity. |
| 118 | if (return_type == Primitive::kPrimFloat) { |
| 119 | return LocationFrom(s0); |
| 120 | } else if (return_type == Primitive::kPrimDouble) { |
| 121 | return LocationFrom(d0); |
| 122 | } else if (return_type == Primitive::kPrimLong) { |
| 123 | return LocationFrom(x0); |
Nicolas Geoffray | 925e562 | 2015-06-03 12:23:32 +0100 | [diff] [blame] | 124 | } else if (return_type == Primitive::kPrimVoid) { |
| 125 | return Location::NoLocation(); |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 126 | } else { |
| 127 | return LocationFrom(w0); |
| 128 | } |
| 129 | } |
| 130 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 131 | Location InvokeRuntimeCallingConvention::GetReturnLocation(Primitive::Type return_type) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 132 | return ARM64ReturnLocation(return_type); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 133 | } |
| 134 | |
Chih-Hung Hsieh | fba3997 | 2016-05-11 11:26:48 -0700 | [diff] [blame] | 135 | // NOLINT on __ macro to suppress wrong warning/fix from clang-tidy. |
| 136 | #define __ down_cast<CodeGeneratorARM64*>(codegen)->GetVIXLAssembler()-> // NOLINT |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 137 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kArm64WordSize, x).Int32Value() |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 138 | |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 139 | // Calculate memory accessing operand for save/restore live registers. |
| 140 | static void SaveRestoreLiveRegistersHelper(CodeGenerator* codegen, |
| 141 | RegisterSet* register_set, |
| 142 | int64_t spill_offset, |
| 143 | bool is_save) { |
| 144 | DCHECK(ArtVixlRegCodeCoherentForRegSet(register_set->GetCoreRegisters(), |
| 145 | codegen->GetNumberOfCoreRegisters(), |
| 146 | register_set->GetFloatingPointRegisters(), |
| 147 | codegen->GetNumberOfFloatingPointRegisters())); |
| 148 | |
| 149 | CPURegList core_list = CPURegList(CPURegister::kRegister, kXRegSize, |
| 150 | register_set->GetCoreRegisters() & (~callee_saved_core_registers.list())); |
Nicolas Geoffray | 75d5b9b | 2015-10-05 07:40:35 +0000 | [diff] [blame] | 151 | CPURegList fp_list = CPURegList(CPURegister::kFPRegister, kDRegSize, |
| 152 | register_set->GetFloatingPointRegisters() & (~callee_saved_fp_registers.list())); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 153 | |
| 154 | MacroAssembler* masm = down_cast<CodeGeneratorARM64*>(codegen)->GetVIXLAssembler(); |
| 155 | UseScratchRegisterScope temps(masm); |
| 156 | |
| 157 | Register base = masm->StackPointer(); |
| 158 | int64_t core_spill_size = core_list.TotalSizeInBytes(); |
| 159 | int64_t fp_spill_size = fp_list.TotalSizeInBytes(); |
| 160 | int64_t reg_size = kXRegSizeInBytes; |
| 161 | int64_t max_ls_pair_offset = spill_offset + core_spill_size + fp_spill_size - 2 * reg_size; |
| 162 | uint32_t ls_access_size = WhichPowerOf2(reg_size); |
| 163 | if (((core_list.Count() > 1) || (fp_list.Count() > 1)) && |
| 164 | !masm->IsImmLSPair(max_ls_pair_offset, ls_access_size)) { |
| 165 | // If the offset does not fit in the instruction's immediate field, use an alternate register |
| 166 | // to compute the base address(float point registers spill base address). |
| 167 | Register new_base = temps.AcquireSameSizeAs(base); |
| 168 | __ Add(new_base, base, Operand(spill_offset + core_spill_size)); |
| 169 | base = new_base; |
| 170 | spill_offset = -core_spill_size; |
| 171 | int64_t new_max_ls_pair_offset = fp_spill_size - 2 * reg_size; |
| 172 | DCHECK(masm->IsImmLSPair(spill_offset, ls_access_size)); |
| 173 | DCHECK(masm->IsImmLSPair(new_max_ls_pair_offset, ls_access_size)); |
| 174 | } |
| 175 | |
| 176 | if (is_save) { |
| 177 | __ StoreCPURegList(core_list, MemOperand(base, spill_offset)); |
| 178 | __ StoreCPURegList(fp_list, MemOperand(base, spill_offset + core_spill_size)); |
| 179 | } else { |
| 180 | __ LoadCPURegList(core_list, MemOperand(base, spill_offset)); |
| 181 | __ LoadCPURegList(fp_list, MemOperand(base, spill_offset + core_spill_size)); |
| 182 | } |
| 183 | } |
| 184 | |
| 185 | void SlowPathCodeARM64::SaveLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) { |
| 186 | RegisterSet* register_set = locations->GetLiveRegisters(); |
| 187 | size_t stack_offset = codegen->GetFirstRegisterSlotInSlowPath(); |
| 188 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 189 | if (!codegen->IsCoreCalleeSaveRegister(i) && register_set->ContainsCoreRegister(i)) { |
| 190 | // If the register holds an object, update the stack mask. |
| 191 | if (locations->RegisterContainsObject(i)) { |
| 192 | locations->SetStackBit(stack_offset / kVRegSize); |
| 193 | } |
| 194 | DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 195 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 196 | saved_core_stack_offsets_[i] = stack_offset; |
| 197 | stack_offset += kXRegSizeInBytes; |
| 198 | } |
| 199 | } |
| 200 | |
| 201 | for (size_t i = 0, e = codegen->GetNumberOfFloatingPointRegisters(); i < e; ++i) { |
| 202 | if (!codegen->IsFloatingPointCalleeSaveRegister(i) && |
| 203 | register_set->ContainsFloatingPointRegister(i)) { |
| 204 | DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 205 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 206 | saved_fpu_stack_offsets_[i] = stack_offset; |
| 207 | stack_offset += kDRegSizeInBytes; |
| 208 | } |
| 209 | } |
| 210 | |
| 211 | SaveRestoreLiveRegistersHelper(codegen, register_set, |
| 212 | codegen->GetFirstRegisterSlotInSlowPath(), true /* is_save */); |
| 213 | } |
| 214 | |
| 215 | void SlowPathCodeARM64::RestoreLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) { |
| 216 | RegisterSet* register_set = locations->GetLiveRegisters(); |
| 217 | SaveRestoreLiveRegistersHelper(codegen, register_set, |
| 218 | codegen->GetFirstRegisterSlotInSlowPath(), false /* is_save */); |
| 219 | } |
| 220 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 221 | class BoundsCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 222 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 223 | explicit BoundsCheckSlowPathARM64(HBoundsCheck* instruction) : SlowPathCodeARM64(instruction) {} |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 224 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 225 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 226 | LocationSummary* locations = instruction_->GetLocations(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 227 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 228 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 229 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 230 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 231 | // Live registers will be restored in the catch block if caught. |
| 232 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 233 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 234 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 235 | // move resolver. |
| 236 | InvokeRuntimeCallingConvention calling_convention; |
| 237 | codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 238 | locations->InAt(0), LocationFrom(calling_convention.GetRegisterAt(0)), Primitive::kPrimInt, |
| 239 | locations->InAt(1), LocationFrom(calling_convention.GetRegisterAt(1)), Primitive::kPrimInt); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 240 | arm64_codegen->InvokeRuntime( |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 241 | QUICK_ENTRY_POINT(pThrowArrayBounds), instruction_, instruction_->GetDexPc(), this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 242 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 243 | } |
| 244 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 245 | bool IsFatal() const OVERRIDE { return true; } |
| 246 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 247 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathARM64"; } |
| 248 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 249 | private: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 250 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathARM64); |
| 251 | }; |
| 252 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 253 | class DivZeroCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 254 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 255 | explicit DivZeroCheckSlowPathARM64(HDivZeroCheck* instruction) : SlowPathCodeARM64(instruction) {} |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 256 | |
| 257 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 258 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 259 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 260 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 261 | // Live registers will be restored in the catch block if caught. |
| 262 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 263 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 264 | arm64_codegen->InvokeRuntime( |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 265 | QUICK_ENTRY_POINT(pThrowDivZero), instruction_, instruction_->GetDexPc(), this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 266 | CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 267 | } |
| 268 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 269 | bool IsFatal() const OVERRIDE { return true; } |
| 270 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 271 | const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathARM64"; } |
| 272 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 273 | private: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 274 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathARM64); |
| 275 | }; |
| 276 | |
| 277 | class LoadClassSlowPathARM64 : public SlowPathCodeARM64 { |
| 278 | public: |
| 279 | LoadClassSlowPathARM64(HLoadClass* cls, |
| 280 | HInstruction* at, |
| 281 | uint32_t dex_pc, |
| 282 | bool do_clinit) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 283 | : SlowPathCodeARM64(at), cls_(cls), at_(at), dex_pc_(dex_pc), do_clinit_(do_clinit) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 284 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 285 | } |
| 286 | |
| 287 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 288 | LocationSummary* locations = at_->GetLocations(); |
| 289 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 290 | |
| 291 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 292 | SaveLiveRegisters(codegen, locations); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 293 | |
| 294 | InvokeRuntimeCallingConvention calling_convention; |
| 295 | __ Mov(calling_convention.GetRegisterAt(0).W(), cls_->GetTypeIndex()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 296 | int32_t entry_point_offset = do_clinit_ ? QUICK_ENTRY_POINT(pInitializeStaticStorage) |
| 297 | : QUICK_ENTRY_POINT(pInitializeType); |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 298 | arm64_codegen->InvokeRuntime(entry_point_offset, at_, dex_pc_, this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 299 | if (do_clinit_) { |
Vladimir Marko | 5ea536a | 2015-04-20 20:11:30 +0100 | [diff] [blame] | 300 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>(); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 301 | } else { |
Vladimir Marko | 5ea536a | 2015-04-20 20:11:30 +0100 | [diff] [blame] | 302 | CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>(); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 303 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 304 | |
| 305 | // Move the class to the desired location. |
| 306 | Location out = locations->Out(); |
| 307 | if (out.IsValid()) { |
| 308 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
| 309 | Primitive::Type type = at_->GetType(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 310 | arm64_codegen->MoveLocation(out, calling_convention.GetReturnLocation(type), type); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 311 | } |
| 312 | |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 313 | RestoreLiveRegisters(codegen, locations); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 314 | __ B(GetExitLabel()); |
| 315 | } |
| 316 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 317 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathARM64"; } |
| 318 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 319 | private: |
| 320 | // The class this slow path will load. |
| 321 | HLoadClass* const cls_; |
| 322 | |
| 323 | // The instruction where this slow path is happening. |
| 324 | // (Might be the load class or an initialization check). |
| 325 | HInstruction* const at_; |
| 326 | |
| 327 | // The dex PC of `at_`. |
| 328 | const uint32_t dex_pc_; |
| 329 | |
| 330 | // Whether to initialize the class. |
| 331 | const bool do_clinit_; |
| 332 | |
| 333 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathARM64); |
| 334 | }; |
| 335 | |
| 336 | class LoadStringSlowPathARM64 : public SlowPathCodeARM64 { |
| 337 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 338 | explicit LoadStringSlowPathARM64(HLoadString* instruction) : SlowPathCodeARM64(instruction) {} |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 339 | |
| 340 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 341 | LocationSummary* locations = instruction_->GetLocations(); |
| 342 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 343 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 344 | |
| 345 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 346 | SaveLiveRegisters(codegen, locations); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 347 | |
| 348 | InvokeRuntimeCallingConvention calling_convention; |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 349 | const uint32_t string_index = instruction_->AsLoadString()->GetStringIndex(); |
| 350 | __ Mov(calling_convention.GetRegisterAt(0).W(), string_index); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 351 | arm64_codegen->InvokeRuntime( |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 352 | QUICK_ENTRY_POINT(pResolveString), instruction_, instruction_->GetDexPc(), this); |
Vladimir Marko | 5ea536a | 2015-04-20 20:11:30 +0100 | [diff] [blame] | 353 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 354 | Primitive::Type type = instruction_->GetType(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 355 | arm64_codegen->MoveLocation(locations->Out(), calling_convention.GetReturnLocation(type), type); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 356 | |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 357 | RestoreLiveRegisters(codegen, locations); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 358 | __ B(GetExitLabel()); |
| 359 | } |
| 360 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 361 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathARM64"; } |
| 362 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 363 | private: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 364 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathARM64); |
| 365 | }; |
| 366 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 367 | class NullCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 368 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 369 | explicit NullCheckSlowPathARM64(HNullCheck* instr) : SlowPathCodeARM64(instr) {} |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 370 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 371 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 372 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 373 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 374 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 375 | // Live registers will be restored in the catch block if caught. |
| 376 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 377 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 378 | arm64_codegen->InvokeRuntime( |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 379 | QUICK_ENTRY_POINT(pThrowNullPointer), instruction_, instruction_->GetDexPc(), this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 380 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 381 | } |
| 382 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 383 | bool IsFatal() const OVERRIDE { return true; } |
| 384 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 385 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathARM64"; } |
| 386 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 387 | private: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 388 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathARM64); |
| 389 | }; |
| 390 | |
| 391 | class SuspendCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 392 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 393 | SuspendCheckSlowPathARM64(HSuspendCheck* instruction, HBasicBlock* successor) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 394 | : SlowPathCodeARM64(instruction), successor_(successor) {} |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 395 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 396 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 397 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 398 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 399 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 400 | arm64_codegen->InvokeRuntime( |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 401 | QUICK_ENTRY_POINT(pTestSuspend), instruction_, instruction_->GetDexPc(), this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 402 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 403 | RestoreLiveRegisters(codegen, instruction_->GetLocations()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 404 | if (successor_ == nullptr) { |
| 405 | __ B(GetReturnLabel()); |
| 406 | } else { |
| 407 | __ B(arm64_codegen->GetLabelOf(successor_)); |
| 408 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 409 | } |
| 410 | |
| 411 | vixl::Label* GetReturnLabel() { |
| 412 | DCHECK(successor_ == nullptr); |
| 413 | return &return_label_; |
| 414 | } |
| 415 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 416 | HBasicBlock* GetSuccessor() const { |
| 417 | return successor_; |
| 418 | } |
| 419 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 420 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathARM64"; } |
| 421 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 422 | private: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 423 | // If not null, the block to branch to after the suspend check. |
| 424 | HBasicBlock* const successor_; |
| 425 | |
| 426 | // If `successor_` is null, the label to branch to after the suspend check. |
| 427 | vixl::Label return_label_; |
| 428 | |
| 429 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathARM64); |
| 430 | }; |
| 431 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 432 | class TypeCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 433 | public: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 434 | TypeCheckSlowPathARM64(HInstruction* instruction, bool is_fatal) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 435 | : SlowPathCodeARM64(instruction), is_fatal_(is_fatal) {} |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 436 | |
| 437 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 438 | LocationSummary* locations = instruction_->GetLocations(); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 439 | Location class_to_check = locations->InAt(1); |
| 440 | Location object_class = instruction_->IsCheckCast() ? locations->GetTemp(0) |
| 441 | : locations->Out(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 442 | DCHECK(instruction_->IsCheckCast() |
| 443 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 444 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 445 | uint32_t dex_pc = instruction_->GetDexPc(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 446 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 447 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 448 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 449 | if (!is_fatal_) { |
| 450 | SaveLiveRegisters(codegen, locations); |
| 451 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 452 | |
| 453 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 454 | // move resolver. |
| 455 | InvokeRuntimeCallingConvention calling_convention; |
| 456 | codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 457 | class_to_check, LocationFrom(calling_convention.GetRegisterAt(0)), Primitive::kPrimNot, |
| 458 | object_class, LocationFrom(calling_convention.GetRegisterAt(1)), Primitive::kPrimNot); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 459 | |
| 460 | if (instruction_->IsInstanceOf()) { |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 461 | arm64_codegen->InvokeRuntime( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 462 | QUICK_ENTRY_POINT(pInstanceofNonTrivial), instruction_, dex_pc, this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 463 | CheckEntrypointTypes<kQuickInstanceofNonTrivial, uint32_t, |
| 464 | const mirror::Class*, const mirror::Class*>(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 465 | Primitive::Type ret_type = instruction_->GetType(); |
| 466 | Location ret_loc = calling_convention.GetReturnLocation(ret_type); |
| 467 | arm64_codegen->MoveLocation(locations->Out(), ret_loc, ret_type); |
| 468 | } else { |
| 469 | DCHECK(instruction_->IsCheckCast()); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 470 | arm64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pCheckCast), instruction_, dex_pc, this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 471 | CheckEntrypointTypes<kQuickCheckCast, void, const mirror::Class*, const mirror::Class*>(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 472 | } |
| 473 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 474 | if (!is_fatal_) { |
| 475 | RestoreLiveRegisters(codegen, locations); |
| 476 | __ B(GetExitLabel()); |
| 477 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 478 | } |
| 479 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 480 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathARM64"; } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 481 | bool IsFatal() const { return is_fatal_; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 482 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 483 | private: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 484 | const bool is_fatal_; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 485 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 486 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathARM64); |
| 487 | }; |
| 488 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 489 | class DeoptimizationSlowPathARM64 : public SlowPathCodeARM64 { |
| 490 | public: |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 491 | explicit DeoptimizationSlowPathARM64(HDeoptimize* instruction) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 492 | : SlowPathCodeARM64(instruction) {} |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 493 | |
| 494 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 495 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 496 | __ Bind(GetEntryLabel()); |
| 497 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 498 | arm64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pDeoptimize), |
| 499 | instruction_, |
| 500 | instruction_->GetDexPc(), |
| 501 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 502 | CheckEntrypointTypes<kQuickDeoptimize, void, void>(); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 503 | } |
| 504 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 505 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathARM64"; } |
| 506 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 507 | private: |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 508 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathARM64); |
| 509 | }; |
| 510 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 511 | class ArraySetSlowPathARM64 : public SlowPathCodeARM64 { |
| 512 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 513 | explicit ArraySetSlowPathARM64(HInstruction* instruction) : SlowPathCodeARM64(instruction) {} |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 514 | |
| 515 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 516 | LocationSummary* locations = instruction_->GetLocations(); |
| 517 | __ Bind(GetEntryLabel()); |
| 518 | SaveLiveRegisters(codegen, locations); |
| 519 | |
| 520 | InvokeRuntimeCallingConvention calling_convention; |
| 521 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 522 | parallel_move.AddMove( |
| 523 | locations->InAt(0), |
| 524 | LocationFrom(calling_convention.GetRegisterAt(0)), |
| 525 | Primitive::kPrimNot, |
| 526 | nullptr); |
| 527 | parallel_move.AddMove( |
| 528 | locations->InAt(1), |
| 529 | LocationFrom(calling_convention.GetRegisterAt(1)), |
| 530 | Primitive::kPrimInt, |
| 531 | nullptr); |
| 532 | parallel_move.AddMove( |
| 533 | locations->InAt(2), |
| 534 | LocationFrom(calling_convention.GetRegisterAt(2)), |
| 535 | Primitive::kPrimNot, |
| 536 | nullptr); |
| 537 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 538 | |
| 539 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 540 | arm64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject), |
| 541 | instruction_, |
| 542 | instruction_->GetDexPc(), |
| 543 | this); |
| 544 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
| 545 | RestoreLiveRegisters(codegen, locations); |
| 546 | __ B(GetExitLabel()); |
| 547 | } |
| 548 | |
| 549 | const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathARM64"; } |
| 550 | |
| 551 | private: |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 552 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathARM64); |
| 553 | }; |
| 554 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 555 | void JumpTableARM64::EmitTable(CodeGeneratorARM64* codegen) { |
| 556 | uint32_t num_entries = switch_instr_->GetNumEntries(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 557 | DCHECK_GE(num_entries, kPackedSwitchCompareJumpThreshold); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 558 | |
| 559 | // We are about to use the assembler to place literals directly. Make sure we have enough |
| 560 | // underlying code buffer and we have generated the jump table with right size. |
| 561 | CodeBufferCheckScope scope(codegen->GetVIXLAssembler(), num_entries * sizeof(int32_t), |
| 562 | CodeBufferCheckScope::kCheck, CodeBufferCheckScope::kExactSize); |
| 563 | |
| 564 | __ Bind(&table_start_); |
| 565 | const ArenaVector<HBasicBlock*>& successors = switch_instr_->GetBlock()->GetSuccessors(); |
| 566 | for (uint32_t i = 0; i < num_entries; i++) { |
| 567 | vixl::Label* target_label = codegen->GetLabelOf(successors[i]); |
| 568 | DCHECK(target_label->IsBound()); |
| 569 | ptrdiff_t jump_offset = target_label->location() - table_start_.location(); |
| 570 | DCHECK_GT(jump_offset, std::numeric_limits<int32_t>::min()); |
| 571 | DCHECK_LE(jump_offset, std::numeric_limits<int32_t>::max()); |
| 572 | Literal<int32_t> literal(jump_offset); |
| 573 | __ place(&literal); |
| 574 | } |
| 575 | } |
| 576 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 577 | // Slow path marking an object during a read barrier. |
| 578 | class ReadBarrierMarkSlowPathARM64 : public SlowPathCodeARM64 { |
| 579 | public: |
| 580 | ReadBarrierMarkSlowPathARM64(HInstruction* instruction, Location out, Location obj) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 581 | : SlowPathCodeARM64(instruction), out_(out), obj_(obj) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 582 | DCHECK(kEmitCompilerReadBarrier); |
| 583 | } |
| 584 | |
| 585 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathARM64"; } |
| 586 | |
| 587 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 588 | LocationSummary* locations = instruction_->GetLocations(); |
| 589 | Primitive::Type type = Primitive::kPrimNot; |
| 590 | DCHECK(locations->CanCall()); |
| 591 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(out_.reg())); |
| 592 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 593 | instruction_->IsStaticFieldGet() || |
| 594 | instruction_->IsArrayGet() || |
| 595 | instruction_->IsLoadClass() || |
| 596 | instruction_->IsLoadString() || |
| 597 | instruction_->IsInstanceOf() || |
| 598 | instruction_->IsCheckCast()) |
| 599 | << "Unexpected instruction in read barrier marking slow path: " |
| 600 | << instruction_->DebugName(); |
| 601 | |
| 602 | __ Bind(GetEntryLabel()); |
| 603 | SaveLiveRegisters(codegen, locations); |
| 604 | |
| 605 | InvokeRuntimeCallingConvention calling_convention; |
| 606 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 607 | arm64_codegen->MoveLocation(LocationFrom(calling_convention.GetRegisterAt(0)), obj_, type); |
| 608 | arm64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pReadBarrierMark), |
| 609 | instruction_, |
| 610 | instruction_->GetDexPc(), |
| 611 | this); |
| 612 | CheckEntrypointTypes<kQuickReadBarrierMark, mirror::Object*, mirror::Object*>(); |
| 613 | arm64_codegen->MoveLocation(out_, calling_convention.GetReturnLocation(type), type); |
| 614 | |
| 615 | RestoreLiveRegisters(codegen, locations); |
| 616 | __ B(GetExitLabel()); |
| 617 | } |
| 618 | |
| 619 | private: |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 620 | const Location out_; |
| 621 | const Location obj_; |
| 622 | |
| 623 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathARM64); |
| 624 | }; |
| 625 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 626 | // Slow path generating a read barrier for a heap reference. |
| 627 | class ReadBarrierForHeapReferenceSlowPathARM64 : public SlowPathCodeARM64 { |
| 628 | public: |
| 629 | ReadBarrierForHeapReferenceSlowPathARM64(HInstruction* instruction, |
| 630 | Location out, |
| 631 | Location ref, |
| 632 | Location obj, |
| 633 | uint32_t offset, |
| 634 | Location index) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 635 | : SlowPathCodeARM64(instruction), |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 636 | out_(out), |
| 637 | ref_(ref), |
| 638 | obj_(obj), |
| 639 | offset_(offset), |
| 640 | index_(index) { |
| 641 | DCHECK(kEmitCompilerReadBarrier); |
| 642 | // If `obj` is equal to `out` or `ref`, it means the initial object |
| 643 | // has been overwritten by (or after) the heap object reference load |
| 644 | // to be instrumented, e.g.: |
| 645 | // |
| 646 | // __ Ldr(out, HeapOperand(out, class_offset); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 647 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 648 | // |
| 649 | // In that case, we have lost the information about the original |
| 650 | // object, and the emitted read barrier cannot work properly. |
| 651 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 652 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 653 | } |
| 654 | |
| 655 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 656 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 657 | LocationSummary* locations = instruction_->GetLocations(); |
| 658 | Primitive::Type type = Primitive::kPrimNot; |
| 659 | DCHECK(locations->CanCall()); |
| 660 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(out_.reg())); |
| 661 | DCHECK(!instruction_->IsInvoke() || |
| 662 | (instruction_->IsInvokeStaticOrDirect() && |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 663 | instruction_->GetLocations()->Intrinsified())) |
| 664 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 665 | << instruction_->DebugName(); |
Roland Levillain | cd3d0fb | 2016-01-15 19:26:48 +0000 | [diff] [blame] | 666 | // The read barrier instrumentation does not support the |
| 667 | // HArm64IntermediateAddress instruction yet. |
| 668 | DCHECK(!(instruction_->IsArrayGet() && |
| 669 | instruction_->AsArrayGet()->GetArray()->IsArm64IntermediateAddress())); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 670 | |
| 671 | __ Bind(GetEntryLabel()); |
| 672 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 673 | SaveLiveRegisters(codegen, locations); |
| 674 | |
| 675 | // We may have to change the index's value, but as `index_` is a |
| 676 | // constant member (like other "inputs" of this slow path), |
| 677 | // introduce a copy of it, `index`. |
| 678 | Location index = index_; |
| 679 | if (index_.IsValid()) { |
| 680 | // Handle `index_` for HArrayGet and intrinsic UnsafeGetObject. |
| 681 | if (instruction_->IsArrayGet()) { |
| 682 | // Compute the actual memory offset and store it in `index`. |
| 683 | Register index_reg = RegisterFrom(index_, Primitive::kPrimInt); |
| 684 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_.reg())); |
| 685 | if (codegen->IsCoreCalleeSaveRegister(index_.reg())) { |
| 686 | // We are about to change the value of `index_reg` (see the |
| 687 | // calls to vixl::MacroAssembler::Lsl and |
| 688 | // vixl::MacroAssembler::Mov below), but it has |
| 689 | // not been saved by the previous call to |
| 690 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 691 | // callee-save register -- |
| 692 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 693 | // callee-save registers, as it has been designed with the |
| 694 | // assumption that callee-save registers are supposed to be |
| 695 | // handled by the called function. So, as a callee-save |
| 696 | // register, `index_reg` _would_ eventually be saved onto |
| 697 | // the stack, but it would be too late: we would have |
| 698 | // changed its value earlier. Therefore, we manually save |
| 699 | // it here into another freely available register, |
| 700 | // `free_reg`, chosen of course among the caller-save |
| 701 | // registers (as a callee-save `free_reg` register would |
| 702 | // exhibit the same problem). |
| 703 | // |
| 704 | // Note we could have requested a temporary register from |
| 705 | // the register allocator instead; but we prefer not to, as |
| 706 | // this is a slow path, and we know we can find a |
| 707 | // caller-save register that is available. |
| 708 | Register free_reg = FindAvailableCallerSaveRegister(codegen); |
| 709 | __ Mov(free_reg.W(), index_reg); |
| 710 | index_reg = free_reg; |
| 711 | index = LocationFrom(index_reg); |
| 712 | } else { |
| 713 | // The initial register stored in `index_` has already been |
| 714 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 715 | // (as it is not a callee-save register), so we can freely |
| 716 | // use it. |
| 717 | } |
| 718 | // Shifting the index value contained in `index_reg` by the scale |
| 719 | // factor (2) cannot overflow in practice, as the runtime is |
| 720 | // unable to allocate object arrays with a size larger than |
| 721 | // 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 722 | __ Lsl(index_reg, index_reg, Primitive::ComponentSizeShift(type)); |
| 723 | static_assert( |
| 724 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 725 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 726 | __ Add(index_reg, index_reg, Operand(offset_)); |
| 727 | } else { |
| 728 | DCHECK(instruction_->IsInvoke()); |
| 729 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 730 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 731 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 732 | << instruction_->AsInvoke()->GetIntrinsic(); |
| 733 | DCHECK_EQ(offset_, 0U); |
| 734 | DCHECK(index_.IsRegisterPair()); |
| 735 | // UnsafeGet's offset location is a register pair, the low |
| 736 | // part contains the correct offset. |
| 737 | index = index_.ToLow(); |
| 738 | } |
| 739 | } |
| 740 | |
| 741 | // We're moving two or three locations to locations that could |
| 742 | // overlap, so we need a parallel move resolver. |
| 743 | InvokeRuntimeCallingConvention calling_convention; |
| 744 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 745 | parallel_move.AddMove(ref_, |
| 746 | LocationFrom(calling_convention.GetRegisterAt(0)), |
| 747 | type, |
| 748 | nullptr); |
| 749 | parallel_move.AddMove(obj_, |
| 750 | LocationFrom(calling_convention.GetRegisterAt(1)), |
| 751 | type, |
| 752 | nullptr); |
| 753 | if (index.IsValid()) { |
| 754 | parallel_move.AddMove(index, |
| 755 | LocationFrom(calling_convention.GetRegisterAt(2)), |
| 756 | Primitive::kPrimInt, |
| 757 | nullptr); |
| 758 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 759 | } else { |
| 760 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 761 | arm64_codegen->MoveConstant(LocationFrom(calling_convention.GetRegisterAt(2)), offset_); |
| 762 | } |
| 763 | arm64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pReadBarrierSlow), |
| 764 | instruction_, |
| 765 | instruction_->GetDexPc(), |
| 766 | this); |
| 767 | CheckEntrypointTypes< |
| 768 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 769 | arm64_codegen->MoveLocation(out_, calling_convention.GetReturnLocation(type), type); |
| 770 | |
| 771 | RestoreLiveRegisters(codegen, locations); |
| 772 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 773 | __ B(GetExitLabel()); |
| 774 | } |
| 775 | |
| 776 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForHeapReferenceSlowPathARM64"; } |
| 777 | |
| 778 | private: |
| 779 | Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
| 780 | size_t ref = static_cast<int>(XRegisterFrom(ref_).code()); |
| 781 | size_t obj = static_cast<int>(XRegisterFrom(obj_).code()); |
| 782 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 783 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 784 | return Register(VIXLRegCodeFromART(i), kXRegSize); |
| 785 | } |
| 786 | } |
| 787 | // We shall never fail to find a free caller-save register, as |
| 788 | // there are more than two core caller-save registers on ARM64 |
| 789 | // (meaning it is possible to find one which is different from |
| 790 | // `ref` and `obj`). |
| 791 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 792 | LOG(FATAL) << "Could not find a free register"; |
| 793 | UNREACHABLE(); |
| 794 | } |
| 795 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 796 | const Location out_; |
| 797 | const Location ref_; |
| 798 | const Location obj_; |
| 799 | const uint32_t offset_; |
| 800 | // An additional location containing an index to an array. |
| 801 | // Only used for HArrayGet and the UnsafeGetObject & |
| 802 | // UnsafeGetObjectVolatile intrinsics. |
| 803 | const Location index_; |
| 804 | |
| 805 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathARM64); |
| 806 | }; |
| 807 | |
| 808 | // Slow path generating a read barrier for a GC root. |
| 809 | class ReadBarrierForRootSlowPathARM64 : public SlowPathCodeARM64 { |
| 810 | public: |
| 811 | ReadBarrierForRootSlowPathARM64(HInstruction* instruction, Location out, Location root) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 812 | : SlowPathCodeARM64(instruction), out_(out), root_(root) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 813 | DCHECK(kEmitCompilerReadBarrier); |
| 814 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 815 | |
| 816 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 817 | LocationSummary* locations = instruction_->GetLocations(); |
| 818 | Primitive::Type type = Primitive::kPrimNot; |
| 819 | DCHECK(locations->CanCall()); |
| 820 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(out_.reg())); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 821 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 822 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 823 | << instruction_->DebugName(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 824 | |
| 825 | __ Bind(GetEntryLabel()); |
| 826 | SaveLiveRegisters(codegen, locations); |
| 827 | |
| 828 | InvokeRuntimeCallingConvention calling_convention; |
| 829 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 830 | // The argument of the ReadBarrierForRootSlow is not a managed |
| 831 | // reference (`mirror::Object*`), but a `GcRoot<mirror::Object>*`; |
| 832 | // thus we need a 64-bit move here, and we cannot use |
| 833 | // |
| 834 | // arm64_codegen->MoveLocation( |
| 835 | // LocationFrom(calling_convention.GetRegisterAt(0)), |
| 836 | // root_, |
| 837 | // type); |
| 838 | // |
| 839 | // which would emit a 32-bit move, as `type` is a (32-bit wide) |
| 840 | // reference type (`Primitive::kPrimNot`). |
| 841 | __ Mov(calling_convention.GetRegisterAt(0), XRegisterFrom(out_)); |
| 842 | arm64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pReadBarrierForRootSlow), |
| 843 | instruction_, |
| 844 | instruction_->GetDexPc(), |
| 845 | this); |
| 846 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 847 | arm64_codegen->MoveLocation(out_, calling_convention.GetReturnLocation(type), type); |
| 848 | |
| 849 | RestoreLiveRegisters(codegen, locations); |
| 850 | __ B(GetExitLabel()); |
| 851 | } |
| 852 | |
| 853 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathARM64"; } |
| 854 | |
| 855 | private: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 856 | const Location out_; |
| 857 | const Location root_; |
| 858 | |
| 859 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathARM64); |
| 860 | }; |
| 861 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 862 | #undef __ |
| 863 | |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 864 | Location InvokeDexCallingConventionVisitorARM64::GetNextLocation(Primitive::Type type) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 865 | Location next_location; |
| 866 | if (type == Primitive::kPrimVoid) { |
| 867 | LOG(FATAL) << "Unreachable type " << type; |
| 868 | } |
| 869 | |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 870 | if (Primitive::IsFloatingPointType(type) && |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 871 | (float_index_ < calling_convention.GetNumberOfFpuRegisters())) { |
| 872 | next_location = LocationFrom(calling_convention.GetFpuRegisterAt(float_index_++)); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 873 | } else if (!Primitive::IsFloatingPointType(type) && |
| 874 | (gp_index_ < calling_convention.GetNumberOfRegisters())) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 875 | next_location = LocationFrom(calling_convention.GetRegisterAt(gp_index_++)); |
| 876 | } else { |
| 877 | size_t stack_offset = calling_convention.GetStackOffsetOf(stack_index_); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 878 | next_location = Primitive::Is64BitType(type) ? Location::DoubleStackSlot(stack_offset) |
| 879 | : Location::StackSlot(stack_offset); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 880 | } |
| 881 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 882 | // Space on the stack is reserved for all arguments. |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 883 | stack_index_ += Primitive::Is64BitType(type) ? 2 : 1; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 884 | return next_location; |
| 885 | } |
| 886 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 887 | Location InvokeDexCallingConventionVisitorARM64::GetMethodLocation() const { |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 888 | return LocationFrom(kArtMethodRegister); |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 889 | } |
| 890 | |
Serban Constantinescu | 579885a | 2015-02-22 20:51:33 +0000 | [diff] [blame] | 891 | CodeGeneratorARM64::CodeGeneratorARM64(HGraph* graph, |
| 892 | const Arm64InstructionSetFeatures& isa_features, |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 893 | const CompilerOptions& compiler_options, |
| 894 | OptimizingCompilerStats* stats) |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 895 | : CodeGenerator(graph, |
| 896 | kNumberOfAllocatableRegisters, |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 897 | kNumberOfAllocatableFPRegisters, |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 898 | kNumberOfAllocatableRegisterPairs, |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 899 | callee_saved_core_registers.list(), |
Nicolas Geoffray | 75d5b9b | 2015-10-05 07:40:35 +0000 | [diff] [blame] | 900 | callee_saved_fp_registers.list(), |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 901 | compiler_options, |
| 902 | stats), |
Alexandre Rames | c01a664 | 2016-04-15 11:54:06 +0100 | [diff] [blame] | 903 | block_labels_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 904 | jump_tables_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 905 | location_builder_(graph, this), |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 906 | instruction_visitor_(graph, this), |
Serban Constantinescu | 579885a | 2015-02-22 20:51:33 +0000 | [diff] [blame] | 907 | move_resolver_(graph->GetArena(), this), |
Vladimir Marko | 93205e3 | 2016-04-13 11:59:46 +0100 | [diff] [blame] | 908 | assembler_(graph->GetArena()), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 909 | isa_features_(isa_features), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 910 | uint32_literals_(std::less<uint32_t>(), |
| 911 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 912 | uint64_literals_(std::less<uint64_t>(), |
| 913 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 914 | method_patches_(MethodReferenceComparator(), |
| 915 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 916 | call_patches_(MethodReferenceComparator(), |
| 917 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 918 | relative_call_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 919 | pc_relative_dex_cache_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 920 | boot_image_string_patches_(StringReferenceValueComparator(), |
| 921 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 922 | pc_relative_string_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 923 | boot_image_address_patches_(std::less<uint32_t>(), |
| 924 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 925 | // Save the link register (containing the return address) to mimic Quick. |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 926 | AddAllocatedRegister(LocationFrom(lr)); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 927 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 928 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 929 | #define __ GetVIXLAssembler()-> |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 930 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 931 | void CodeGeneratorARM64::EmitJumpTables() { |
Alexandre Rames | c01a664 | 2016-04-15 11:54:06 +0100 | [diff] [blame] | 932 | for (auto&& jump_table : jump_tables_) { |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 933 | jump_table->EmitTable(this); |
| 934 | } |
| 935 | } |
| 936 | |
Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 937 | void CodeGeneratorARM64::Finalize(CodeAllocator* allocator) { |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 938 | EmitJumpTables(); |
Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 939 | // Ensure we emit the literal pool. |
| 940 | __ FinalizeCode(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 941 | |
Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 942 | CodeGenerator::Finalize(allocator); |
| 943 | } |
| 944 | |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 945 | void ParallelMoveResolverARM64::PrepareForEmitNativeCode() { |
| 946 | // Note: There are 6 kinds of moves: |
| 947 | // 1. constant -> GPR/FPR (non-cycle) |
| 948 | // 2. constant -> stack (non-cycle) |
| 949 | // 3. GPR/FPR -> GPR/FPR |
| 950 | // 4. GPR/FPR -> stack |
| 951 | // 5. stack -> GPR/FPR |
| 952 | // 6. stack -> stack (non-cycle) |
| 953 | // Case 1, 2 and 6 should never be included in a dependency cycle on ARM64. For case 3, 4, and 5 |
| 954 | // VIXL uses at most 1 GPR. VIXL has 2 GPR and 1 FPR temps, and there should be no intersecting |
| 955 | // cycles on ARM64, so we always have 1 GPR and 1 FPR available VIXL temps to resolve the |
| 956 | // dependency. |
| 957 | vixl_temps_.Open(GetVIXLAssembler()); |
| 958 | } |
| 959 | |
| 960 | void ParallelMoveResolverARM64::FinishEmitNativeCode() { |
| 961 | vixl_temps_.Close(); |
| 962 | } |
| 963 | |
| 964 | Location ParallelMoveResolverARM64::AllocateScratchLocationFor(Location::Kind kind) { |
| 965 | DCHECK(kind == Location::kRegister || kind == Location::kFpuRegister || |
| 966 | kind == Location::kStackSlot || kind == Location::kDoubleStackSlot); |
| 967 | kind = (kind == Location::kFpuRegister) ? Location::kFpuRegister : Location::kRegister; |
| 968 | Location scratch = GetScratchLocation(kind); |
| 969 | if (!scratch.Equals(Location::NoLocation())) { |
| 970 | return scratch; |
| 971 | } |
| 972 | // Allocate from VIXL temp registers. |
| 973 | if (kind == Location::kRegister) { |
| 974 | scratch = LocationFrom(vixl_temps_.AcquireX()); |
| 975 | } else { |
| 976 | DCHECK(kind == Location::kFpuRegister); |
| 977 | scratch = LocationFrom(vixl_temps_.AcquireD()); |
| 978 | } |
| 979 | AddScratchLocation(scratch); |
| 980 | return scratch; |
| 981 | } |
| 982 | |
| 983 | void ParallelMoveResolverARM64::FreeScratchLocation(Location loc) { |
| 984 | if (loc.IsRegister()) { |
| 985 | vixl_temps_.Release(XRegisterFrom(loc)); |
| 986 | } else { |
| 987 | DCHECK(loc.IsFpuRegister()); |
| 988 | vixl_temps_.Release(DRegisterFrom(loc)); |
| 989 | } |
| 990 | RemoveScratchLocation(loc); |
| 991 | } |
| 992 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 993 | void ParallelMoveResolverARM64::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 994 | MoveOperands* move = moves_[index]; |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 995 | codegen_->MoveLocation(move->GetDestination(), move->GetSource(), Primitive::kPrimVoid); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 996 | } |
| 997 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 998 | void CodeGeneratorARM64::GenerateFrameEntry() { |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 999 | MacroAssembler* masm = GetVIXLAssembler(); |
| 1000 | BlockPoolsScope block_pools(masm); |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1001 | __ Bind(&frame_entry_label_); |
| 1002 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1003 | bool do_overflow_check = FrameNeedsStackCheck(GetFrameSize(), kArm64) || !IsLeafMethod(); |
| 1004 | if (do_overflow_check) { |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1005 | UseScratchRegisterScope temps(masm); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1006 | Register temp = temps.AcquireX(); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1007 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1008 | __ Sub(temp, sp, static_cast<int32_t>(GetStackOverflowReservedBytes(kArm64))); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1009 | __ Ldr(wzr, MemOperand(temp, 0)); |
| 1010 | RecordPcInfo(nullptr, 0); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1011 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1012 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1013 | if (!HasEmptyFrame()) { |
| 1014 | int frame_size = GetFrameSize(); |
| 1015 | // Stack layout: |
| 1016 | // sp[frame_size - 8] : lr. |
| 1017 | // ... : other preserved core registers. |
| 1018 | // ... : other preserved fp registers. |
| 1019 | // ... : reserved frame space. |
| 1020 | // sp[0] : current method. |
| 1021 | __ Str(kArtMethodRegister, MemOperand(sp, -frame_size, PreIndex)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1022 | GetAssembler()->cfi().AdjustCFAOffset(frame_size); |
Zheng Xu | 69a5030 | 2015-04-14 20:04:41 +0800 | [diff] [blame] | 1023 | GetAssembler()->SpillRegisters(GetFramePreservedCoreRegisters(), |
| 1024 | frame_size - GetCoreSpillSize()); |
| 1025 | GetAssembler()->SpillRegisters(GetFramePreservedFPRegisters(), |
| 1026 | frame_size - FrameEntrySpillSize()); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1027 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1028 | } |
| 1029 | |
| 1030 | void CodeGeneratorARM64::GenerateFrameExit() { |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1031 | BlockPoolsScope block_pools(GetVIXLAssembler()); |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1032 | GetAssembler()->cfi().RememberState(); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1033 | if (!HasEmptyFrame()) { |
| 1034 | int frame_size = GetFrameSize(); |
Zheng Xu | 69a5030 | 2015-04-14 20:04:41 +0800 | [diff] [blame] | 1035 | GetAssembler()->UnspillRegisters(GetFramePreservedFPRegisters(), |
| 1036 | frame_size - FrameEntrySpillSize()); |
| 1037 | GetAssembler()->UnspillRegisters(GetFramePreservedCoreRegisters(), |
| 1038 | frame_size - GetCoreSpillSize()); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1039 | __ Drop(frame_size); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1040 | GetAssembler()->cfi().AdjustCFAOffset(-frame_size); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1041 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1042 | __ Ret(); |
| 1043 | GetAssembler()->cfi().RestoreState(); |
| 1044 | GetAssembler()->cfi().DefCFAOffset(GetFrameSize()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1045 | } |
| 1046 | |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1047 | vixl::CPURegList CodeGeneratorARM64::GetFramePreservedCoreRegisters() const { |
| 1048 | DCHECK(ArtVixlRegCodeCoherentForRegSet(core_spill_mask_, GetNumberOfCoreRegisters(), 0, 0)); |
| 1049 | return vixl::CPURegList(vixl::CPURegister::kRegister, vixl::kXRegSize, |
| 1050 | core_spill_mask_); |
| 1051 | } |
| 1052 | |
| 1053 | vixl::CPURegList CodeGeneratorARM64::GetFramePreservedFPRegisters() const { |
| 1054 | DCHECK(ArtVixlRegCodeCoherentForRegSet(0, 0, fpu_spill_mask_, |
| 1055 | GetNumberOfFloatingPointRegisters())); |
| 1056 | return vixl::CPURegList(vixl::CPURegister::kFPRegister, vixl::kDRegSize, |
| 1057 | fpu_spill_mask_); |
| 1058 | } |
| 1059 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1060 | void CodeGeneratorARM64::Bind(HBasicBlock* block) { |
| 1061 | __ Bind(GetLabelOf(block)); |
| 1062 | } |
| 1063 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1064 | void CodeGeneratorARM64::MoveConstant(Location location, int32_t value) { |
| 1065 | DCHECK(location.IsRegister()); |
| 1066 | __ Mov(RegisterFrom(location, Primitive::kPrimInt), value); |
| 1067 | } |
| 1068 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1069 | void CodeGeneratorARM64::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1070 | if (location.IsRegister()) { |
| 1071 | locations->AddTemp(location); |
| 1072 | } else { |
| 1073 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1074 | } |
| 1075 | } |
| 1076 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1077 | void CodeGeneratorARM64::MarkGCCard(Register object, Register value, bool value_can_be_null) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1078 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1079 | Register card = temps.AcquireX(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1080 | Register temp = temps.AcquireW(); // Index within the CardTable - 32bit. |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1081 | vixl::Label done; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1082 | if (value_can_be_null) { |
| 1083 | __ Cbz(value, &done); |
| 1084 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1085 | __ Ldr(card, MemOperand(tr, Thread::CardTableOffset<kArm64WordSize>().Int32Value())); |
| 1086 | __ Lsr(temp, object, gc::accounting::CardTable::kCardShift); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1087 | __ Strb(card, MemOperand(card, temp.X())); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1088 | if (value_can_be_null) { |
| 1089 | __ Bind(&done); |
| 1090 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1091 | } |
| 1092 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1093 | void CodeGeneratorARM64::SetupBlockedRegisters() const { |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1094 | // Blocked core registers: |
| 1095 | // lr : Runtime reserved. |
| 1096 | // tr : Runtime reserved. |
| 1097 | // xSuspend : Runtime reserved. TODO: Unblock this when the runtime stops using it. |
| 1098 | // ip1 : VIXL core temp. |
| 1099 | // ip0 : VIXL core temp. |
| 1100 | // |
| 1101 | // Blocked fp registers: |
| 1102 | // d31 : VIXL fp temp. |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1103 | CPURegList reserved_core_registers = vixl_reserved_core_registers; |
| 1104 | reserved_core_registers.Combine(runtime_reserved_core_registers); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1105 | while (!reserved_core_registers.IsEmpty()) { |
| 1106 | blocked_core_registers_[reserved_core_registers.PopLowestIndex().code()] = true; |
| 1107 | } |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1108 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1109 | CPURegList reserved_fp_registers = vixl_reserved_fp_registers; |
Zheng Xu | a3ec394 | 2015-02-15 18:39:46 +0800 | [diff] [blame] | 1110 | while (!reserved_fp_registers.IsEmpty()) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1111 | blocked_fpu_registers_[reserved_fp_registers.PopLowestIndex().code()] = true; |
| 1112 | } |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1113 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1114 | if (GetGraph()->IsDebuggable()) { |
Nicolas Geoffray | ecf680d | 2015-10-05 11:15:37 +0100 | [diff] [blame] | 1115 | // Stubs do not save callee-save floating point registers. If the graph |
| 1116 | // is debuggable, we need to deal with these registers differently. For |
| 1117 | // now, just block them. |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1118 | CPURegList reserved_fp_registers_debuggable = callee_saved_fp_registers; |
| 1119 | while (!reserved_fp_registers_debuggable.IsEmpty()) { |
| 1120 | blocked_fpu_registers_[reserved_fp_registers_debuggable.PopLowestIndex().code()] = true; |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1121 | } |
| 1122 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1123 | } |
| 1124 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1125 | size_t CodeGeneratorARM64::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1126 | Register reg = Register(VIXLRegCodeFromART(reg_id), kXRegSize); |
| 1127 | __ Str(reg, MemOperand(sp, stack_index)); |
| 1128 | return kArm64WordSize; |
| 1129 | } |
| 1130 | |
| 1131 | size_t CodeGeneratorARM64::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1132 | Register reg = Register(VIXLRegCodeFromART(reg_id), kXRegSize); |
| 1133 | __ Ldr(reg, MemOperand(sp, stack_index)); |
| 1134 | return kArm64WordSize; |
| 1135 | } |
| 1136 | |
| 1137 | size_t CodeGeneratorARM64::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 1138 | FPRegister reg = FPRegister(reg_id, kDRegSize); |
| 1139 | __ Str(reg, MemOperand(sp, stack_index)); |
| 1140 | return kArm64WordSize; |
| 1141 | } |
| 1142 | |
| 1143 | size_t CodeGeneratorARM64::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 1144 | FPRegister reg = FPRegister(reg_id, kDRegSize); |
| 1145 | __ Ldr(reg, MemOperand(sp, stack_index)); |
| 1146 | return kArm64WordSize; |
| 1147 | } |
| 1148 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1149 | void CodeGeneratorARM64::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1150 | stream << XRegister(reg); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1151 | } |
| 1152 | |
| 1153 | void CodeGeneratorARM64::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1154 | stream << DRegister(reg); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1155 | } |
| 1156 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1157 | void CodeGeneratorARM64::MoveConstant(CPURegister destination, HConstant* constant) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1158 | if (constant->IsIntConstant()) { |
| 1159 | __ Mov(Register(destination), constant->AsIntConstant()->GetValue()); |
| 1160 | } else if (constant->IsLongConstant()) { |
| 1161 | __ Mov(Register(destination), constant->AsLongConstant()->GetValue()); |
| 1162 | } else if (constant->IsNullConstant()) { |
| 1163 | __ Mov(Register(destination), 0); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1164 | } else if (constant->IsFloatConstant()) { |
| 1165 | __ Fmov(FPRegister(destination), constant->AsFloatConstant()->GetValue()); |
| 1166 | } else { |
| 1167 | DCHECK(constant->IsDoubleConstant()); |
| 1168 | __ Fmov(FPRegister(destination), constant->AsDoubleConstant()->GetValue()); |
| 1169 | } |
| 1170 | } |
| 1171 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1172 | |
| 1173 | static bool CoherentConstantAndType(Location constant, Primitive::Type type) { |
| 1174 | DCHECK(constant.IsConstant()); |
| 1175 | HConstant* cst = constant.GetConstant(); |
| 1176 | return (cst->IsIntConstant() && type == Primitive::kPrimInt) || |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1177 | // Null is mapped to a core W register, which we associate with kPrimInt. |
| 1178 | (cst->IsNullConstant() && type == Primitive::kPrimInt) || |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1179 | (cst->IsLongConstant() && type == Primitive::kPrimLong) || |
| 1180 | (cst->IsFloatConstant() && type == Primitive::kPrimFloat) || |
| 1181 | (cst->IsDoubleConstant() && type == Primitive::kPrimDouble); |
| 1182 | } |
| 1183 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1184 | void CodeGeneratorARM64::MoveLocation(Location destination, |
| 1185 | Location source, |
| 1186 | Primitive::Type dst_type) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1187 | if (source.Equals(destination)) { |
| 1188 | return; |
| 1189 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1190 | |
| 1191 | // A valid move can always be inferred from the destination and source |
| 1192 | // locations. When moving from and to a register, the argument type can be |
| 1193 | // used to generate 32bit instead of 64bit moves. In debug mode we also |
| 1194 | // checks the coherency of the locations and the type. |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1195 | bool unspecified_type = (dst_type == Primitive::kPrimVoid); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1196 | |
| 1197 | if (destination.IsRegister() || destination.IsFpuRegister()) { |
| 1198 | if (unspecified_type) { |
| 1199 | HConstant* src_cst = source.IsConstant() ? source.GetConstant() : nullptr; |
| 1200 | if (source.IsStackSlot() || |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1201 | (src_cst != nullptr && (src_cst->IsIntConstant() |
| 1202 | || src_cst->IsFloatConstant() |
| 1203 | || src_cst->IsNullConstant()))) { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1204 | // For stack slots and 32bit constants, a 64bit type is appropriate. |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1205 | dst_type = destination.IsRegister() ? Primitive::kPrimInt : Primitive::kPrimFloat; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1206 | } else { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1207 | // If the source is a double stack slot or a 64bit constant, a 64bit |
| 1208 | // type is appropriate. Else the source is a register, and since the |
| 1209 | // type has not been specified, we chose a 64bit type to force a 64bit |
| 1210 | // move. |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1211 | dst_type = destination.IsRegister() ? Primitive::kPrimLong : Primitive::kPrimDouble; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1212 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1213 | } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1214 | DCHECK((destination.IsFpuRegister() && Primitive::IsFloatingPointType(dst_type)) || |
| 1215 | (destination.IsRegister() && !Primitive::IsFloatingPointType(dst_type))); |
| 1216 | CPURegister dst = CPURegisterFrom(destination, dst_type); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1217 | if (source.IsStackSlot() || source.IsDoubleStackSlot()) { |
| 1218 | DCHECK(dst.Is64Bits() == source.IsDoubleStackSlot()); |
| 1219 | __ Ldr(dst, StackOperandFrom(source)); |
| 1220 | } else if (source.IsConstant()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1221 | DCHECK(CoherentConstantAndType(source, dst_type)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1222 | MoveConstant(dst, source.GetConstant()); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1223 | } else if (source.IsRegister()) { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1224 | if (destination.IsRegister()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1225 | __ Mov(Register(dst), RegisterFrom(source, dst_type)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1226 | } else { |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1227 | DCHECK(destination.IsFpuRegister()); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1228 | Primitive::Type source_type = Primitive::Is64BitType(dst_type) |
| 1229 | ? Primitive::kPrimLong |
| 1230 | : Primitive::kPrimInt; |
| 1231 | __ Fmov(FPRegisterFrom(destination, dst_type), RegisterFrom(source, source_type)); |
| 1232 | } |
| 1233 | } else { |
| 1234 | DCHECK(source.IsFpuRegister()); |
| 1235 | if (destination.IsRegister()) { |
| 1236 | Primitive::Type source_type = Primitive::Is64BitType(dst_type) |
| 1237 | ? Primitive::kPrimDouble |
| 1238 | : Primitive::kPrimFloat; |
| 1239 | __ Fmov(RegisterFrom(destination, dst_type), FPRegisterFrom(source, source_type)); |
| 1240 | } else { |
| 1241 | DCHECK(destination.IsFpuRegister()); |
| 1242 | __ Fmov(FPRegister(dst), FPRegisterFrom(source, dst_type)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1243 | } |
| 1244 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1245 | } else { // The destination is not a register. It must be a stack slot. |
| 1246 | DCHECK(destination.IsStackSlot() || destination.IsDoubleStackSlot()); |
| 1247 | if (source.IsRegister() || source.IsFpuRegister()) { |
| 1248 | if (unspecified_type) { |
| 1249 | if (source.IsRegister()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1250 | dst_type = destination.IsStackSlot() ? Primitive::kPrimInt : Primitive::kPrimLong; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1251 | } else { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1252 | dst_type = destination.IsStackSlot() ? Primitive::kPrimFloat : Primitive::kPrimDouble; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1253 | } |
| 1254 | } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1255 | DCHECK((destination.IsDoubleStackSlot() == Primitive::Is64BitType(dst_type)) && |
| 1256 | (source.IsFpuRegister() == Primitive::IsFloatingPointType(dst_type))); |
| 1257 | __ Str(CPURegisterFrom(source, dst_type), StackOperandFrom(destination)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1258 | } else if (source.IsConstant()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1259 | DCHECK(unspecified_type || CoherentConstantAndType(source, dst_type)) |
| 1260 | << source << " " << dst_type; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1261 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 1262 | HConstant* src_cst = source.GetConstant(); |
| 1263 | CPURegister temp; |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1264 | if (src_cst->IsIntConstant() || src_cst->IsNullConstant()) { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1265 | temp = temps.AcquireW(); |
| 1266 | } else if (src_cst->IsLongConstant()) { |
| 1267 | temp = temps.AcquireX(); |
| 1268 | } else if (src_cst->IsFloatConstant()) { |
| 1269 | temp = temps.AcquireS(); |
| 1270 | } else { |
| 1271 | DCHECK(src_cst->IsDoubleConstant()); |
| 1272 | temp = temps.AcquireD(); |
| 1273 | } |
| 1274 | MoveConstant(temp, src_cst); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1275 | __ Str(temp, StackOperandFrom(destination)); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1276 | } else { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1277 | DCHECK(source.IsStackSlot() || source.IsDoubleStackSlot()); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1278 | DCHECK(source.IsDoubleStackSlot() == destination.IsDoubleStackSlot()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1279 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1280 | // There is generally less pressure on FP registers. |
| 1281 | FPRegister temp = destination.IsDoubleStackSlot() ? temps.AcquireD() : temps.AcquireS(); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1282 | __ Ldr(temp, StackOperandFrom(source)); |
| 1283 | __ Str(temp, StackOperandFrom(destination)); |
| 1284 | } |
| 1285 | } |
| 1286 | } |
| 1287 | |
| 1288 | void CodeGeneratorARM64::Load(Primitive::Type type, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1289 | CPURegister dst, |
| 1290 | const MemOperand& src) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1291 | switch (type) { |
| 1292 | case Primitive::kPrimBoolean: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1293 | __ Ldrb(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1294 | break; |
| 1295 | case Primitive::kPrimByte: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1296 | __ Ldrsb(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1297 | break; |
| 1298 | case Primitive::kPrimShort: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1299 | __ Ldrsh(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1300 | break; |
| 1301 | case Primitive::kPrimChar: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1302 | __ Ldrh(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1303 | break; |
| 1304 | case Primitive::kPrimInt: |
| 1305 | case Primitive::kPrimNot: |
| 1306 | case Primitive::kPrimLong: |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1307 | case Primitive::kPrimFloat: |
| 1308 | case Primitive::kPrimDouble: |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 1309 | DCHECK_EQ(dst.Is64Bits(), Primitive::Is64BitType(type)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1310 | __ Ldr(dst, src); |
| 1311 | break; |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1312 | case Primitive::kPrimVoid: |
| 1313 | LOG(FATAL) << "Unreachable type " << type; |
| 1314 | } |
| 1315 | } |
| 1316 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1317 | void CodeGeneratorARM64::LoadAcquire(HInstruction* instruction, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1318 | CPURegister dst, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1319 | const MemOperand& src, |
| 1320 | bool needs_null_check) { |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1321 | MacroAssembler* masm = GetVIXLAssembler(); |
| 1322 | BlockPoolsScope block_pools(masm); |
| 1323 | UseScratchRegisterScope temps(masm); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1324 | Register temp_base = temps.AcquireX(); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1325 | Primitive::Type type = instruction->GetType(); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1326 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1327 | DCHECK(!src.IsPreIndex()); |
| 1328 | DCHECK(!src.IsPostIndex()); |
| 1329 | |
| 1330 | // TODO(vixl): Let the MacroAssembler handle MemOperand. |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 1331 | __ Add(temp_base, src.base(), OperandFromMemOperand(src)); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1332 | MemOperand base = MemOperand(temp_base); |
| 1333 | switch (type) { |
| 1334 | case Primitive::kPrimBoolean: |
| 1335 | __ Ldarb(Register(dst), base); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1336 | if (needs_null_check) { |
| 1337 | MaybeRecordImplicitNullCheck(instruction); |
| 1338 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1339 | break; |
| 1340 | case Primitive::kPrimByte: |
| 1341 | __ Ldarb(Register(dst), base); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1342 | if (needs_null_check) { |
| 1343 | MaybeRecordImplicitNullCheck(instruction); |
| 1344 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1345 | __ Sbfx(Register(dst), Register(dst), 0, Primitive::ComponentSize(type) * kBitsPerByte); |
| 1346 | break; |
| 1347 | case Primitive::kPrimChar: |
| 1348 | __ Ldarh(Register(dst), base); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1349 | if (needs_null_check) { |
| 1350 | MaybeRecordImplicitNullCheck(instruction); |
| 1351 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1352 | break; |
| 1353 | case Primitive::kPrimShort: |
| 1354 | __ Ldarh(Register(dst), base); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1355 | if (needs_null_check) { |
| 1356 | MaybeRecordImplicitNullCheck(instruction); |
| 1357 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1358 | __ Sbfx(Register(dst), Register(dst), 0, Primitive::ComponentSize(type) * kBitsPerByte); |
| 1359 | break; |
| 1360 | case Primitive::kPrimInt: |
| 1361 | case Primitive::kPrimNot: |
| 1362 | case Primitive::kPrimLong: |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 1363 | DCHECK_EQ(dst.Is64Bits(), Primitive::Is64BitType(type)); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1364 | __ Ldar(Register(dst), base); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1365 | if (needs_null_check) { |
| 1366 | MaybeRecordImplicitNullCheck(instruction); |
| 1367 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1368 | break; |
| 1369 | case Primitive::kPrimFloat: |
| 1370 | case Primitive::kPrimDouble: { |
| 1371 | DCHECK(dst.IsFPRegister()); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 1372 | DCHECK_EQ(dst.Is64Bits(), Primitive::Is64BitType(type)); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1373 | |
| 1374 | Register temp = dst.Is64Bits() ? temps.AcquireX() : temps.AcquireW(); |
| 1375 | __ Ldar(temp, base); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1376 | if (needs_null_check) { |
| 1377 | MaybeRecordImplicitNullCheck(instruction); |
| 1378 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1379 | __ Fmov(FPRegister(dst), temp); |
| 1380 | break; |
| 1381 | } |
| 1382 | case Primitive::kPrimVoid: |
| 1383 | LOG(FATAL) << "Unreachable type " << type; |
| 1384 | } |
| 1385 | } |
| 1386 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1387 | void CodeGeneratorARM64::Store(Primitive::Type type, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1388 | CPURegister src, |
| 1389 | const MemOperand& dst) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1390 | switch (type) { |
| 1391 | case Primitive::kPrimBoolean: |
| 1392 | case Primitive::kPrimByte: |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1393 | __ Strb(Register(src), dst); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1394 | break; |
| 1395 | case Primitive::kPrimChar: |
| 1396 | case Primitive::kPrimShort: |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1397 | __ Strh(Register(src), dst); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1398 | break; |
| 1399 | case Primitive::kPrimInt: |
| 1400 | case Primitive::kPrimNot: |
| 1401 | case Primitive::kPrimLong: |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1402 | case Primitive::kPrimFloat: |
| 1403 | case Primitive::kPrimDouble: |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 1404 | DCHECK_EQ(src.Is64Bits(), Primitive::Is64BitType(type)); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1405 | __ Str(src, dst); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1406 | break; |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1407 | case Primitive::kPrimVoid: |
| 1408 | LOG(FATAL) << "Unreachable type " << type; |
| 1409 | } |
| 1410 | } |
| 1411 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1412 | void CodeGeneratorARM64::StoreRelease(Primitive::Type type, |
| 1413 | CPURegister src, |
| 1414 | const MemOperand& dst) { |
| 1415 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 1416 | Register temp_base = temps.AcquireX(); |
| 1417 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1418 | DCHECK(!dst.IsPreIndex()); |
| 1419 | DCHECK(!dst.IsPostIndex()); |
| 1420 | |
| 1421 | // TODO(vixl): Let the MacroAssembler handle this. |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 1422 | Operand op = OperandFromMemOperand(dst); |
| 1423 | __ Add(temp_base, dst.base(), op); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1424 | MemOperand base = MemOperand(temp_base); |
| 1425 | switch (type) { |
| 1426 | case Primitive::kPrimBoolean: |
| 1427 | case Primitive::kPrimByte: |
| 1428 | __ Stlrb(Register(src), base); |
| 1429 | break; |
| 1430 | case Primitive::kPrimChar: |
| 1431 | case Primitive::kPrimShort: |
| 1432 | __ Stlrh(Register(src), base); |
| 1433 | break; |
| 1434 | case Primitive::kPrimInt: |
| 1435 | case Primitive::kPrimNot: |
| 1436 | case Primitive::kPrimLong: |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 1437 | DCHECK_EQ(src.Is64Bits(), Primitive::Is64BitType(type)); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1438 | __ Stlr(Register(src), base); |
| 1439 | break; |
| 1440 | case Primitive::kPrimFloat: |
| 1441 | case Primitive::kPrimDouble: { |
| 1442 | DCHECK(src.IsFPRegister()); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 1443 | DCHECK_EQ(src.Is64Bits(), Primitive::Is64BitType(type)); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1444 | |
| 1445 | Register temp = src.Is64Bits() ? temps.AcquireX() : temps.AcquireW(); |
| 1446 | __ Fmov(temp, FPRegister(src)); |
| 1447 | __ Stlr(temp, base); |
| 1448 | break; |
| 1449 | } |
| 1450 | case Primitive::kPrimVoid: |
| 1451 | LOG(FATAL) << "Unreachable type " << type; |
| 1452 | } |
| 1453 | } |
| 1454 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1455 | void CodeGeneratorARM64::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 1456 | HInstruction* instruction, |
| 1457 | uint32_t dex_pc, |
| 1458 | SlowPathCode* slow_path) { |
| 1459 | InvokeRuntime(GetThreadOffset<kArm64WordSize>(entrypoint).Int32Value(), |
| 1460 | instruction, |
| 1461 | dex_pc, |
| 1462 | slow_path); |
| 1463 | } |
| 1464 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1465 | void CodeGeneratorARM64::InvokeRuntime(int32_t entry_point_offset, |
| 1466 | HInstruction* instruction, |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 1467 | uint32_t dex_pc, |
| 1468 | SlowPathCode* slow_path) { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1469 | ValidateInvokeRuntime(instruction, slow_path); |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1470 | BlockPoolsScope block_pools(GetVIXLAssembler()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1471 | __ Ldr(lr, MemOperand(tr, entry_point_offset)); |
| 1472 | __ Blr(lr); |
Roland Levillain | 896e32d | 2015-05-05 18:07:10 +0100 | [diff] [blame] | 1473 | RecordPcInfo(instruction, dex_pc, slow_path); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1474 | } |
| 1475 | |
| 1476 | void InstructionCodeGeneratorARM64::GenerateClassInitializationCheck(SlowPathCodeARM64* slow_path, |
| 1477 | vixl::Register class_reg) { |
| 1478 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 1479 | Register temp = temps.AcquireW(); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1480 | size_t status_offset = mirror::Class::StatusOffset().SizeValue(); |
| 1481 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1482 | // Even if the initialized flag is set, we need to ensure consistent memory ordering. |
Serban Constantinescu | 4a6a67c | 2016-01-27 09:19:56 +0000 | [diff] [blame] | 1483 | // TODO(vixl): Let the MacroAssembler handle MemOperand. |
| 1484 | __ Add(temp, class_reg, status_offset); |
| 1485 | __ Ldar(temp, HeapOperand(temp)); |
| 1486 | __ Cmp(temp, mirror::Class::kStatusInitialized); |
| 1487 | __ B(lt, slow_path->GetEntryLabel()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1488 | __ Bind(slow_path->GetExitLabel()); |
| 1489 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1490 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1491 | void CodeGeneratorARM64::GenerateMemoryBarrier(MemBarrierKind kind) { |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1492 | BarrierType type = BarrierAll; |
| 1493 | |
| 1494 | switch (kind) { |
| 1495 | case MemBarrierKind::kAnyAny: |
| 1496 | case MemBarrierKind::kAnyStore: { |
| 1497 | type = BarrierAll; |
| 1498 | break; |
| 1499 | } |
| 1500 | case MemBarrierKind::kLoadAny: { |
| 1501 | type = BarrierReads; |
| 1502 | break; |
| 1503 | } |
| 1504 | case MemBarrierKind::kStoreStore: { |
| 1505 | type = BarrierWrites; |
| 1506 | break; |
| 1507 | } |
| 1508 | default: |
| 1509 | LOG(FATAL) << "Unexpected memory barrier " << kind; |
| 1510 | } |
| 1511 | __ Dmb(InnerShareable, type); |
| 1512 | } |
| 1513 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1514 | void InstructionCodeGeneratorARM64::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 1515 | HBasicBlock* successor) { |
| 1516 | SuspendCheckSlowPathARM64* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 1517 | down_cast<SuspendCheckSlowPathARM64*>(instruction->GetSlowPath()); |
| 1518 | if (slow_path == nullptr) { |
| 1519 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathARM64(instruction, successor); |
| 1520 | instruction->SetSlowPath(slow_path); |
| 1521 | codegen_->AddSlowPath(slow_path); |
| 1522 | if (successor != nullptr) { |
| 1523 | DCHECK(successor->IsLoopHeader()); |
| 1524 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 1525 | } |
| 1526 | } else { |
| 1527 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 1528 | } |
| 1529 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1530 | UseScratchRegisterScope temps(codegen_->GetVIXLAssembler()); |
| 1531 | Register temp = temps.AcquireW(); |
| 1532 | |
| 1533 | __ Ldrh(temp, MemOperand(tr, Thread::ThreadFlagsOffset<kArm64WordSize>().SizeValue())); |
| 1534 | if (successor == nullptr) { |
| 1535 | __ Cbnz(temp, slow_path->GetEntryLabel()); |
| 1536 | __ Bind(slow_path->GetReturnLabel()); |
| 1537 | } else { |
| 1538 | __ Cbz(temp, codegen_->GetLabelOf(successor)); |
| 1539 | __ B(slow_path->GetEntryLabel()); |
| 1540 | // slow_path will return to GetLabelOf(successor). |
| 1541 | } |
| 1542 | } |
| 1543 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1544 | InstructionCodeGeneratorARM64::InstructionCodeGeneratorARM64(HGraph* graph, |
| 1545 | CodeGeneratorARM64* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1546 | : InstructionCodeGenerator(graph, codegen), |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1547 | assembler_(codegen->GetAssembler()), |
| 1548 | codegen_(codegen) {} |
| 1549 | |
| 1550 | #define FOR_EACH_UNIMPLEMENTED_INSTRUCTION(M) \ |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1551 | /* No unimplemented IR. */ |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1552 | |
| 1553 | #define UNIMPLEMENTED_INSTRUCTION_BREAK_CODE(name) name##UnimplementedInstructionBreakCode |
| 1554 | |
| 1555 | enum UnimplementedInstructionBreakCode { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1556 | // Using a base helps identify when we hit such breakpoints. |
| 1557 | UnimplementedInstructionBreakCodeBaseCode = 0x900, |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1558 | #define ENUM_UNIMPLEMENTED_INSTRUCTION(name) UNIMPLEMENTED_INSTRUCTION_BREAK_CODE(name), |
| 1559 | FOR_EACH_UNIMPLEMENTED_INSTRUCTION(ENUM_UNIMPLEMENTED_INSTRUCTION) |
| 1560 | #undef ENUM_UNIMPLEMENTED_INSTRUCTION |
| 1561 | }; |
| 1562 | |
| 1563 | #define DEFINE_UNIMPLEMENTED_INSTRUCTION_VISITORS(name) \ |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1564 | void InstructionCodeGeneratorARM64::Visit##name(H##name* instr ATTRIBUTE_UNUSED) { \ |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1565 | __ Brk(UNIMPLEMENTED_INSTRUCTION_BREAK_CODE(name)); \ |
| 1566 | } \ |
| 1567 | void LocationsBuilderARM64::Visit##name(H##name* instr) { \ |
| 1568 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr); \ |
| 1569 | locations->SetOut(Location::Any()); \ |
| 1570 | } |
| 1571 | FOR_EACH_UNIMPLEMENTED_INSTRUCTION(DEFINE_UNIMPLEMENTED_INSTRUCTION_VISITORS) |
| 1572 | #undef DEFINE_UNIMPLEMENTED_INSTRUCTION_VISITORS |
| 1573 | |
| 1574 | #undef UNIMPLEMENTED_INSTRUCTION_BREAK_CODE |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1575 | #undef FOR_EACH_UNIMPLEMENTED_INSTRUCTION |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1576 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1577 | void LocationsBuilderARM64::HandleBinaryOp(HBinaryOperation* instr) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1578 | DCHECK_EQ(instr->InputCount(), 2U); |
| 1579 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr); |
| 1580 | Primitive::Type type = instr->GetResultType(); |
| 1581 | switch (type) { |
| 1582 | case Primitive::kPrimInt: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1583 | case Primitive::kPrimLong: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1584 | locations->SetInAt(0, Location::RequiresRegister()); |
Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 1585 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instr->InputAt(1), instr)); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 1586 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1587 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1588 | |
| 1589 | case Primitive::kPrimFloat: |
| 1590 | case Primitive::kPrimDouble: |
| 1591 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1592 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1593 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1594 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1595 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1596 | default: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1597 | LOG(FATAL) << "Unexpected " << instr->DebugName() << " type " << type; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1598 | } |
| 1599 | } |
| 1600 | |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1601 | void LocationsBuilderARM64::HandleFieldGet(HInstruction* instruction) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1602 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 1603 | |
| 1604 | bool object_field_get_with_read_barrier = |
| 1605 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1606 | LocationSummary* locations = |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1607 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 1608 | object_field_get_with_read_barrier ? |
| 1609 | LocationSummary::kCallOnSlowPath : |
| 1610 | LocationSummary::kNoCall); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1611 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1612 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 1613 | locations->SetOut(Location::RequiresFpuRegister()); |
| 1614 | } else { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1615 | // The output overlaps for an object field get when read barriers |
| 1616 | // are enabled: we do not want the load to overwrite the object's |
| 1617 | // location, as we need it to emit the read barrier. |
| 1618 | locations->SetOut( |
| 1619 | Location::RequiresRegister(), |
| 1620 | object_field_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1621 | } |
| 1622 | } |
| 1623 | |
| 1624 | void InstructionCodeGeneratorARM64::HandleFieldGet(HInstruction* instruction, |
| 1625 | const FieldInfo& field_info) { |
| 1626 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1627 | LocationSummary* locations = instruction->GetLocations(); |
| 1628 | Location base_loc = locations->InAt(0); |
| 1629 | Location out = locations->Out(); |
| 1630 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1631 | Primitive::Type field_type = field_info.GetFieldType(); |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1632 | BlockPoolsScope block_pools(GetVIXLAssembler()); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1633 | MemOperand field = HeapOperand(InputRegisterAt(instruction, 0), field_info.GetFieldOffset()); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1634 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1635 | if (field_type == Primitive::kPrimNot && kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 1636 | // Object FieldGet with Baker's read barrier case. |
| 1637 | MacroAssembler* masm = GetVIXLAssembler(); |
| 1638 | UseScratchRegisterScope temps(masm); |
| 1639 | // /* HeapReference<Object> */ out = *(base + offset) |
| 1640 | Register base = RegisterFrom(base_loc, Primitive::kPrimNot); |
| 1641 | Register temp = temps.AcquireW(); |
| 1642 | // Note that potential implicit null checks are handled in this |
| 1643 | // CodeGeneratorARM64::GenerateFieldLoadWithBakerReadBarrier call. |
| 1644 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 1645 | instruction, |
| 1646 | out, |
| 1647 | base, |
| 1648 | offset, |
| 1649 | temp, |
| 1650 | /* needs_null_check */ true, |
Serban Constantinescu | 4a6a67c | 2016-01-27 09:19:56 +0000 | [diff] [blame] | 1651 | field_info.IsVolatile()); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1652 | } else { |
| 1653 | // General case. |
| 1654 | if (field_info.IsVolatile()) { |
Serban Constantinescu | 4a6a67c | 2016-01-27 09:19:56 +0000 | [diff] [blame] | 1655 | // Note that a potential implicit null check is handled in this |
| 1656 | // CodeGeneratorARM64::LoadAcquire call. |
| 1657 | // NB: LoadAcquire will record the pc info if needed. |
| 1658 | codegen_->LoadAcquire( |
| 1659 | instruction, OutputCPURegister(instruction), field, /* needs_null_check */ true); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1660 | } else { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1661 | codegen_->Load(field_type, OutputCPURegister(instruction), field); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1662 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1663 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1664 | if (field_type == Primitive::kPrimNot) { |
| 1665 | // If read barriers are enabled, emit read barriers other than |
| 1666 | // Baker's using a slow path (and also unpoison the loaded |
| 1667 | // reference, if heap poisoning is enabled). |
| 1668 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 1669 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1670 | } |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1671 | } |
| 1672 | |
| 1673 | void LocationsBuilderARM64::HandleFieldSet(HInstruction* instruction) { |
| 1674 | LocationSummary* locations = |
| 1675 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 1676 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1677 | if (Primitive::IsFloatingPointType(instruction->InputAt(1)->GetType())) { |
| 1678 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1679 | } else { |
| 1680 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1681 | } |
| 1682 | } |
| 1683 | |
| 1684 | void InstructionCodeGeneratorARM64::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1685 | const FieldInfo& field_info, |
| 1686 | bool value_can_be_null) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1687 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1688 | BlockPoolsScope block_pools(GetVIXLAssembler()); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1689 | |
| 1690 | Register obj = InputRegisterAt(instruction, 0); |
| 1691 | CPURegister value = InputCPURegisterAt(instruction, 1); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1692 | CPURegister source = value; |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1693 | Offset offset = field_info.GetFieldOffset(); |
| 1694 | Primitive::Type field_type = field_info.GetFieldType(); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1695 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1696 | { |
| 1697 | // We use a block to end the scratch scope before the write barrier, thus |
| 1698 | // freeing the temporary registers so they can be used in `MarkGCCard`. |
| 1699 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 1700 | |
| 1701 | if (kPoisonHeapReferences && field_type == Primitive::kPrimNot) { |
| 1702 | DCHECK(value.IsW()); |
| 1703 | Register temp = temps.AcquireW(); |
| 1704 | __ Mov(temp, value.W()); |
| 1705 | GetAssembler()->PoisonHeapReference(temp.W()); |
| 1706 | source = temp; |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1707 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1708 | |
| 1709 | if (field_info.IsVolatile()) { |
Serban Constantinescu | 4a6a67c | 2016-01-27 09:19:56 +0000 | [diff] [blame] | 1710 | codegen_->StoreRelease(field_type, source, HeapOperand(obj, offset)); |
| 1711 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1712 | } else { |
| 1713 | codegen_->Store(field_type, source, HeapOperand(obj, offset)); |
| 1714 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 1715 | } |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1716 | } |
| 1717 | |
| 1718 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1719 | codegen_->MarkGCCard(obj, Register(value), value_can_be_null); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1720 | } |
| 1721 | } |
| 1722 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1723 | void InstructionCodeGeneratorARM64::HandleBinaryOp(HBinaryOperation* instr) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1724 | Primitive::Type type = instr->GetType(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1725 | |
| 1726 | switch (type) { |
| 1727 | case Primitive::kPrimInt: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1728 | case Primitive::kPrimLong: { |
| 1729 | Register dst = OutputRegister(instr); |
| 1730 | Register lhs = InputRegisterAt(instr, 0); |
| 1731 | Operand rhs = InputOperandAt(instr, 1); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1732 | if (instr->IsAdd()) { |
| 1733 | __ Add(dst, lhs, rhs); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1734 | } else if (instr->IsAnd()) { |
| 1735 | __ And(dst, lhs, rhs); |
| 1736 | } else if (instr->IsOr()) { |
| 1737 | __ Orr(dst, lhs, rhs); |
| 1738 | } else if (instr->IsSub()) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1739 | __ Sub(dst, lhs, rhs); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 1740 | } else if (instr->IsRor()) { |
| 1741 | if (rhs.IsImmediate()) { |
| 1742 | uint32_t shift = rhs.immediate() & (lhs.SizeInBits() - 1); |
| 1743 | __ Ror(dst, lhs, shift); |
| 1744 | } else { |
| 1745 | // Ensure shift distance is in the same size register as the result. If |
| 1746 | // we are rotating a long and the shift comes in a w register originally, |
| 1747 | // we don't need to sxtw for use as an x since the shift distances are |
| 1748 | // all & reg_bits - 1. |
| 1749 | __ Ror(dst, lhs, RegisterFrom(instr->GetLocations()->InAt(1), type)); |
| 1750 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1751 | } else { |
| 1752 | DCHECK(instr->IsXor()); |
| 1753 | __ Eor(dst, lhs, rhs); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1754 | } |
| 1755 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1756 | } |
| 1757 | case Primitive::kPrimFloat: |
| 1758 | case Primitive::kPrimDouble: { |
| 1759 | FPRegister dst = OutputFPRegister(instr); |
| 1760 | FPRegister lhs = InputFPRegisterAt(instr, 0); |
| 1761 | FPRegister rhs = InputFPRegisterAt(instr, 1); |
| 1762 | if (instr->IsAdd()) { |
| 1763 | __ Fadd(dst, lhs, rhs); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1764 | } else if (instr->IsSub()) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1765 | __ Fsub(dst, lhs, rhs); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1766 | } else { |
| 1767 | LOG(FATAL) << "Unexpected floating-point binary operation"; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1768 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1769 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1770 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1771 | default: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1772 | LOG(FATAL) << "Unexpected binary operation type " << type; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1773 | } |
| 1774 | } |
| 1775 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1776 | void LocationsBuilderARM64::HandleShift(HBinaryOperation* instr) { |
| 1777 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr()); |
| 1778 | |
| 1779 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr); |
| 1780 | Primitive::Type type = instr->GetResultType(); |
| 1781 | switch (type) { |
| 1782 | case Primitive::kPrimInt: |
| 1783 | case Primitive::kPrimLong: { |
| 1784 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1785 | locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1))); |
| 1786 | locations->SetOut(Location::RequiresRegister()); |
| 1787 | break; |
| 1788 | } |
| 1789 | default: |
| 1790 | LOG(FATAL) << "Unexpected shift type " << type; |
| 1791 | } |
| 1792 | } |
| 1793 | |
| 1794 | void InstructionCodeGeneratorARM64::HandleShift(HBinaryOperation* instr) { |
| 1795 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr()); |
| 1796 | |
| 1797 | Primitive::Type type = instr->GetType(); |
| 1798 | switch (type) { |
| 1799 | case Primitive::kPrimInt: |
| 1800 | case Primitive::kPrimLong: { |
| 1801 | Register dst = OutputRegister(instr); |
| 1802 | Register lhs = InputRegisterAt(instr, 0); |
| 1803 | Operand rhs = InputOperandAt(instr, 1); |
| 1804 | if (rhs.IsImmediate()) { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 1805 | uint32_t shift_value = rhs.immediate() & |
| 1806 | (type == Primitive::kPrimInt ? kMaxIntShiftDistance : kMaxLongShiftDistance); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1807 | if (instr->IsShl()) { |
| 1808 | __ Lsl(dst, lhs, shift_value); |
| 1809 | } else if (instr->IsShr()) { |
| 1810 | __ Asr(dst, lhs, shift_value); |
| 1811 | } else { |
| 1812 | __ Lsr(dst, lhs, shift_value); |
| 1813 | } |
| 1814 | } else { |
| 1815 | Register rhs_reg = dst.IsX() ? rhs.reg().X() : rhs.reg().W(); |
| 1816 | |
| 1817 | if (instr->IsShl()) { |
| 1818 | __ Lsl(dst, lhs, rhs_reg); |
| 1819 | } else if (instr->IsShr()) { |
| 1820 | __ Asr(dst, lhs, rhs_reg); |
| 1821 | } else { |
| 1822 | __ Lsr(dst, lhs, rhs_reg); |
| 1823 | } |
| 1824 | } |
| 1825 | break; |
| 1826 | } |
| 1827 | default: |
| 1828 | LOG(FATAL) << "Unexpected shift operation type " << type; |
| 1829 | } |
| 1830 | } |
| 1831 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1832 | void LocationsBuilderARM64::VisitAdd(HAdd* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1833 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1834 | } |
| 1835 | |
| 1836 | void InstructionCodeGeneratorARM64::VisitAdd(HAdd* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1837 | HandleBinaryOp(instruction); |
| 1838 | } |
| 1839 | |
| 1840 | void LocationsBuilderARM64::VisitAnd(HAnd* instruction) { |
| 1841 | HandleBinaryOp(instruction); |
| 1842 | } |
| 1843 | |
| 1844 | void InstructionCodeGeneratorARM64::VisitAnd(HAnd* instruction) { |
| 1845 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1846 | } |
| 1847 | |
Artem Serov | 7fc6350 | 2016-02-09 17:15:29 +0000 | [diff] [blame] | 1848 | void LocationsBuilderARM64::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instr) { |
Kevin Brodsky | 9ff0d20 | 2016-01-11 13:43:31 +0000 | [diff] [blame] | 1849 | DCHECK(Primitive::IsIntegralType(instr->GetType())) << instr->GetType(); |
| 1850 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr); |
| 1851 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1852 | // There is no immediate variant of negated bitwise instructions in AArch64. |
| 1853 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1854 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1855 | } |
| 1856 | |
Artem Serov | 7fc6350 | 2016-02-09 17:15:29 +0000 | [diff] [blame] | 1857 | void InstructionCodeGeneratorARM64::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instr) { |
Kevin Brodsky | 9ff0d20 | 2016-01-11 13:43:31 +0000 | [diff] [blame] | 1858 | Register dst = OutputRegister(instr); |
| 1859 | Register lhs = InputRegisterAt(instr, 0); |
| 1860 | Register rhs = InputRegisterAt(instr, 1); |
| 1861 | |
| 1862 | switch (instr->GetOpKind()) { |
| 1863 | case HInstruction::kAnd: |
| 1864 | __ Bic(dst, lhs, rhs); |
| 1865 | break; |
| 1866 | case HInstruction::kOr: |
| 1867 | __ Orn(dst, lhs, rhs); |
| 1868 | break; |
| 1869 | case HInstruction::kXor: |
| 1870 | __ Eon(dst, lhs, rhs); |
| 1871 | break; |
| 1872 | default: |
| 1873 | LOG(FATAL) << "Unreachable"; |
| 1874 | } |
| 1875 | } |
| 1876 | |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 1877 | void LocationsBuilderARM64::VisitArm64DataProcWithShifterOp( |
| 1878 | HArm64DataProcWithShifterOp* instruction) { |
| 1879 | DCHECK(instruction->GetType() == Primitive::kPrimInt || |
| 1880 | instruction->GetType() == Primitive::kPrimLong); |
| 1881 | LocationSummary* locations = |
| 1882 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 1883 | if (instruction->GetInstrKind() == HInstruction::kNeg) { |
| 1884 | locations->SetInAt(0, Location::ConstantLocation(instruction->InputAt(0)->AsConstant())); |
| 1885 | } else { |
| 1886 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1887 | } |
| 1888 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1889 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1890 | } |
| 1891 | |
| 1892 | void InstructionCodeGeneratorARM64::VisitArm64DataProcWithShifterOp( |
| 1893 | HArm64DataProcWithShifterOp* instruction) { |
| 1894 | Primitive::Type type = instruction->GetType(); |
| 1895 | HInstruction::InstructionKind kind = instruction->GetInstrKind(); |
| 1896 | DCHECK(type == Primitive::kPrimInt || type == Primitive::kPrimLong); |
| 1897 | Register out = OutputRegister(instruction); |
| 1898 | Register left; |
| 1899 | if (kind != HInstruction::kNeg) { |
| 1900 | left = InputRegisterAt(instruction, 0); |
| 1901 | } |
| 1902 | // If this `HArm64DataProcWithShifterOp` was created by merging a type conversion as the |
| 1903 | // shifter operand operation, the IR generating `right_reg` (input to the type |
| 1904 | // conversion) can have a different type from the current instruction's type, |
| 1905 | // so we manually indicate the type. |
| 1906 | Register right_reg = RegisterFrom(instruction->GetLocations()->InAt(1), type); |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 1907 | int64_t shift_amount = instruction->GetShiftAmount() & |
| 1908 | (type == Primitive::kPrimInt ? kMaxIntShiftDistance : kMaxLongShiftDistance); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 1909 | |
| 1910 | Operand right_operand(0); |
| 1911 | |
| 1912 | HArm64DataProcWithShifterOp::OpKind op_kind = instruction->GetOpKind(); |
| 1913 | if (HArm64DataProcWithShifterOp::IsExtensionOp(op_kind)) { |
| 1914 | right_operand = Operand(right_reg, helpers::ExtendFromOpKind(op_kind)); |
| 1915 | } else { |
| 1916 | right_operand = Operand(right_reg, helpers::ShiftFromOpKind(op_kind), shift_amount); |
| 1917 | } |
| 1918 | |
| 1919 | // Logical binary operations do not support extension operations in the |
| 1920 | // operand. Note that VIXL would still manage if it was passed by generating |
| 1921 | // the extension as a separate instruction. |
| 1922 | // `HNeg` also does not support extension. See comments in `ShifterOperandSupportsExtension()`. |
| 1923 | DCHECK(!right_operand.IsExtendedRegister() || |
| 1924 | (kind != HInstruction::kAnd && kind != HInstruction::kOr && kind != HInstruction::kXor && |
| 1925 | kind != HInstruction::kNeg)); |
| 1926 | switch (kind) { |
| 1927 | case HInstruction::kAdd: |
| 1928 | __ Add(out, left, right_operand); |
| 1929 | break; |
| 1930 | case HInstruction::kAnd: |
| 1931 | __ And(out, left, right_operand); |
| 1932 | break; |
| 1933 | case HInstruction::kNeg: |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1934 | DCHECK(instruction->InputAt(0)->AsConstant()->IsArithmeticZero()); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 1935 | __ Neg(out, right_operand); |
| 1936 | break; |
| 1937 | case HInstruction::kOr: |
| 1938 | __ Orr(out, left, right_operand); |
| 1939 | break; |
| 1940 | case HInstruction::kSub: |
| 1941 | __ Sub(out, left, right_operand); |
| 1942 | break; |
| 1943 | case HInstruction::kXor: |
| 1944 | __ Eor(out, left, right_operand); |
| 1945 | break; |
| 1946 | default: |
| 1947 | LOG(FATAL) << "Unexpected operation kind: " << kind; |
| 1948 | UNREACHABLE(); |
| 1949 | } |
| 1950 | } |
| 1951 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1952 | void LocationsBuilderARM64::VisitArm64IntermediateAddress(HArm64IntermediateAddress* instruction) { |
Roland Levillain | cd3d0fb | 2016-01-15 19:26:48 +0000 | [diff] [blame] | 1953 | // The read barrier instrumentation does not support the |
| 1954 | // HArm64IntermediateAddress instruction yet. |
| 1955 | DCHECK(!kEmitCompilerReadBarrier); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1956 | LocationSummary* locations = |
| 1957 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 1958 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1959 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->GetOffset(), instruction)); |
| 1960 | locations->SetOut(Location::RequiresRegister()); |
| 1961 | } |
| 1962 | |
| 1963 | void InstructionCodeGeneratorARM64::VisitArm64IntermediateAddress( |
| 1964 | HArm64IntermediateAddress* instruction) { |
Roland Levillain | cd3d0fb | 2016-01-15 19:26:48 +0000 | [diff] [blame] | 1965 | // The read barrier instrumentation does not support the |
| 1966 | // HArm64IntermediateAddress instruction yet. |
| 1967 | DCHECK(!kEmitCompilerReadBarrier); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1968 | __ Add(OutputRegister(instruction), |
| 1969 | InputRegisterAt(instruction, 0), |
| 1970 | Operand(InputOperandAt(instruction, 1))); |
| 1971 | } |
| 1972 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 1973 | void LocationsBuilderARM64::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 1974 | LocationSummary* locations = |
| 1975 | new (GetGraph()->GetArena()) LocationSummary(instr, LocationSummary::kNoCall); |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 1976 | HInstruction* accumulator = instr->InputAt(HMultiplyAccumulate::kInputAccumulatorIndex); |
| 1977 | if (instr->GetOpKind() == HInstruction::kSub && |
| 1978 | accumulator->IsConstant() && |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1979 | accumulator->AsConstant()->IsArithmeticZero()) { |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 1980 | // Don't allocate register for Mneg instruction. |
| 1981 | } else { |
| 1982 | locations->SetInAt(HMultiplyAccumulate::kInputAccumulatorIndex, |
| 1983 | Location::RequiresRegister()); |
| 1984 | } |
| 1985 | locations->SetInAt(HMultiplyAccumulate::kInputMulLeftIndex, Location::RequiresRegister()); |
| 1986 | locations->SetInAt(HMultiplyAccumulate::kInputMulRightIndex, Location::RequiresRegister()); |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 1987 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1988 | } |
| 1989 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 1990 | void InstructionCodeGeneratorARM64::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 1991 | Register res = OutputRegister(instr); |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 1992 | Register mul_left = InputRegisterAt(instr, HMultiplyAccumulate::kInputMulLeftIndex); |
| 1993 | Register mul_right = InputRegisterAt(instr, HMultiplyAccumulate::kInputMulRightIndex); |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 1994 | |
| 1995 | // Avoid emitting code that could trigger Cortex A53's erratum 835769. |
| 1996 | // This fixup should be carried out for all multiply-accumulate instructions: |
| 1997 | // madd, msub, smaddl, smsubl, umaddl and umsubl. |
| 1998 | if (instr->GetType() == Primitive::kPrimLong && |
| 1999 | codegen_->GetInstructionSetFeatures().NeedFixCortexA53_835769()) { |
| 2000 | MacroAssembler* masm = down_cast<CodeGeneratorARM64*>(codegen_)->GetVIXLAssembler(); |
| 2001 | vixl::Instruction* prev = masm->GetCursorAddress<vixl::Instruction*>() - vixl::kInstructionSize; |
| 2002 | if (prev->IsLoadOrStore()) { |
| 2003 | // Make sure we emit only exactly one nop. |
| 2004 | vixl::CodeBufferCheckScope scope(masm, |
| 2005 | vixl::kInstructionSize, |
| 2006 | vixl::CodeBufferCheckScope::kCheck, |
| 2007 | vixl::CodeBufferCheckScope::kExactSize); |
| 2008 | __ nop(); |
| 2009 | } |
| 2010 | } |
| 2011 | |
| 2012 | if (instr->GetOpKind() == HInstruction::kAdd) { |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2013 | Register accumulator = InputRegisterAt(instr, HMultiplyAccumulate::kInputAccumulatorIndex); |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2014 | __ Madd(res, mul_left, mul_right, accumulator); |
| 2015 | } else { |
| 2016 | DCHECK(instr->GetOpKind() == HInstruction::kSub); |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2017 | HInstruction* accum_instr = instr->InputAt(HMultiplyAccumulate::kInputAccumulatorIndex); |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2018 | if (accum_instr->IsConstant() && accum_instr->AsConstant()->IsArithmeticZero()) { |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2019 | __ Mneg(res, mul_left, mul_right); |
| 2020 | } else { |
| 2021 | Register accumulator = InputRegisterAt(instr, HMultiplyAccumulate::kInputAccumulatorIndex); |
| 2022 | __ Msub(res, mul_left, mul_right, accumulator); |
| 2023 | } |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2024 | } |
| 2025 | } |
| 2026 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2027 | void LocationsBuilderARM64::VisitArrayGet(HArrayGet* instruction) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2028 | bool object_array_get_with_read_barrier = |
| 2029 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2030 | LocationSummary* locations = |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2031 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 2032 | object_array_get_with_read_barrier ? |
| 2033 | LocationSummary::kCallOnSlowPath : |
| 2034 | LocationSummary::kNoCall); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2035 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2036 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 2037 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 2038 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 2039 | } else { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2040 | // The output overlaps in the case of an object array get with |
| 2041 | // read barriers enabled: we do not want the move to overwrite the |
| 2042 | // array's location, as we need it to emit the read barrier. |
| 2043 | locations->SetOut( |
| 2044 | Location::RequiresRegister(), |
| 2045 | object_array_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 2046 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2047 | } |
| 2048 | |
| 2049 | void InstructionCodeGeneratorARM64::VisitArrayGet(HArrayGet* instruction) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2050 | Primitive::Type type = instruction->GetType(); |
| 2051 | Register obj = InputRegisterAt(instruction, 0); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2052 | LocationSummary* locations = instruction->GetLocations(); |
| 2053 | Location index = locations->InAt(1); |
| 2054 | uint32_t offset = mirror::Array::DataOffset(Primitive::ComponentSize(type)).Uint32Value(); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2055 | Location out = locations->Out(); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2056 | |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 2057 | MacroAssembler* masm = GetVIXLAssembler(); |
| 2058 | UseScratchRegisterScope temps(masm); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2059 | // Block pools between `Load` and `MaybeRecordImplicitNullCheck`. |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 2060 | BlockPoolsScope block_pools(masm); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2061 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2062 | if (type == Primitive::kPrimNot && kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 2063 | // Object ArrayGet with Baker's read barrier case. |
| 2064 | Register temp = temps.AcquireW(); |
| 2065 | // The read barrier instrumentation does not support the |
| 2066 | // HArm64IntermediateAddress instruction yet. |
| 2067 | DCHECK(!instruction->GetArray()->IsArm64IntermediateAddress()); |
| 2068 | // Note that a potential implicit null check is handled in the |
| 2069 | // CodeGeneratorARM64::GenerateArrayLoadWithBakerReadBarrier call. |
| 2070 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
| 2071 | instruction, out, obj.W(), offset, index, temp, /* needs_null_check */ true); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2072 | } else { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2073 | // General case. |
| 2074 | MemOperand source = HeapOperand(obj); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2075 | if (index.IsConstant()) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2076 | offset += Int64ConstantFrom(index) << Primitive::ComponentSizeShift(type); |
| 2077 | source = HeapOperand(obj, offset); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2078 | } else { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2079 | Register temp = temps.AcquireSameSizeAs(obj); |
| 2080 | if (instruction->GetArray()->IsArm64IntermediateAddress()) { |
| 2081 | // The read barrier instrumentation does not support the |
| 2082 | // HArm64IntermediateAddress instruction yet. |
| 2083 | DCHECK(!kEmitCompilerReadBarrier); |
| 2084 | // We do not need to compute the intermediate address from the array: the |
| 2085 | // input instruction has done it already. See the comment in |
| 2086 | // `InstructionSimplifierArm64::TryExtractArrayAccessAddress()`. |
| 2087 | if (kIsDebugBuild) { |
| 2088 | HArm64IntermediateAddress* tmp = instruction->GetArray()->AsArm64IntermediateAddress(); |
| 2089 | DCHECK_EQ(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64(), offset); |
| 2090 | } |
| 2091 | temp = obj; |
| 2092 | } else { |
| 2093 | __ Add(temp, obj, offset); |
| 2094 | } |
| 2095 | source = HeapOperand(temp, XRegisterFrom(index), LSL, Primitive::ComponentSizeShift(type)); |
| 2096 | } |
| 2097 | |
| 2098 | codegen_->Load(type, OutputCPURegister(instruction), source); |
| 2099 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2100 | |
| 2101 | if (type == Primitive::kPrimNot) { |
| 2102 | static_assert( |
| 2103 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 2104 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 2105 | Location obj_loc = locations->InAt(0); |
| 2106 | if (index.IsConstant()) { |
| 2107 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, obj_loc, offset); |
| 2108 | } else { |
| 2109 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, obj_loc, offset, index); |
| 2110 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2111 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2112 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2113 | } |
| 2114 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2115 | void LocationsBuilderARM64::VisitArrayLength(HArrayLength* instruction) { |
| 2116 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 2117 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 2118 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2119 | } |
| 2120 | |
| 2121 | void InstructionCodeGeneratorARM64::VisitArrayLength(HArrayLength* instruction) { |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 2122 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 2123 | BlockPoolsScope block_pools(GetVIXLAssembler()); |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 2124 | __ Ldr(OutputRegister(instruction), HeapOperand(InputRegisterAt(instruction, 0), offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 2125 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2126 | } |
| 2127 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2128 | void LocationsBuilderARM64::VisitArraySet(HArraySet* instruction) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2129 | Primitive::Type value_type = instruction->GetComponentType(); |
| 2130 | |
| 2131 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
| 2132 | bool object_array_set_with_read_barrier = |
| 2133 | kEmitCompilerReadBarrier && (value_type == Primitive::kPrimNot); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2134 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 2135 | instruction, |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2136 | (may_need_runtime_call_for_type_check || object_array_set_with_read_barrier) ? |
| 2137 | LocationSummary::kCallOnSlowPath : |
| 2138 | LocationSummary::kNoCall); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2139 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2140 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2141 | if (Primitive::IsFloatingPointType(value_type)) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2142 | locations->SetInAt(2, Location::RequiresFpuRegister()); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2143 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2144 | locations->SetInAt(2, Location::RequiresRegister()); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2145 | } |
| 2146 | } |
| 2147 | |
| 2148 | void InstructionCodeGeneratorARM64::VisitArraySet(HArraySet* instruction) { |
| 2149 | Primitive::Type value_type = instruction->GetComponentType(); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2150 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2151 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2152 | bool needs_write_barrier = |
| 2153 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2154 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2155 | Register array = InputRegisterAt(instruction, 0); |
| 2156 | CPURegister value = InputCPURegisterAt(instruction, 2); |
| 2157 | CPURegister source = value; |
| 2158 | Location index = locations->InAt(1); |
| 2159 | size_t offset = mirror::Array::DataOffset(Primitive::ComponentSize(value_type)).Uint32Value(); |
| 2160 | MemOperand destination = HeapOperand(array); |
| 2161 | MacroAssembler* masm = GetVIXLAssembler(); |
| 2162 | BlockPoolsScope block_pools(masm); |
| 2163 | |
| 2164 | if (!needs_write_barrier) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2165 | DCHECK(!may_need_runtime_call_for_type_check); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2166 | if (index.IsConstant()) { |
| 2167 | offset += Int64ConstantFrom(index) << Primitive::ComponentSizeShift(value_type); |
| 2168 | destination = HeapOperand(array, offset); |
| 2169 | } else { |
| 2170 | UseScratchRegisterScope temps(masm); |
| 2171 | Register temp = temps.AcquireSameSizeAs(array); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2172 | if (instruction->GetArray()->IsArm64IntermediateAddress()) { |
Roland Levillain | cd3d0fb | 2016-01-15 19:26:48 +0000 | [diff] [blame] | 2173 | // The read barrier instrumentation does not support the |
| 2174 | // HArm64IntermediateAddress instruction yet. |
| 2175 | DCHECK(!kEmitCompilerReadBarrier); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2176 | // We do not need to compute the intermediate address from the array: the |
| 2177 | // input instruction has done it already. See the comment in |
| 2178 | // `InstructionSimplifierArm64::TryExtractArrayAccessAddress()`. |
| 2179 | if (kIsDebugBuild) { |
| 2180 | HArm64IntermediateAddress* tmp = instruction->GetArray()->AsArm64IntermediateAddress(); |
| 2181 | DCHECK(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64() == offset); |
| 2182 | } |
| 2183 | temp = array; |
| 2184 | } else { |
| 2185 | __ Add(temp, array, offset); |
| 2186 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2187 | destination = HeapOperand(temp, |
| 2188 | XRegisterFrom(index), |
| 2189 | LSL, |
| 2190 | Primitive::ComponentSizeShift(value_type)); |
| 2191 | } |
| 2192 | codegen_->Store(value_type, value, destination); |
| 2193 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2194 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2195 | DCHECK(needs_write_barrier); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2196 | DCHECK(!instruction->GetArray()->IsArm64IntermediateAddress()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2197 | vixl::Label done; |
| 2198 | SlowPathCodeARM64* slow_path = nullptr; |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2199 | { |
| 2200 | // We use a block to end the scratch scope before the write barrier, thus |
| 2201 | // freeing the temporary registers so they can be used in `MarkGCCard`. |
| 2202 | UseScratchRegisterScope temps(masm); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2203 | Register temp = temps.AcquireSameSizeAs(array); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2204 | if (index.IsConstant()) { |
| 2205 | offset += Int64ConstantFrom(index) << Primitive::ComponentSizeShift(value_type); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2206 | destination = HeapOperand(array, offset); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2207 | } else { |
Alexandre Rames | 82000b0 | 2015-07-07 11:34:16 +0100 | [diff] [blame] | 2208 | destination = HeapOperand(temp, |
| 2209 | XRegisterFrom(index), |
| 2210 | LSL, |
| 2211 | Primitive::ComponentSizeShift(value_type)); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2212 | } |
| 2213 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2214 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2215 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 2216 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 2217 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2218 | if (may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2219 | slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathARM64(instruction); |
| 2220 | codegen_->AddSlowPath(slow_path); |
| 2221 | if (instruction->GetValueCanBeNull()) { |
| 2222 | vixl::Label non_zero; |
| 2223 | __ Cbnz(Register(value), &non_zero); |
| 2224 | if (!index.IsConstant()) { |
| 2225 | __ Add(temp, array, offset); |
| 2226 | } |
| 2227 | __ Str(wzr, destination); |
| 2228 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2229 | __ B(&done); |
| 2230 | __ Bind(&non_zero); |
| 2231 | } |
| 2232 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2233 | if (kEmitCompilerReadBarrier) { |
| 2234 | // When read barriers are enabled, the type checking |
| 2235 | // instrumentation requires two read barriers: |
| 2236 | // |
| 2237 | // __ Mov(temp2, temp); |
| 2238 | // // /* HeapReference<Class> */ temp = temp->component_type_ |
| 2239 | // __ Ldr(temp, HeapOperand(temp, component_offset)); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2240 | // codegen_->GenerateReadBarrierSlow( |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2241 | // instruction, temp_loc, temp_loc, temp2_loc, component_offset); |
| 2242 | // |
| 2243 | // // /* HeapReference<Class> */ temp2 = value->klass_ |
| 2244 | // __ Ldr(temp2, HeapOperand(Register(value), class_offset)); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2245 | // codegen_->GenerateReadBarrierSlow( |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2246 | // instruction, temp2_loc, temp2_loc, value_loc, class_offset, temp_loc); |
| 2247 | // |
| 2248 | // __ Cmp(temp, temp2); |
| 2249 | // |
| 2250 | // However, the second read barrier may trash `temp`, as it |
| 2251 | // is a temporary register, and as such would not be saved |
| 2252 | // along with live registers before calling the runtime (nor |
| 2253 | // restored afterwards). So in this case, we bail out and |
| 2254 | // delegate the work to the array set slow path. |
| 2255 | // |
| 2256 | // TODO: Extend the register allocator to support a new |
| 2257 | // "(locally) live temp" location so as to avoid always |
| 2258 | // going into the slow path when read barriers are enabled. |
| 2259 | __ B(slow_path->GetEntryLabel()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2260 | } else { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2261 | Register temp2 = temps.AcquireSameSizeAs(array); |
| 2262 | // /* HeapReference<Class> */ temp = array->klass_ |
| 2263 | __ Ldr(temp, HeapOperand(array, class_offset)); |
| 2264 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2265 | GetAssembler()->MaybeUnpoisonHeapReference(temp); |
| 2266 | |
| 2267 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| 2268 | __ Ldr(temp, HeapOperand(temp, component_offset)); |
| 2269 | // /* HeapReference<Class> */ temp2 = value->klass_ |
| 2270 | __ Ldr(temp2, HeapOperand(Register(value), class_offset)); |
| 2271 | // If heap poisoning is enabled, no need to unpoison `temp` |
| 2272 | // nor `temp2`, as we are comparing two poisoned references. |
| 2273 | __ Cmp(temp, temp2); |
| 2274 | |
| 2275 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 2276 | vixl::Label do_put; |
| 2277 | __ B(eq, &do_put); |
| 2278 | // If heap poisoning is enabled, the `temp` reference has |
| 2279 | // not been unpoisoned yet; unpoison it now. |
| 2280 | GetAssembler()->MaybeUnpoisonHeapReference(temp); |
| 2281 | |
| 2282 | // /* HeapReference<Class> */ temp = temp->super_class_ |
| 2283 | __ Ldr(temp, HeapOperand(temp, super_offset)); |
| 2284 | // If heap poisoning is enabled, no need to unpoison |
| 2285 | // `temp`, as we are comparing against null below. |
| 2286 | __ Cbnz(temp, slow_path->GetEntryLabel()); |
| 2287 | __ Bind(&do_put); |
| 2288 | } else { |
| 2289 | __ B(ne, slow_path->GetEntryLabel()); |
| 2290 | } |
| 2291 | temps.Release(temp2); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2292 | } |
| 2293 | } |
| 2294 | |
| 2295 | if (kPoisonHeapReferences) { |
Nicolas Geoffray | a8a0fe2 | 2015-10-01 15:50:27 +0100 | [diff] [blame] | 2296 | Register temp2 = temps.AcquireSameSizeAs(array); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2297 | DCHECK(value.IsW()); |
Nicolas Geoffray | a8a0fe2 | 2015-10-01 15:50:27 +0100 | [diff] [blame] | 2298 | __ Mov(temp2, value.W()); |
| 2299 | GetAssembler()->PoisonHeapReference(temp2); |
| 2300 | source = temp2; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2301 | } |
| 2302 | |
| 2303 | if (!index.IsConstant()) { |
| 2304 | __ Add(temp, array, offset); |
| 2305 | } |
Nicolas Geoffray | 61b1dbe | 2015-10-01 10:27:52 +0100 | [diff] [blame] | 2306 | __ Str(source, destination); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2307 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2308 | if (!may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2309 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2310 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2311 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2312 | |
| 2313 | codegen_->MarkGCCard(array, value.W(), instruction->GetValueCanBeNull()); |
| 2314 | |
| 2315 | if (done.IsLinked()) { |
| 2316 | __ Bind(&done); |
| 2317 | } |
| 2318 | |
| 2319 | if (slow_path != nullptr) { |
| 2320 | __ Bind(slow_path->GetExitLabel()); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2321 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2322 | } |
| 2323 | } |
| 2324 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2325 | void LocationsBuilderARM64::VisitBoundsCheck(HBoundsCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2326 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 2327 | ? LocationSummary::kCallOnSlowPath |
| 2328 | : LocationSummary::kNoCall; |
| 2329 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2330 | locations->SetInAt(0, Location::RequiresRegister()); |
Serban Constantinescu | 760d8ef | 2015-03-28 18:09:56 +0000 | [diff] [blame] | 2331 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->InputAt(1), instruction)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2332 | if (instruction->HasUses()) { |
| 2333 | locations->SetOut(Location::SameAsFirstInput()); |
| 2334 | } |
| 2335 | } |
| 2336 | |
| 2337 | void InstructionCodeGeneratorARM64::VisitBoundsCheck(HBoundsCheck* instruction) { |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 2338 | BoundsCheckSlowPathARM64* slow_path = |
| 2339 | new (GetGraph()->GetArena()) BoundsCheckSlowPathARM64(instruction); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2340 | codegen_->AddSlowPath(slow_path); |
| 2341 | |
| 2342 | __ Cmp(InputRegisterAt(instruction, 0), InputOperandAt(instruction, 1)); |
| 2343 | __ B(slow_path->GetEntryLabel(), hs); |
| 2344 | } |
| 2345 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2346 | void LocationsBuilderARM64::VisitClinitCheck(HClinitCheck* check) { |
| 2347 | LocationSummary* locations = |
| 2348 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 2349 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2350 | if (check->HasUses()) { |
| 2351 | locations->SetOut(Location::SameAsFirstInput()); |
| 2352 | } |
| 2353 | } |
| 2354 | |
| 2355 | void InstructionCodeGeneratorARM64::VisitClinitCheck(HClinitCheck* check) { |
| 2356 | // We assume the class is not null. |
| 2357 | SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM64( |
| 2358 | check->GetLoadClass(), check, check->GetDexPc(), true); |
| 2359 | codegen_->AddSlowPath(slow_path); |
| 2360 | GenerateClassInitializationCheck(slow_path, InputRegisterAt(check, 0)); |
| 2361 | } |
| 2362 | |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2363 | static bool IsFloatingPointZeroConstant(HInstruction* inst) { |
| 2364 | return (inst->IsFloatConstant() && (inst->AsFloatConstant()->IsArithmeticZero())) |
| 2365 | || (inst->IsDoubleConstant() && (inst->AsDoubleConstant()->IsArithmeticZero())); |
| 2366 | } |
| 2367 | |
| 2368 | void InstructionCodeGeneratorARM64::GenerateFcmp(HInstruction* instruction) { |
| 2369 | FPRegister lhs_reg = InputFPRegisterAt(instruction, 0); |
| 2370 | Location rhs_loc = instruction->GetLocations()->InAt(1); |
| 2371 | if (rhs_loc.IsConstant()) { |
| 2372 | // 0.0 is the only immediate that can be encoded directly in |
| 2373 | // an FCMP instruction. |
| 2374 | // |
| 2375 | // Both the JLS (section 15.20.1) and the JVMS (section 6.5) |
| 2376 | // specify that in a floating-point comparison, positive zero |
| 2377 | // and negative zero are considered equal, so we can use the |
| 2378 | // literal 0.0 for both cases here. |
| 2379 | // |
| 2380 | // Note however that some methods (Float.equal, Float.compare, |
| 2381 | // Float.compareTo, Double.equal, Double.compare, |
| 2382 | // Double.compareTo, Math.max, Math.min, StrictMath.max, |
| 2383 | // StrictMath.min) consider 0.0 to be (strictly) greater than |
| 2384 | // -0.0. So if we ever translate calls to these methods into a |
| 2385 | // HCompare instruction, we must handle the -0.0 case with |
| 2386 | // care here. |
| 2387 | DCHECK(IsFloatingPointZeroConstant(rhs_loc.GetConstant())); |
| 2388 | __ Fcmp(lhs_reg, 0.0); |
| 2389 | } else { |
| 2390 | __ Fcmp(lhs_reg, InputFPRegisterAt(instruction, 1)); |
| 2391 | } |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2392 | } |
| 2393 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2394 | void LocationsBuilderARM64::VisitCompare(HCompare* compare) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2395 | LocationSummary* locations = |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2396 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
| 2397 | Primitive::Type in_type = compare->InputAt(0)->GetType(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2398 | switch (in_type) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 2399 | case Primitive::kPrimBoolean: |
| 2400 | case Primitive::kPrimByte: |
| 2401 | case Primitive::kPrimShort: |
| 2402 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2403 | case Primitive::kPrimInt: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2404 | case Primitive::kPrimLong: { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2405 | locations->SetInAt(0, Location::RequiresRegister()); |
Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 2406 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(compare->InputAt(1), compare)); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2407 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2408 | break; |
| 2409 | } |
| 2410 | case Primitive::kPrimFloat: |
| 2411 | case Primitive::kPrimDouble: { |
| 2412 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2413 | locations->SetInAt(1, |
| 2414 | IsFloatingPointZeroConstant(compare->InputAt(1)) |
| 2415 | ? Location::ConstantLocation(compare->InputAt(1)->AsConstant()) |
| 2416 | : Location::RequiresFpuRegister()); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2417 | locations->SetOut(Location::RequiresRegister()); |
| 2418 | break; |
| 2419 | } |
| 2420 | default: |
| 2421 | LOG(FATAL) << "Unexpected type for compare operation " << in_type; |
| 2422 | } |
| 2423 | } |
| 2424 | |
| 2425 | void InstructionCodeGeneratorARM64::VisitCompare(HCompare* compare) { |
| 2426 | Primitive::Type in_type = compare->InputAt(0)->GetType(); |
| 2427 | |
| 2428 | // 0 if: left == right |
| 2429 | // 1 if: left > right |
| 2430 | // -1 if: left < right |
| 2431 | switch (in_type) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 2432 | case Primitive::kPrimBoolean: |
| 2433 | case Primitive::kPrimByte: |
| 2434 | case Primitive::kPrimShort: |
| 2435 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2436 | case Primitive::kPrimInt: |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2437 | case Primitive::kPrimLong: { |
| 2438 | Register result = OutputRegister(compare); |
| 2439 | Register left = InputRegisterAt(compare, 0); |
| 2440 | Operand right = InputOperandAt(compare, 1); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2441 | __ Cmp(left, right); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2442 | __ Cset(result, ne); // result == +1 if NE or 0 otherwise |
| 2443 | __ Cneg(result, result, lt); // result == -1 if LT or unchanged otherwise |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2444 | break; |
| 2445 | } |
| 2446 | case Primitive::kPrimFloat: |
| 2447 | case Primitive::kPrimDouble: { |
| 2448 | Register result = OutputRegister(compare); |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2449 | GenerateFcmp(compare); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 2450 | __ Cset(result, ne); |
| 2451 | __ Cneg(result, result, ARM64FPCondition(kCondLT, compare->IsGtBias())); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2452 | break; |
| 2453 | } |
| 2454 | default: |
| 2455 | LOG(FATAL) << "Unimplemented compare type " << in_type; |
| 2456 | } |
| 2457 | } |
| 2458 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2459 | void LocationsBuilderARM64::HandleCondition(HCondition* instruction) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2460 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2461 | |
| 2462 | if (Primitive::IsFloatingPointType(instruction->InputAt(0)->GetType())) { |
| 2463 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2464 | locations->SetInAt(1, |
| 2465 | IsFloatingPointZeroConstant(instruction->InputAt(1)) |
| 2466 | ? Location::ConstantLocation(instruction->InputAt(1)->AsConstant()) |
| 2467 | : Location::RequiresFpuRegister()); |
| 2468 | } else { |
| 2469 | // Integer cases. |
| 2470 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2471 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->InputAt(1), instruction)); |
| 2472 | } |
| 2473 | |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2474 | if (!instruction->IsEmittedAtUseSite()) { |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 2475 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2476 | } |
| 2477 | } |
| 2478 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2479 | void InstructionCodeGeneratorARM64::HandleCondition(HCondition* instruction) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2480 | if (instruction->IsEmittedAtUseSite()) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2481 | return; |
| 2482 | } |
| 2483 | |
| 2484 | LocationSummary* locations = instruction->GetLocations(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2485 | Register res = RegisterFrom(locations->Out(), instruction->GetType()); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2486 | IfCondition if_cond = instruction->GetCondition(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2487 | |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2488 | if (Primitive::IsFloatingPointType(instruction->InputAt(0)->GetType())) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2489 | GenerateFcmp(instruction); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 2490 | __ Cset(res, ARM64FPCondition(if_cond, instruction->IsGtBias())); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2491 | } else { |
| 2492 | // Integer cases. |
| 2493 | Register lhs = InputRegisterAt(instruction, 0); |
| 2494 | Operand rhs = InputOperandAt(instruction, 1); |
| 2495 | __ Cmp(lhs, rhs); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 2496 | __ Cset(res, ARM64Condition(if_cond)); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2497 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2498 | } |
| 2499 | |
| 2500 | #define FOR_EACH_CONDITION_INSTRUCTION(M) \ |
| 2501 | M(Equal) \ |
| 2502 | M(NotEqual) \ |
| 2503 | M(LessThan) \ |
| 2504 | M(LessThanOrEqual) \ |
| 2505 | M(GreaterThan) \ |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2506 | M(GreaterThanOrEqual) \ |
| 2507 | M(Below) \ |
| 2508 | M(BelowOrEqual) \ |
| 2509 | M(Above) \ |
| 2510 | M(AboveOrEqual) |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2511 | #define DEFINE_CONDITION_VISITORS(Name) \ |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2512 | void LocationsBuilderARM64::Visit##Name(H##Name* comp) { HandleCondition(comp); } \ |
| 2513 | void InstructionCodeGeneratorARM64::Visit##Name(H##Name* comp) { HandleCondition(comp); } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2514 | FOR_EACH_CONDITION_INSTRUCTION(DEFINE_CONDITION_VISITORS) |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2515 | #undef DEFINE_CONDITION_VISITORS |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2516 | #undef FOR_EACH_CONDITION_INSTRUCTION |
| 2517 | |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2518 | void InstructionCodeGeneratorARM64::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 2519 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2520 | |
| 2521 | LocationSummary* locations = instruction->GetLocations(); |
| 2522 | Location second = locations->InAt(1); |
| 2523 | DCHECK(second.IsConstant()); |
| 2524 | |
| 2525 | Register out = OutputRegister(instruction); |
| 2526 | Register dividend = InputRegisterAt(instruction, 0); |
| 2527 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 2528 | DCHECK(imm == 1 || imm == -1); |
| 2529 | |
| 2530 | if (instruction->IsRem()) { |
| 2531 | __ Mov(out, 0); |
| 2532 | } else { |
| 2533 | if (imm == 1) { |
| 2534 | __ Mov(out, dividend); |
| 2535 | } else { |
| 2536 | __ Neg(out, dividend); |
| 2537 | } |
| 2538 | } |
| 2539 | } |
| 2540 | |
| 2541 | void InstructionCodeGeneratorARM64::DivRemByPowerOfTwo(HBinaryOperation* instruction) { |
| 2542 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2543 | |
| 2544 | LocationSummary* locations = instruction->GetLocations(); |
| 2545 | Location second = locations->InAt(1); |
| 2546 | DCHECK(second.IsConstant()); |
| 2547 | |
| 2548 | Register out = OutputRegister(instruction); |
| 2549 | Register dividend = InputRegisterAt(instruction, 0); |
| 2550 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 2551 | uint64_t abs_imm = static_cast<uint64_t>(AbsOrMin(imm)); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2552 | int ctz_imm = CTZ(abs_imm); |
| 2553 | |
| 2554 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2555 | Register temp = temps.AcquireSameSizeAs(out); |
| 2556 | |
| 2557 | if (instruction->IsDiv()) { |
| 2558 | __ Add(temp, dividend, abs_imm - 1); |
| 2559 | __ Cmp(dividend, 0); |
| 2560 | __ Csel(out, temp, dividend, lt); |
| 2561 | if (imm > 0) { |
| 2562 | __ Asr(out, out, ctz_imm); |
| 2563 | } else { |
| 2564 | __ Neg(out, Operand(out, ASR, ctz_imm)); |
| 2565 | } |
| 2566 | } else { |
| 2567 | int bits = instruction->GetResultType() == Primitive::kPrimInt ? 32 : 64; |
| 2568 | __ Asr(temp, dividend, bits - 1); |
| 2569 | __ Lsr(temp, temp, bits - ctz_imm); |
| 2570 | __ Add(out, dividend, temp); |
| 2571 | __ And(out, out, abs_imm - 1); |
| 2572 | __ Sub(out, out, temp); |
| 2573 | } |
| 2574 | } |
| 2575 | |
| 2576 | void InstructionCodeGeneratorARM64::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 2577 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2578 | |
| 2579 | LocationSummary* locations = instruction->GetLocations(); |
| 2580 | Location second = locations->InAt(1); |
| 2581 | DCHECK(second.IsConstant()); |
| 2582 | |
| 2583 | Register out = OutputRegister(instruction); |
| 2584 | Register dividend = InputRegisterAt(instruction, 0); |
| 2585 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 2586 | |
| 2587 | Primitive::Type type = instruction->GetResultType(); |
| 2588 | DCHECK(type == Primitive::kPrimInt || type == Primitive::kPrimLong); |
| 2589 | |
| 2590 | int64_t magic; |
| 2591 | int shift; |
| 2592 | CalculateMagicAndShiftForDivRem(imm, type == Primitive::kPrimLong /* is_long */, &magic, &shift); |
| 2593 | |
| 2594 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2595 | Register temp = temps.AcquireSameSizeAs(out); |
| 2596 | |
| 2597 | // temp = get_high(dividend * magic) |
| 2598 | __ Mov(temp, magic); |
| 2599 | if (type == Primitive::kPrimLong) { |
| 2600 | __ Smulh(temp, dividend, temp); |
| 2601 | } else { |
| 2602 | __ Smull(temp.X(), dividend, temp); |
| 2603 | __ Lsr(temp.X(), temp.X(), 32); |
| 2604 | } |
| 2605 | |
| 2606 | if (imm > 0 && magic < 0) { |
| 2607 | __ Add(temp, temp, dividend); |
| 2608 | } else if (imm < 0 && magic > 0) { |
| 2609 | __ Sub(temp, temp, dividend); |
| 2610 | } |
| 2611 | |
| 2612 | if (shift != 0) { |
| 2613 | __ Asr(temp, temp, shift); |
| 2614 | } |
| 2615 | |
| 2616 | if (instruction->IsDiv()) { |
| 2617 | __ Sub(out, temp, Operand(temp, ASR, type == Primitive::kPrimLong ? 63 : 31)); |
| 2618 | } else { |
| 2619 | __ Sub(temp, temp, Operand(temp, ASR, type == Primitive::kPrimLong ? 63 : 31)); |
| 2620 | // TODO: Strength reduction for msub. |
| 2621 | Register temp_imm = temps.AcquireSameSizeAs(out); |
| 2622 | __ Mov(temp_imm, imm); |
| 2623 | __ Msub(out, temp, temp_imm, dividend); |
| 2624 | } |
| 2625 | } |
| 2626 | |
| 2627 | void InstructionCodeGeneratorARM64::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 2628 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2629 | Primitive::Type type = instruction->GetResultType(); |
| 2630 | DCHECK(type == Primitive::kPrimInt || Primitive::kPrimLong); |
| 2631 | |
| 2632 | LocationSummary* locations = instruction->GetLocations(); |
| 2633 | Register out = OutputRegister(instruction); |
| 2634 | Location second = locations->InAt(1); |
| 2635 | |
| 2636 | if (second.IsConstant()) { |
| 2637 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 2638 | |
| 2639 | if (imm == 0) { |
| 2640 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 2641 | } else if (imm == 1 || imm == -1) { |
| 2642 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 2643 | } else if (IsPowerOfTwo(AbsOrMin(imm))) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2644 | DivRemByPowerOfTwo(instruction); |
| 2645 | } else { |
| 2646 | DCHECK(imm <= -2 || imm >= 2); |
| 2647 | GenerateDivRemWithAnyConstant(instruction); |
| 2648 | } |
| 2649 | } else { |
| 2650 | Register dividend = InputRegisterAt(instruction, 0); |
| 2651 | Register divisor = InputRegisterAt(instruction, 1); |
| 2652 | if (instruction->IsDiv()) { |
| 2653 | __ Sdiv(out, dividend, divisor); |
| 2654 | } else { |
| 2655 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2656 | Register temp = temps.AcquireSameSizeAs(out); |
| 2657 | __ Sdiv(temp, dividend, divisor); |
| 2658 | __ Msub(out, temp, divisor, dividend); |
| 2659 | } |
| 2660 | } |
| 2661 | } |
| 2662 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2663 | void LocationsBuilderARM64::VisitDiv(HDiv* div) { |
| 2664 | LocationSummary* locations = |
| 2665 | new (GetGraph()->GetArena()) LocationSummary(div, LocationSummary::kNoCall); |
| 2666 | switch (div->GetResultType()) { |
| 2667 | case Primitive::kPrimInt: |
| 2668 | case Primitive::kPrimLong: |
| 2669 | locations->SetInAt(0, Location::RequiresRegister()); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2670 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2671 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2672 | break; |
| 2673 | |
| 2674 | case Primitive::kPrimFloat: |
| 2675 | case Primitive::kPrimDouble: |
| 2676 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2677 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2678 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 2679 | break; |
| 2680 | |
| 2681 | default: |
| 2682 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 2683 | } |
| 2684 | } |
| 2685 | |
| 2686 | void InstructionCodeGeneratorARM64::VisitDiv(HDiv* div) { |
| 2687 | Primitive::Type type = div->GetResultType(); |
| 2688 | switch (type) { |
| 2689 | case Primitive::kPrimInt: |
| 2690 | case Primitive::kPrimLong: |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2691 | GenerateDivRemIntegral(div); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2692 | break; |
| 2693 | |
| 2694 | case Primitive::kPrimFloat: |
| 2695 | case Primitive::kPrimDouble: |
| 2696 | __ Fdiv(OutputFPRegister(div), InputFPRegisterAt(div, 0), InputFPRegisterAt(div, 1)); |
| 2697 | break; |
| 2698 | |
| 2699 | default: |
| 2700 | LOG(FATAL) << "Unexpected div type " << type; |
| 2701 | } |
| 2702 | } |
| 2703 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2704 | void LocationsBuilderARM64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2705 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 2706 | ? LocationSummary::kCallOnSlowPath |
| 2707 | : LocationSummary::kNoCall; |
| 2708 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2709 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
| 2710 | if (instruction->HasUses()) { |
| 2711 | locations->SetOut(Location::SameAsFirstInput()); |
| 2712 | } |
| 2713 | } |
| 2714 | |
| 2715 | void InstructionCodeGeneratorARM64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 2716 | SlowPathCodeARM64* slow_path = |
| 2717 | new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM64(instruction); |
| 2718 | codegen_->AddSlowPath(slow_path); |
| 2719 | Location value = instruction->GetLocations()->InAt(0); |
| 2720 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 2721 | Primitive::Type type = instruction->GetType(); |
| 2722 | |
Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 2723 | if (!Primitive::IsIntegralType(type)) { |
| 2724 | LOG(FATAL) << "Unexpected type " << type << " for DivZeroCheck."; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 2725 | return; |
| 2726 | } |
| 2727 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2728 | if (value.IsConstant()) { |
| 2729 | int64_t divisor = Int64ConstantFrom(value); |
| 2730 | if (divisor == 0) { |
| 2731 | __ B(slow_path->GetEntryLabel()); |
| 2732 | } else { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 2733 | // A division by a non-null constant is valid. We don't need to perform |
| 2734 | // any check, so simply fall through. |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2735 | } |
| 2736 | } else { |
| 2737 | __ Cbz(InputRegisterAt(instruction, 0), slow_path->GetEntryLabel()); |
| 2738 | } |
| 2739 | } |
| 2740 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2741 | void LocationsBuilderARM64::VisitDoubleConstant(HDoubleConstant* constant) { |
| 2742 | LocationSummary* locations = |
| 2743 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 2744 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2745 | } |
| 2746 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2747 | void InstructionCodeGeneratorARM64::VisitDoubleConstant( |
| 2748 | HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2749 | // Will be generated at use site. |
| 2750 | } |
| 2751 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2752 | void LocationsBuilderARM64::VisitExit(HExit* exit) { |
| 2753 | exit->SetLocations(nullptr); |
| 2754 | } |
| 2755 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2756 | void InstructionCodeGeneratorARM64::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2757 | } |
| 2758 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2759 | void LocationsBuilderARM64::VisitFloatConstant(HFloatConstant* constant) { |
| 2760 | LocationSummary* locations = |
| 2761 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 2762 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2763 | } |
| 2764 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2765 | void InstructionCodeGeneratorARM64::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2766 | // Will be generated at use site. |
| 2767 | } |
| 2768 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2769 | void InstructionCodeGeneratorARM64::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2770 | DCHECK(!successor->IsExitBlock()); |
| 2771 | HBasicBlock* block = got->GetBlock(); |
| 2772 | HInstruction* previous = got->GetPrevious(); |
| 2773 | HLoopInformation* info = block->GetLoopInformation(); |
| 2774 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2775 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2776 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck()); |
| 2777 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 2778 | return; |
| 2779 | } |
| 2780 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 2781 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 2782 | } |
| 2783 | if (!codegen_->GoesToNextBlock(block, successor)) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2784 | __ B(codegen_->GetLabelOf(successor)); |
| 2785 | } |
| 2786 | } |
| 2787 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2788 | void LocationsBuilderARM64::VisitGoto(HGoto* got) { |
| 2789 | got->SetLocations(nullptr); |
| 2790 | } |
| 2791 | |
| 2792 | void InstructionCodeGeneratorARM64::VisitGoto(HGoto* got) { |
| 2793 | HandleGoto(got, got->GetSuccessor()); |
| 2794 | } |
| 2795 | |
| 2796 | void LocationsBuilderARM64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 2797 | try_boundary->SetLocations(nullptr); |
| 2798 | } |
| 2799 | |
| 2800 | void InstructionCodeGeneratorARM64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 2801 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 2802 | if (!successor->IsExitBlock()) { |
| 2803 | HandleGoto(try_boundary, successor); |
| 2804 | } |
| 2805 | } |
| 2806 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2807 | void InstructionCodeGeneratorARM64::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2808 | size_t condition_input_index, |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2809 | vixl::Label* true_target, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2810 | vixl::Label* false_target) { |
| 2811 | // FP branching requires both targets to be explicit. If either of the targets |
| 2812 | // is nullptr (fallthrough) use and bind `fallthrough_target` instead. |
| 2813 | vixl::Label fallthrough_target; |
| 2814 | HInstruction* cond = instruction->InputAt(condition_input_index); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2815 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2816 | if (true_target == nullptr && false_target == nullptr) { |
| 2817 | // Nothing to do. The code always falls through. |
| 2818 | return; |
| 2819 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2820 | // Constant condition, statically compared against "true" (integer value 1). |
| 2821 | if (cond->AsIntConstant()->IsTrue()) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2822 | if (true_target != nullptr) { |
| 2823 | __ B(true_target); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2824 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2825 | } else { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2826 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2827 | if (false_target != nullptr) { |
| 2828 | __ B(false_target); |
| 2829 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2830 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2831 | return; |
| 2832 | } |
| 2833 | |
| 2834 | // The following code generates these patterns: |
| 2835 | // (1) true_target == nullptr && false_target != nullptr |
| 2836 | // - opposite condition true => branch to false_target |
| 2837 | // (2) true_target != nullptr && false_target == nullptr |
| 2838 | // - condition true => branch to true_target |
| 2839 | // (3) true_target != nullptr && false_target != nullptr |
| 2840 | // - condition true => branch to true_target |
| 2841 | // - branch to false_target |
| 2842 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2843 | // The condition instruction has been materialized, compare the output to 0. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2844 | Location cond_val = instruction->GetLocations()->InAt(condition_input_index); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2845 | DCHECK(cond_val.IsRegister()); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2846 | if (true_target == nullptr) { |
| 2847 | __ Cbz(InputRegisterAt(instruction, condition_input_index), false_target); |
| 2848 | } else { |
| 2849 | __ Cbnz(InputRegisterAt(instruction, condition_input_index), true_target); |
| 2850 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2851 | } else { |
| 2852 | // The condition instruction has not been materialized, use its inputs as |
| 2853 | // the comparison and its condition as the branch condition. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2854 | HCondition* condition = cond->AsCondition(); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2855 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2856 | Primitive::Type type = condition->InputAt(0)->GetType(); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2857 | if (Primitive::IsFloatingPointType(type)) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2858 | GenerateFcmp(condition); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2859 | if (true_target == nullptr) { |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 2860 | IfCondition opposite_condition = condition->GetOppositeCondition(); |
| 2861 | __ B(ARM64FPCondition(opposite_condition, condition->IsGtBias()), false_target); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2862 | } else { |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 2863 | __ B(ARM64FPCondition(condition->GetCondition(), condition->IsGtBias()), true_target); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2864 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2865 | } else { |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2866 | // Integer cases. |
| 2867 | Register lhs = InputRegisterAt(condition, 0); |
| 2868 | Operand rhs = InputOperandAt(condition, 1); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2869 | |
| 2870 | Condition arm64_cond; |
| 2871 | vixl::Label* non_fallthrough_target; |
| 2872 | if (true_target == nullptr) { |
| 2873 | arm64_cond = ARM64Condition(condition->GetOppositeCondition()); |
| 2874 | non_fallthrough_target = false_target; |
| 2875 | } else { |
| 2876 | arm64_cond = ARM64Condition(condition->GetCondition()); |
| 2877 | non_fallthrough_target = true_target; |
| 2878 | } |
| 2879 | |
Aart Bik | 086d27e | 2016-01-20 17:02:00 -0800 | [diff] [blame] | 2880 | if ((arm64_cond == eq || arm64_cond == ne || arm64_cond == lt || arm64_cond == ge) && |
| 2881 | rhs.IsImmediate() && (rhs.immediate() == 0)) { |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2882 | switch (arm64_cond) { |
| 2883 | case eq: |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2884 | __ Cbz(lhs, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2885 | break; |
| 2886 | case ne: |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2887 | __ Cbnz(lhs, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2888 | break; |
| 2889 | case lt: |
| 2890 | // Test the sign bit and branch accordingly. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2891 | __ Tbnz(lhs, (lhs.IsX() ? kXRegSize : kWRegSize) - 1, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2892 | break; |
| 2893 | case ge: |
| 2894 | // Test the sign bit and branch accordingly. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2895 | __ Tbz(lhs, (lhs.IsX() ? kXRegSize : kWRegSize) - 1, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2896 | break; |
| 2897 | default: |
| 2898 | // Without the `static_cast` the compiler throws an error for |
| 2899 | // `-Werror=sign-promo`. |
| 2900 | LOG(FATAL) << "Unexpected condition: " << static_cast<int>(arm64_cond); |
| 2901 | } |
| 2902 | } else { |
| 2903 | __ Cmp(lhs, rhs); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2904 | __ B(arm64_cond, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2905 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2906 | } |
| 2907 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2908 | |
| 2909 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 2910 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 2911 | if (true_target != nullptr && false_target != nullptr) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2912 | __ B(false_target); |
| 2913 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2914 | |
| 2915 | if (fallthrough_target.IsLinked()) { |
| 2916 | __ Bind(&fallthrough_target); |
| 2917 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2918 | } |
| 2919 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2920 | void LocationsBuilderARM64::VisitIf(HIf* if_instr) { |
| 2921 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2922 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2923 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2924 | } |
| 2925 | } |
| 2926 | |
| 2927 | void InstructionCodeGeneratorARM64::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2928 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 2929 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
| 2930 | vixl::Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 2931 | nullptr : codegen_->GetLabelOf(true_successor); |
| 2932 | vixl::Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 2933 | nullptr : codegen_->GetLabelOf(false_successor); |
| 2934 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2935 | } |
| 2936 | |
| 2937 | void LocationsBuilderARM64::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 2938 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 2939 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2940 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2941 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2942 | } |
| 2943 | } |
| 2944 | |
| 2945 | void InstructionCodeGeneratorARM64::VisitDeoptimize(HDeoptimize* deoptimize) { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 2946 | SlowPathCodeARM64* slow_path = |
| 2947 | deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathARM64>(deoptimize); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2948 | GenerateTestAndBranch(deoptimize, |
| 2949 | /* condition_input_index */ 0, |
| 2950 | slow_path->GetEntryLabel(), |
| 2951 | /* false_target */ nullptr); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2952 | } |
| 2953 | |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 2954 | static inline bool IsConditionOnFloatingPointValues(HInstruction* condition) { |
| 2955 | return condition->IsCondition() && |
| 2956 | Primitive::IsFloatingPointType(condition->InputAt(0)->GetType()); |
| 2957 | } |
| 2958 | |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame^] | 2959 | static inline Condition GetConditionForSelect(HCondition* condition) { |
| 2960 | IfCondition cond = condition->AsCondition()->GetCondition(); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 2961 | return IsConditionOnFloatingPointValues(condition) ? ARM64FPCondition(cond, condition->IsGtBias()) |
| 2962 | : ARM64Condition(cond); |
| 2963 | } |
| 2964 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 2965 | void LocationsBuilderARM64::VisitSelect(HSelect* select) { |
| 2966 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(select); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame^] | 2967 | if (Primitive::IsFloatingPointType(select->GetType())) { |
| 2968 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2969 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2970 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2971 | } else { |
| 2972 | HConstant* cst_true_value = select->GetTrueValue()->AsConstant(); |
| 2973 | HConstant* cst_false_value = select->GetFalseValue()->AsConstant(); |
| 2974 | bool is_true_value_constant = cst_true_value != nullptr; |
| 2975 | bool is_false_value_constant = cst_false_value != nullptr; |
| 2976 | // Ask VIXL whether we should synthesize constants in registers. |
| 2977 | // We give an arbitrary register to VIXL when dealing with non-constant inputs. |
| 2978 | Operand true_op = is_true_value_constant ? |
| 2979 | Operand(Int64FromConstant(cst_true_value)) : Operand(x1); |
| 2980 | Operand false_op = is_false_value_constant ? |
| 2981 | Operand(Int64FromConstant(cst_false_value)) : Operand(x2); |
| 2982 | bool true_value_in_register = false; |
| 2983 | bool false_value_in_register = false; |
| 2984 | MacroAssembler::GetCselSynthesisInformation( |
| 2985 | x0, true_op, false_op, &true_value_in_register, &false_value_in_register); |
| 2986 | true_value_in_register |= !is_true_value_constant; |
| 2987 | false_value_in_register |= !is_false_value_constant; |
| 2988 | |
| 2989 | locations->SetInAt(1, true_value_in_register ? Location::RequiresRegister() |
| 2990 | : Location::ConstantLocation(cst_true_value)); |
| 2991 | locations->SetInAt(0, false_value_in_register ? Location::RequiresRegister() |
| 2992 | : Location::ConstantLocation(cst_false_value)); |
| 2993 | locations->SetOut(Location::RequiresRegister()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 2994 | } |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame^] | 2995 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 2996 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
| 2997 | locations->SetInAt(2, Location::RequiresRegister()); |
| 2998 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 2999 | } |
| 3000 | |
| 3001 | void InstructionCodeGeneratorARM64::VisitSelect(HSelect* select) { |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3002 | HInstruction* cond = select->GetCondition(); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3003 | Condition csel_cond; |
| 3004 | |
| 3005 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 3006 | if (cond->IsCondition() && cond->GetNext() == select) { |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame^] | 3007 | // Use the condition flags set by the previous instruction. |
| 3008 | csel_cond = GetConditionForSelect(cond->AsCondition()); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3009 | } else { |
| 3010 | __ Cmp(InputRegisterAt(select, 2), 0); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame^] | 3011 | csel_cond = ne; |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3012 | } |
| 3013 | } else if (IsConditionOnFloatingPointValues(cond)) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3014 | GenerateFcmp(cond); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame^] | 3015 | csel_cond = GetConditionForSelect(cond->AsCondition()); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3016 | } else { |
| 3017 | __ Cmp(InputRegisterAt(cond, 0), InputOperandAt(cond, 1)); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame^] | 3018 | csel_cond = GetConditionForSelect(cond->AsCondition()); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3019 | } |
| 3020 | |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame^] | 3021 | if (Primitive::IsFloatingPointType(select->GetType())) { |
| 3022 | __ Fcsel(OutputFPRegister(select), |
| 3023 | InputFPRegisterAt(select, 1), |
| 3024 | InputFPRegisterAt(select, 0), |
| 3025 | csel_cond); |
| 3026 | } else { |
| 3027 | __ Csel(OutputRegister(select), |
| 3028 | InputOperandAt(select, 1), |
| 3029 | InputOperandAt(select, 0), |
| 3030 | csel_cond); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3031 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3032 | } |
| 3033 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 3034 | void LocationsBuilderARM64::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| 3035 | new (GetGraph()->GetArena()) LocationSummary(info); |
| 3036 | } |
| 3037 | |
David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 3038 | void InstructionCodeGeneratorARM64::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 3039 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 3040 | } |
| 3041 | |
| 3042 | void CodeGeneratorARM64::GenerateNop() { |
| 3043 | __ Nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 3044 | } |
| 3045 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3046 | void LocationsBuilderARM64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 3047 | HandleFieldGet(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3048 | } |
| 3049 | |
| 3050 | void InstructionCodeGeneratorARM64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 3051 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3052 | } |
| 3053 | |
| 3054 | void LocationsBuilderARM64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 3055 | HandleFieldSet(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3056 | } |
| 3057 | |
| 3058 | void InstructionCodeGeneratorARM64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3059 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3060 | } |
| 3061 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3062 | static bool TypeCheckNeedsATemporary(TypeCheckKind type_check_kind) { |
| 3063 | return kEmitCompilerReadBarrier && |
| 3064 | (kUseBakerReadBarrier || |
| 3065 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 3066 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 3067 | type_check_kind == TypeCheckKind::kArrayObjectCheck); |
| 3068 | } |
| 3069 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3070 | void LocationsBuilderARM64::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3071 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3072 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 3073 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3074 | case TypeCheckKind::kExactCheck: |
| 3075 | case TypeCheckKind::kAbstractClassCheck: |
| 3076 | case TypeCheckKind::kClassHierarchyCheck: |
| 3077 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3078 | call_kind = |
| 3079 | kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3080 | break; |
| 3081 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3082 | case TypeCheckKind::kUnresolvedCheck: |
| 3083 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3084 | call_kind = LocationSummary::kCallOnSlowPath; |
| 3085 | break; |
| 3086 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3087 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3088 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3089 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3090 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3091 | // The "out" register is used as a temporary, so it overlaps with the inputs. |
| 3092 | // Note that TypeCheckSlowPathARM64 uses this register too. |
| 3093 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 3094 | // When read barriers are enabled, we need a temporary register for |
| 3095 | // some cases. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3096 | if (TypeCheckNeedsATemporary(type_check_kind)) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3097 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3098 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3099 | } |
| 3100 | |
| 3101 | void InstructionCodeGeneratorARM64::VisitInstanceOf(HInstanceOf* instruction) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3102 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3103 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3104 | Location obj_loc = locations->InAt(0); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3105 | Register obj = InputRegisterAt(instruction, 0); |
| 3106 | Register cls = InputRegisterAt(instruction, 1); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3107 | Location out_loc = locations->Out(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3108 | Register out = OutputRegister(instruction); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3109 | Location maybe_temp_loc = TypeCheckNeedsATemporary(type_check_kind) ? |
| 3110 | locations->GetTemp(0) : |
| 3111 | Location::NoLocation(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3112 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 3113 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 3114 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 3115 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3116 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3117 | vixl::Label done, zero; |
| 3118 | SlowPathCodeARM64* slow_path = nullptr; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3119 | |
| 3120 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 3121 | // Avoid null check if we know `obj` is not null. |
| 3122 | if (instruction->MustDoNullCheck()) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3123 | __ Cbz(obj, &zero); |
| 3124 | } |
| 3125 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3126 | // /* HeapReference<Class> */ out = obj->klass_ |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3127 | GenerateReferenceLoadTwoRegisters(instruction, out_loc, obj_loc, class_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3128 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3129 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3130 | case TypeCheckKind::kExactCheck: { |
| 3131 | __ Cmp(out, cls); |
| 3132 | __ Cset(out, eq); |
| 3133 | if (zero.IsLinked()) { |
| 3134 | __ B(&done); |
| 3135 | } |
| 3136 | break; |
| 3137 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3138 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3139 | case TypeCheckKind::kAbstractClassCheck: { |
| 3140 | // If the class is abstract, we eagerly fetch the super class of the |
| 3141 | // object to avoid doing a comparison we know will fail. |
| 3142 | vixl::Label loop, success; |
| 3143 | __ Bind(&loop); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3144 | // /* HeapReference<Class> */ out = out->super_class_ |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3145 | GenerateReferenceLoadOneRegister(instruction, out_loc, super_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3146 | // If `out` is null, we use it for the result, and jump to `done`. |
| 3147 | __ Cbz(out, &done); |
| 3148 | __ Cmp(out, cls); |
| 3149 | __ B(ne, &loop); |
| 3150 | __ Mov(out, 1); |
| 3151 | if (zero.IsLinked()) { |
| 3152 | __ B(&done); |
| 3153 | } |
| 3154 | break; |
| 3155 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3156 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3157 | case TypeCheckKind::kClassHierarchyCheck: { |
| 3158 | // Walk over the class hierarchy to find a match. |
| 3159 | vixl::Label loop, success; |
| 3160 | __ Bind(&loop); |
| 3161 | __ Cmp(out, cls); |
| 3162 | __ B(eq, &success); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3163 | // /* HeapReference<Class> */ out = out->super_class_ |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3164 | GenerateReferenceLoadOneRegister(instruction, out_loc, super_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3165 | __ Cbnz(out, &loop); |
| 3166 | // If `out` is null, we use it for the result, and jump to `done`. |
| 3167 | __ B(&done); |
| 3168 | __ Bind(&success); |
| 3169 | __ Mov(out, 1); |
| 3170 | if (zero.IsLinked()) { |
| 3171 | __ B(&done); |
| 3172 | } |
| 3173 | break; |
| 3174 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3175 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3176 | case TypeCheckKind::kArrayObjectCheck: { |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 3177 | // Do an exact check. |
| 3178 | vixl::Label exact_check; |
| 3179 | __ Cmp(out, cls); |
| 3180 | __ B(eq, &exact_check); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3181 | // Otherwise, we need to check that the object's class is a non-primitive array. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3182 | // /* HeapReference<Class> */ out = out->component_type_ |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3183 | GenerateReferenceLoadOneRegister(instruction, out_loc, component_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3184 | // If `out` is null, we use it for the result, and jump to `done`. |
| 3185 | __ Cbz(out, &done); |
| 3186 | __ Ldrh(out, HeapOperand(out, primitive_offset)); |
| 3187 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
| 3188 | __ Cbnz(out, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 3189 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3190 | __ Mov(out, 1); |
| 3191 | __ B(&done); |
| 3192 | break; |
| 3193 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3194 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3195 | case TypeCheckKind::kArrayCheck: { |
| 3196 | __ Cmp(out, cls); |
| 3197 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3198 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM64(instruction, |
| 3199 | /* is_fatal */ false); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3200 | codegen_->AddSlowPath(slow_path); |
| 3201 | __ B(ne, slow_path->GetEntryLabel()); |
| 3202 | __ Mov(out, 1); |
| 3203 | if (zero.IsLinked()) { |
| 3204 | __ B(&done); |
| 3205 | } |
| 3206 | break; |
| 3207 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3208 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 3209 | case TypeCheckKind::kUnresolvedCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3210 | case TypeCheckKind::kInterfaceCheck: { |
| 3211 | // Note that we indeed only call on slow path, but we always go |
| 3212 | // into the slow path for the unresolved and interface check |
| 3213 | // cases. |
| 3214 | // |
| 3215 | // We cannot directly call the InstanceofNonTrivial runtime |
| 3216 | // entry point without resorting to a type checking slow path |
| 3217 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 3218 | // require to assign fixed registers for the inputs of this |
| 3219 | // HInstanceOf instruction (following the runtime calling |
| 3220 | // convention), which might be cluttered by the potential first |
| 3221 | // read barrier emission at the beginning of this method. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3222 | // |
| 3223 | // TODO: Introduce a new runtime entry point taking the object |
| 3224 | // to test (instead of its class) as argument, and let it deal |
| 3225 | // with the read barrier issues. This will let us refactor this |
| 3226 | // case of the `switch` code as it was previously (with a direct |
| 3227 | // call to the runtime not using a type checking slow path). |
| 3228 | // This should also be beneficial for the other cases above. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3229 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 3230 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM64(instruction, |
| 3231 | /* is_fatal */ false); |
| 3232 | codegen_->AddSlowPath(slow_path); |
| 3233 | __ B(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3234 | if (zero.IsLinked()) { |
| 3235 | __ B(&done); |
| 3236 | } |
| 3237 | break; |
| 3238 | } |
| 3239 | } |
| 3240 | |
| 3241 | if (zero.IsLinked()) { |
| 3242 | __ Bind(&zero); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 3243 | __ Mov(out, 0); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3244 | } |
| 3245 | |
| 3246 | if (done.IsLinked()) { |
| 3247 | __ Bind(&done); |
| 3248 | } |
| 3249 | |
| 3250 | if (slow_path != nullptr) { |
| 3251 | __ Bind(slow_path->GetExitLabel()); |
| 3252 | } |
| 3253 | } |
| 3254 | |
| 3255 | void LocationsBuilderARM64::VisitCheckCast(HCheckCast* instruction) { |
| 3256 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 3257 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
| 3258 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3259 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 3260 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3261 | case TypeCheckKind::kExactCheck: |
| 3262 | case TypeCheckKind::kAbstractClassCheck: |
| 3263 | case TypeCheckKind::kClassHierarchyCheck: |
| 3264 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3265 | call_kind = (throws_into_catch || kEmitCompilerReadBarrier) ? |
| 3266 | LocationSummary::kCallOnSlowPath : |
| 3267 | LocationSummary::kNoCall; // In fact, call on a fatal (non-returning) slow path. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3268 | break; |
| 3269 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3270 | case TypeCheckKind::kUnresolvedCheck: |
| 3271 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3272 | call_kind = LocationSummary::kCallOnSlowPath; |
| 3273 | break; |
| 3274 | } |
| 3275 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3276 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 3277 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3278 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3279 | // Note that TypeCheckSlowPathARM64 uses this "temp" register too. |
| 3280 | locations->AddTemp(Location::RequiresRegister()); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3281 | // When read barriers are enabled, we need an additional temporary |
| 3282 | // register for some cases. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3283 | if (TypeCheckNeedsATemporary(type_check_kind)) { |
| 3284 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3285 | } |
| 3286 | } |
| 3287 | |
| 3288 | void InstructionCodeGeneratorARM64::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3289 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3290 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3291 | Location obj_loc = locations->InAt(0); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3292 | Register obj = InputRegisterAt(instruction, 0); |
| 3293 | Register cls = InputRegisterAt(instruction, 1); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3294 | Location temp_loc = locations->GetTemp(0); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3295 | Location maybe_temp2_loc = TypeCheckNeedsATemporary(type_check_kind) ? |
| 3296 | locations->GetTemp(1) : |
| 3297 | Location::NoLocation(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3298 | Register temp = WRegisterFrom(temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3299 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 3300 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 3301 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 3302 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3303 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3304 | bool is_type_check_slow_path_fatal = |
| 3305 | (type_check_kind == TypeCheckKind::kExactCheck || |
| 3306 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 3307 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 3308 | type_check_kind == TypeCheckKind::kArrayObjectCheck) && |
| 3309 | !instruction->CanThrowIntoCatchBlock(); |
| 3310 | SlowPathCodeARM64* type_check_slow_path = |
| 3311 | new (GetGraph()->GetArena()) TypeCheckSlowPathARM64(instruction, |
| 3312 | is_type_check_slow_path_fatal); |
| 3313 | codegen_->AddSlowPath(type_check_slow_path); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3314 | |
| 3315 | vixl::Label done; |
| 3316 | // Avoid null check if we know obj is not null. |
| 3317 | if (instruction->MustDoNullCheck()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 3318 | __ Cbz(obj, &done); |
| 3319 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3320 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3321 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3322 | GenerateReferenceLoadTwoRegisters(instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame] | 3323 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3324 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3325 | case TypeCheckKind::kExactCheck: |
| 3326 | case TypeCheckKind::kArrayCheck: { |
| 3327 | __ Cmp(temp, cls); |
| 3328 | // Jump to slow path for throwing the exception or doing a |
| 3329 | // more involved array check. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3330 | __ B(ne, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3331 | break; |
| 3332 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3333 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3334 | case TypeCheckKind::kAbstractClassCheck: { |
| 3335 | // If the class is abstract, we eagerly fetch the super class of the |
| 3336 | // object to avoid doing a comparison we know will fail. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3337 | vixl::Label loop, compare_classes; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3338 | __ Bind(&loop); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3339 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3340 | GenerateReferenceLoadOneRegister(instruction, temp_loc, super_offset, maybe_temp2_loc); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3341 | |
| 3342 | // If the class reference currently in `temp` is not null, jump |
| 3343 | // to the `compare_classes` label to compare it with the checked |
| 3344 | // class. |
| 3345 | __ Cbnz(temp, &compare_classes); |
| 3346 | // Otherwise, jump to the slow path to throw the exception. |
| 3347 | // |
| 3348 | // But before, move back the object's class into `temp` before |
| 3349 | // going into the slow path, as it has been overwritten in the |
| 3350 | // meantime. |
| 3351 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3352 | GenerateReferenceLoadTwoRegisters( |
| 3353 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3354 | __ B(type_check_slow_path->GetEntryLabel()); |
| 3355 | |
| 3356 | __ Bind(&compare_classes); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3357 | __ Cmp(temp, cls); |
| 3358 | __ B(ne, &loop); |
| 3359 | break; |
| 3360 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3361 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3362 | case TypeCheckKind::kClassHierarchyCheck: { |
| 3363 | // Walk over the class hierarchy to find a match. |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 3364 | vixl::Label loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3365 | __ Bind(&loop); |
| 3366 | __ Cmp(temp, cls); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 3367 | __ B(eq, &done); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3368 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3369 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3370 | GenerateReferenceLoadOneRegister(instruction, temp_loc, super_offset, maybe_temp2_loc); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3371 | |
| 3372 | // If the class reference currently in `temp` is not null, jump |
| 3373 | // back at the beginning of the loop. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3374 | __ Cbnz(temp, &loop); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3375 | // Otherwise, jump to the slow path to throw the exception. |
| 3376 | // |
| 3377 | // But before, move back the object's class into `temp` before |
| 3378 | // going into the slow path, as it has been overwritten in the |
| 3379 | // meantime. |
| 3380 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3381 | GenerateReferenceLoadTwoRegisters( |
| 3382 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3383 | __ B(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3384 | break; |
| 3385 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3386 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3387 | case TypeCheckKind::kArrayObjectCheck: { |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 3388 | // Do an exact check. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3389 | vixl::Label check_non_primitive_component_type; |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 3390 | __ Cmp(temp, cls); |
| 3391 | __ B(eq, &done); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3392 | |
| 3393 | // Otherwise, we need to check that the object's class is a non-primitive array. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3394 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3395 | GenerateReferenceLoadOneRegister(instruction, temp_loc, component_offset, maybe_temp2_loc); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3396 | |
| 3397 | // If the component type is not null (i.e. the object is indeed |
| 3398 | // an array), jump to label `check_non_primitive_component_type` |
| 3399 | // to further check that this component type is not a primitive |
| 3400 | // type. |
| 3401 | __ Cbnz(temp, &check_non_primitive_component_type); |
| 3402 | // Otherwise, jump to the slow path to throw the exception. |
| 3403 | // |
| 3404 | // But before, move back the object's class into `temp` before |
| 3405 | // going into the slow path, as it has been overwritten in the |
| 3406 | // meantime. |
| 3407 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3408 | GenerateReferenceLoadTwoRegisters( |
| 3409 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3410 | __ B(type_check_slow_path->GetEntryLabel()); |
| 3411 | |
| 3412 | __ Bind(&check_non_primitive_component_type); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3413 | __ Ldrh(temp, HeapOperand(temp, primitive_offset)); |
| 3414 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3415 | __ Cbz(temp, &done); |
| 3416 | // Same comment as above regarding `temp` and the slow path. |
| 3417 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3418 | GenerateReferenceLoadTwoRegisters( |
| 3419 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3420 | __ B(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3421 | break; |
| 3422 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3423 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 3424 | case TypeCheckKind::kUnresolvedCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3425 | case TypeCheckKind::kInterfaceCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3426 | // We always go into the type check slow path for the unresolved |
| 3427 | // and interface check cases. |
| 3428 | // |
| 3429 | // We cannot directly call the CheckCast runtime entry point |
| 3430 | // without resorting to a type checking slow path here (i.e. by |
| 3431 | // calling InvokeRuntime directly), as it would require to |
| 3432 | // assign fixed registers for the inputs of this HInstanceOf |
| 3433 | // instruction (following the runtime calling convention), which |
| 3434 | // might be cluttered by the potential first read barrier |
| 3435 | // emission at the beginning of this method. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3436 | // |
| 3437 | // TODO: Introduce a new runtime entry point taking the object |
| 3438 | // to test (instead of its class) as argument, and let it deal |
| 3439 | // with the read barrier issues. This will let us refactor this |
| 3440 | // case of the `switch` code as it was previously (with a direct |
| 3441 | // call to the runtime not using a type checking slow path). |
| 3442 | // This should also be beneficial for the other cases above. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3443 | __ B(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3444 | break; |
| 3445 | } |
Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame] | 3446 | __ Bind(&done); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3447 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3448 | __ Bind(type_check_slow_path->GetExitLabel()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3449 | } |
| 3450 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3451 | void LocationsBuilderARM64::VisitIntConstant(HIntConstant* constant) { |
| 3452 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant); |
| 3453 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3454 | } |
| 3455 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3456 | void InstructionCodeGeneratorARM64::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3457 | // Will be generated at use site. |
| 3458 | } |
| 3459 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 3460 | void LocationsBuilderARM64::VisitNullConstant(HNullConstant* constant) { |
| 3461 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant); |
| 3462 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3463 | } |
| 3464 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3465 | void InstructionCodeGeneratorARM64::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 3466 | // Will be generated at use site. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 3467 | } |
| 3468 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 3469 | void LocationsBuilderARM64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 3470 | // The trampoline uses the same calling convention as dex calling conventions, |
| 3471 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 3472 | // the method_idx. |
| 3473 | HandleInvoke(invoke); |
| 3474 | } |
| 3475 | |
| 3476 | void InstructionCodeGeneratorARM64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 3477 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 3478 | } |
| 3479 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3480 | void LocationsBuilderARM64::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 3481 | InvokeDexCallingConventionVisitorARM64 calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 3482 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3483 | } |
| 3484 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3485 | void LocationsBuilderARM64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 3486 | HandleInvoke(invoke); |
| 3487 | } |
| 3488 | |
| 3489 | void InstructionCodeGeneratorARM64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 3490 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3491 | LocationSummary* locations = invoke->GetLocations(); |
| 3492 | Register temp = XRegisterFrom(locations->GetTemp(0)); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 3493 | uint32_t method_offset = mirror::Class::EmbeddedImTableEntryOffset( |
| 3494 | invoke->GetImtIndex() % mirror::Class::kImtSize, kArm64PointerSize).Uint32Value(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3495 | Location receiver = locations->InAt(0); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3496 | Offset class_offset = mirror::Object::ClassOffset(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 3497 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64WordSize); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3498 | |
| 3499 | // The register ip1 is required to be used for the hidden argument in |
| 3500 | // art_quick_imt_conflict_trampoline, so prevent VIXL from using it. |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 3501 | MacroAssembler* masm = GetVIXLAssembler(); |
| 3502 | UseScratchRegisterScope scratch_scope(masm); |
| 3503 | BlockPoolsScope block_pools(masm); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3504 | scratch_scope.Exclude(ip1); |
| 3505 | __ Mov(ip1, invoke->GetDexMethodIndex()); |
| 3506 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3507 | if (receiver.IsStackSlot()) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 3508 | __ Ldr(temp.W(), StackOperandFrom(receiver)); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3509 | // /* HeapReference<Class> */ temp = temp->klass_ |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 3510 | __ Ldr(temp.W(), HeapOperand(temp.W(), class_offset)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3511 | } else { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3512 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 3513 | __ Ldr(temp.W(), HeapOperandFrom(receiver, class_offset)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3514 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3515 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3516 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 3517 | // emit a read barrier for the previous class reference load. |
| 3518 | // However this is not required in practice, as this is an |
| 3519 | // intermediate/temporary reference and because the current |
| 3520 | // concurrent copying collector keeps the from-space memory |
| 3521 | // intact/accessible until the end of the marking phase (the |
| 3522 | // concurrent copying collector may not in the future). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3523 | GetAssembler()->MaybeUnpoisonHeapReference(temp.W()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3524 | // temp = temp->GetImtEntryAt(method_offset); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 3525 | __ Ldr(temp, MemOperand(temp, method_offset)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3526 | // lr = temp->GetEntryPoint(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 3527 | __ Ldr(lr, MemOperand(temp, entry_point.Int32Value())); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3528 | // lr(); |
| 3529 | __ Blr(lr); |
| 3530 | DCHECK(!codegen_->IsLeafMethod()); |
| 3531 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 3532 | } |
| 3533 | |
| 3534 | void LocationsBuilderARM64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 3535 | IntrinsicLocationsBuilderARM64 intrinsic(GetGraph()->GetArena()); |
| 3536 | if (intrinsic.TryDispatch(invoke)) { |
| 3537 | return; |
| 3538 | } |
| 3539 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3540 | HandleInvoke(invoke); |
| 3541 | } |
| 3542 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 3543 | void LocationsBuilderARM64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 3544 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 3545 | // art::PrepareForRegisterAllocation. |
| 3546 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3547 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 3548 | IntrinsicLocationsBuilderARM64 intrinsic(GetGraph()->GetArena()); |
| 3549 | if (intrinsic.TryDispatch(invoke)) { |
| 3550 | return; |
| 3551 | } |
| 3552 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3553 | HandleInvoke(invoke); |
| 3554 | } |
| 3555 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 3556 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARM64* codegen) { |
| 3557 | if (invoke->GetLocations()->Intrinsified()) { |
| 3558 | IntrinsicCodeGeneratorARM64 intrinsic(codegen); |
| 3559 | intrinsic.Dispatch(invoke); |
| 3560 | return true; |
| 3561 | } |
| 3562 | return false; |
| 3563 | } |
| 3564 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3565 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorARM64::GetSupportedInvokeStaticOrDirectDispatch( |
| 3566 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
| 3567 | MethodReference target_method ATTRIBUTE_UNUSED) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3568 | // On ARM64 we support all dispatch types. |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3569 | return desired_dispatch_info; |
| 3570 | } |
| 3571 | |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 3572 | void CodeGeneratorARM64::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3573 | // For better instruction scheduling we load the direct code pointer before the method pointer. |
| 3574 | bool direct_code_loaded = false; |
| 3575 | switch (invoke->GetCodePtrLocation()) { |
| 3576 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 3577 | // LR = code address from literal pool with link-time patch. |
| 3578 | __ Ldr(lr, DeduplicateMethodCodeLiteral(invoke->GetTargetMethod())); |
| 3579 | direct_code_loaded = true; |
| 3580 | break; |
| 3581 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
| 3582 | // LR = invoke->GetDirectCodePtr(); |
| 3583 | __ Ldr(lr, DeduplicateUint64Literal(invoke->GetDirectCodePtr())); |
| 3584 | direct_code_loaded = true; |
| 3585 | break; |
| 3586 | default: |
| 3587 | break; |
| 3588 | } |
| 3589 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 3590 | // Make sure that ArtMethod* is passed in kArtMethodRegister as per the calling convention. |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3591 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 3592 | switch (invoke->GetMethodLoadKind()) { |
| 3593 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: |
| 3594 | // temp = thread->string_init_entrypoint |
Alexandre Rames | 6dc0174 | 2015-11-12 14:44:19 +0000 | [diff] [blame] | 3595 | __ Ldr(XRegisterFrom(temp), MemOperand(tr, invoke->GetStringInitOffset())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3596 | break; |
| 3597 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3598 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3599 | break; |
| 3600 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 3601 | // Load method address from literal pool. |
Alexandre Rames | 6dc0174 | 2015-11-12 14:44:19 +0000 | [diff] [blame] | 3602 | __ Ldr(XRegisterFrom(temp), DeduplicateUint64Literal(invoke->GetMethodAddress())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3603 | break; |
| 3604 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup: |
| 3605 | // Load method address from literal pool with a link-time patch. |
Alexandre Rames | 6dc0174 | 2015-11-12 14:44:19 +0000 | [diff] [blame] | 3606 | __ Ldr(XRegisterFrom(temp), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3607 | DeduplicateMethodAddressLiteral(invoke->GetTargetMethod())); |
| 3608 | break; |
| 3609 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: { |
| 3610 | // Add ADRP with its PC-relative DexCache access patch. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 3611 | const DexFile& dex_file = *invoke->GetTargetMethod().dex_file; |
| 3612 | uint32_t element_offset = invoke->GetDexCacheArrayOffset(); |
| 3613 | vixl::Label* adrp_label = NewPcRelativeDexCacheArrayPatch(dex_file, element_offset); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3614 | { |
| 3615 | vixl::SingleEmissionCheckScope guard(GetVIXLAssembler()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 3616 | __ Bind(adrp_label); |
| 3617 | __ adrp(XRegisterFrom(temp), /* offset placeholder */ 0); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3618 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3619 | // Add LDR with its PC-relative DexCache access patch. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 3620 | vixl::Label* ldr_label = |
| 3621 | NewPcRelativeDexCacheArrayPatch(dex_file, element_offset, adrp_label); |
Alexandre Rames | 6dc0174 | 2015-11-12 14:44:19 +0000 | [diff] [blame] | 3622 | { |
| 3623 | vixl::SingleEmissionCheckScope guard(GetVIXLAssembler()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 3624 | __ Bind(ldr_label); |
| 3625 | __ ldr(XRegisterFrom(temp), MemOperand(XRegisterFrom(temp), /* offset placeholder */ 0)); |
Alexandre Rames | 6dc0174 | 2015-11-12 14:44:19 +0000 | [diff] [blame] | 3626 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3627 | break; |
Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 3628 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3629 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3630 | Location current_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3631 | Register reg = XRegisterFrom(temp); |
| 3632 | Register method_reg; |
| 3633 | if (current_method.IsRegister()) { |
| 3634 | method_reg = XRegisterFrom(current_method); |
| 3635 | } else { |
| 3636 | DCHECK(invoke->GetLocations()->Intrinsified()); |
| 3637 | DCHECK(!current_method.IsValid()); |
| 3638 | method_reg = reg; |
| 3639 | __ Ldr(reg.X(), MemOperand(sp, kCurrentMethodStackOffset)); |
| 3640 | } |
Vladimir Marko | b2c431e | 2015-08-19 12:45:42 +0000 | [diff] [blame] | 3641 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3642 | // /* ArtMethod*[] */ temp = temp.ptr_sized_fields_->dex_cache_resolved_methods_; |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 3643 | __ Ldr(reg.X(), |
| 3644 | MemOperand(method_reg.X(), |
| 3645 | ArtMethod::DexCacheResolvedMethodsOffset(kArm64WordSize).Int32Value())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3646 | // temp = temp[index_in_cache]; |
Vladimir Marko | 40ecb12 | 2016-04-06 17:33:41 +0100 | [diff] [blame] | 3647 | // Note: Don't use invoke->GetTargetMethod() as it may point to a different dex file. |
| 3648 | uint32_t index_in_cache = invoke->GetDexMethodIndex(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3649 | __ Ldr(reg.X(), MemOperand(reg.X(), GetCachePointerOffset(index_in_cache))); |
| 3650 | break; |
| 3651 | } |
| 3652 | } |
| 3653 | |
| 3654 | switch (invoke->GetCodePtrLocation()) { |
| 3655 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 3656 | __ Bl(&frame_entry_label_); |
| 3657 | break; |
| 3658 | case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative: { |
| 3659 | relative_call_patches_.emplace_back(invoke->GetTargetMethod()); |
| 3660 | vixl::Label* label = &relative_call_patches_.back().label; |
Alexandre Rames | 6dc0174 | 2015-11-12 14:44:19 +0000 | [diff] [blame] | 3661 | vixl::SingleEmissionCheckScope guard(GetVIXLAssembler()); |
| 3662 | __ Bind(label); |
| 3663 | __ bl(0); // Branch and link to itself. This will be overriden at link time. |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3664 | break; |
| 3665 | } |
| 3666 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 3667 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
| 3668 | // LR prepared above for better instruction scheduling. |
| 3669 | DCHECK(direct_code_loaded); |
| 3670 | // lr() |
| 3671 | __ Blr(lr); |
| 3672 | break; |
| 3673 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 3674 | // LR = callee_method->entry_point_from_quick_compiled_code_; |
| 3675 | __ Ldr(lr, MemOperand( |
Alexandre Rames | 6dc0174 | 2015-11-12 14:44:19 +0000 | [diff] [blame] | 3676 | XRegisterFrom(callee_method), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3677 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64WordSize).Int32Value())); |
| 3678 | // lr() |
| 3679 | __ Blr(lr); |
| 3680 | break; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 3681 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3682 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 3683 | DCHECK(!IsLeafMethod()); |
| 3684 | } |
| 3685 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 3686 | void CodeGeneratorARM64::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_in) { |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 3687 | // Use the calling convention instead of the location of the receiver, as |
| 3688 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 3689 | // slow path, the arguments have been moved to the right place, so here we are |
| 3690 | // guaranteed that the receiver is the first register of the calling convention. |
| 3691 | InvokeDexCallingConvention calling_convention; |
| 3692 | Register receiver = calling_convention.GetRegisterAt(0); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 3693 | Register temp = XRegisterFrom(temp_in); |
| 3694 | size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 3695 | invoke->GetVTableIndex(), kArm64PointerSize).SizeValue(); |
| 3696 | Offset class_offset = mirror::Object::ClassOffset(); |
| 3697 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64WordSize); |
| 3698 | |
| 3699 | BlockPoolsScope block_pools(GetVIXLAssembler()); |
| 3700 | |
| 3701 | DCHECK(receiver.IsRegister()); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3702 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 3703 | __ Ldr(temp.W(), HeapOperandFrom(LocationFrom(receiver), class_offset)); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 3704 | MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3705 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 3706 | // emit a read barrier for the previous class reference load. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3707 | // intermediate/temporary reference and because the current |
| 3708 | // concurrent copying collector keeps the from-space memory |
| 3709 | // intact/accessible until the end of the marking phase (the |
| 3710 | // concurrent copying collector may not in the future). |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 3711 | GetAssembler()->MaybeUnpoisonHeapReference(temp.W()); |
| 3712 | // temp = temp->GetMethodAt(method_offset); |
| 3713 | __ Ldr(temp, MemOperand(temp, method_offset)); |
| 3714 | // lr = temp->GetEntryPoint(); |
| 3715 | __ Ldr(lr, MemOperand(temp, entry_point.SizeValue())); |
| 3716 | // lr(); |
| 3717 | __ Blr(lr); |
| 3718 | } |
| 3719 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 3720 | vixl::Label* CodeGeneratorARM64::NewPcRelativeStringPatch(const DexFile& dex_file, |
| 3721 | uint32_t string_index, |
| 3722 | vixl::Label* adrp_label) { |
| 3723 | return NewPcRelativePatch(dex_file, string_index, adrp_label, &pc_relative_string_patches_); |
| 3724 | } |
| 3725 | |
| 3726 | vixl::Label* CodeGeneratorARM64::NewPcRelativeDexCacheArrayPatch(const DexFile& dex_file, |
| 3727 | uint32_t element_offset, |
| 3728 | vixl::Label* adrp_label) { |
| 3729 | return NewPcRelativePatch(dex_file, element_offset, adrp_label, &pc_relative_dex_cache_patches_); |
| 3730 | } |
| 3731 | |
| 3732 | vixl::Label* CodeGeneratorARM64::NewPcRelativePatch(const DexFile& dex_file, |
| 3733 | uint32_t offset_or_index, |
| 3734 | vixl::Label* adrp_label, |
| 3735 | ArenaDeque<PcRelativePatchInfo>* patches) { |
| 3736 | // Add a patch entry and return the label. |
| 3737 | patches->emplace_back(dex_file, offset_or_index); |
| 3738 | PcRelativePatchInfo* info = &patches->back(); |
| 3739 | vixl::Label* label = &info->label; |
| 3740 | // If adrp_label is null, this is the ADRP patch and needs to point to its own label. |
| 3741 | info->pc_insn_label = (adrp_label != nullptr) ? adrp_label : label; |
| 3742 | return label; |
| 3743 | } |
| 3744 | |
| 3745 | vixl::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateBootImageStringLiteral( |
| 3746 | const DexFile& dex_file, uint32_t string_index) { |
| 3747 | return boot_image_string_patches_.GetOrCreate( |
| 3748 | StringReference(&dex_file, string_index), |
| 3749 | [this]() { return __ CreateLiteralDestroyedWithPool<uint32_t>(/* placeholder */ 0u); }); |
| 3750 | } |
| 3751 | |
| 3752 | vixl::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateBootImageAddressLiteral(uint64_t address) { |
| 3753 | bool needs_patch = GetCompilerOptions().GetIncludePatchInformation(); |
| 3754 | Uint32ToLiteralMap* map = needs_patch ? &boot_image_address_patches_ : &uint32_literals_; |
| 3755 | return DeduplicateUint32Literal(dchecked_integral_cast<uint32_t>(address), map); |
| 3756 | } |
| 3757 | |
| 3758 | vixl::Literal<uint64_t>* CodeGeneratorARM64::DeduplicateDexCacheAddressLiteral(uint64_t address) { |
| 3759 | return DeduplicateUint64Literal(address); |
| 3760 | } |
| 3761 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3762 | void CodeGeneratorARM64::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) { |
| 3763 | DCHECK(linker_patches->empty()); |
| 3764 | size_t size = |
| 3765 | method_patches_.size() + |
| 3766 | call_patches_.size() + |
| 3767 | relative_call_patches_.size() + |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 3768 | pc_relative_dex_cache_patches_.size() + |
| 3769 | boot_image_string_patches_.size() + |
| 3770 | pc_relative_string_patches_.size() + |
| 3771 | boot_image_address_patches_.size(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3772 | linker_patches->reserve(size); |
| 3773 | for (const auto& entry : method_patches_) { |
| 3774 | const MethodReference& target_method = entry.first; |
| 3775 | vixl::Literal<uint64_t>* literal = entry.second; |
| 3776 | linker_patches->push_back(LinkerPatch::MethodPatch(literal->offset(), |
| 3777 | target_method.dex_file, |
| 3778 | target_method.dex_method_index)); |
| 3779 | } |
| 3780 | for (const auto& entry : call_patches_) { |
| 3781 | const MethodReference& target_method = entry.first; |
| 3782 | vixl::Literal<uint64_t>* literal = entry.second; |
| 3783 | linker_patches->push_back(LinkerPatch::CodePatch(literal->offset(), |
| 3784 | target_method.dex_file, |
| 3785 | target_method.dex_method_index)); |
| 3786 | } |
| 3787 | for (const MethodPatchInfo<vixl::Label>& info : relative_call_patches_) { |
Alexandre Rames | 6dc0174 | 2015-11-12 14:44:19 +0000 | [diff] [blame] | 3788 | linker_patches->push_back(LinkerPatch::RelativeCodePatch(info.label.location(), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3789 | info.target_method.dex_file, |
| 3790 | info.target_method.dex_method_index)); |
| 3791 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 3792 | for (const PcRelativePatchInfo& info : pc_relative_dex_cache_patches_) { |
Alexandre Rames | 6dc0174 | 2015-11-12 14:44:19 +0000 | [diff] [blame] | 3793 | linker_patches->push_back(LinkerPatch::DexCacheArrayPatch(info.label.location(), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3794 | &info.target_dex_file, |
Alexandre Rames | 6dc0174 | 2015-11-12 14:44:19 +0000 | [diff] [blame] | 3795 | info.pc_insn_label->location(), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 3796 | info.offset_or_index)); |
| 3797 | } |
| 3798 | for (const auto& entry : boot_image_string_patches_) { |
| 3799 | const StringReference& target_string = entry.first; |
| 3800 | vixl::Literal<uint32_t>* literal = entry.second; |
| 3801 | linker_patches->push_back(LinkerPatch::StringPatch(literal->offset(), |
| 3802 | target_string.dex_file, |
| 3803 | target_string.string_index)); |
| 3804 | } |
| 3805 | for (const PcRelativePatchInfo& info : pc_relative_string_patches_) { |
| 3806 | linker_patches->push_back(LinkerPatch::RelativeStringPatch(info.label.location(), |
| 3807 | &info.target_dex_file, |
| 3808 | info.pc_insn_label->location(), |
| 3809 | info.offset_or_index)); |
| 3810 | } |
| 3811 | for (const auto& entry : boot_image_address_patches_) { |
| 3812 | DCHECK(GetCompilerOptions().GetIncludePatchInformation()); |
| 3813 | vixl::Literal<uint32_t>* literal = entry.second; |
| 3814 | linker_patches->push_back(LinkerPatch::RecordPosition(literal->offset())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3815 | } |
| 3816 | } |
| 3817 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 3818 | vixl::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateUint32Literal(uint32_t value, |
| 3819 | Uint32ToLiteralMap* map) { |
| 3820 | return map->GetOrCreate( |
| 3821 | value, |
| 3822 | [this, value]() { return __ CreateLiteralDestroyedWithPool<uint32_t>(value); }); |
| 3823 | } |
| 3824 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3825 | vixl::Literal<uint64_t>* CodeGeneratorARM64::DeduplicateUint64Literal(uint64_t value) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 3826 | return uint64_literals_.GetOrCreate( |
| 3827 | value, |
| 3828 | [this, value]() { return __ CreateLiteralDestroyedWithPool<uint64_t>(value); }); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3829 | } |
| 3830 | |
| 3831 | vixl::Literal<uint64_t>* CodeGeneratorARM64::DeduplicateMethodLiteral( |
| 3832 | MethodReference target_method, |
| 3833 | MethodToLiteralMap* map) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 3834 | return map->GetOrCreate( |
| 3835 | target_method, |
| 3836 | [this]() { return __ CreateLiteralDestroyedWithPool<uint64_t>(/* placeholder */ 0u); }); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3837 | } |
| 3838 | |
| 3839 | vixl::Literal<uint64_t>* CodeGeneratorARM64::DeduplicateMethodAddressLiteral( |
| 3840 | MethodReference target_method) { |
| 3841 | return DeduplicateMethodLiteral(target_method, &method_patches_); |
| 3842 | } |
| 3843 | |
| 3844 | vixl::Literal<uint64_t>* CodeGeneratorARM64::DeduplicateMethodCodeLiteral( |
| 3845 | MethodReference target_method) { |
| 3846 | return DeduplicateMethodLiteral(target_method, &call_patches_); |
| 3847 | } |
| 3848 | |
| 3849 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 3850 | void InstructionCodeGeneratorARM64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 3851 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 3852 | // art::PrepareForRegisterAllocation. |
| 3853 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3854 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 3855 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 3856 | return; |
| 3857 | } |
| 3858 | |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 3859 | BlockPoolsScope block_pools(GetVIXLAssembler()); |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 3860 | LocationSummary* locations = invoke->GetLocations(); |
| 3861 | codegen_->GenerateStaticOrDirectCall( |
| 3862 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 3863 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3864 | } |
| 3865 | |
| 3866 | void InstructionCodeGeneratorARM64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 3867 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 3868 | return; |
| 3869 | } |
| 3870 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 3871 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3872 | DCHECK(!codegen_->IsLeafMethod()); |
| 3873 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 3874 | } |
| 3875 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3876 | void LocationsBuilderARM64::VisitLoadClass(HLoadClass* cls) { |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 3877 | InvokeRuntimeCallingConvention calling_convention; |
| 3878 | CodeGenerator::CreateLoadClassLocationSummary( |
| 3879 | cls, |
| 3880 | LocationFrom(calling_convention.GetRegisterAt(0)), |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3881 | LocationFrom(vixl::x0), |
| 3882 | /* code_generator_supports_read_barrier */ true); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3883 | } |
| 3884 | |
| 3885 | void InstructionCodeGeneratorARM64::VisitLoadClass(HLoadClass* cls) { |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 3886 | if (cls->NeedsAccessCheck()) { |
| 3887 | codegen_->MoveConstant(cls->GetLocations()->GetTemp(0), cls->GetTypeIndex()); |
| 3888 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pInitializeTypeAndVerifyAccess), |
| 3889 | cls, |
| 3890 | cls->GetDexPc(), |
| 3891 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3892 | CheckEntrypointTypes<kQuickInitializeTypeAndVerifyAccess, void*, uint32_t>(); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 3893 | return; |
| 3894 | } |
| 3895 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3896 | Location out_loc = cls->GetLocations()->Out(); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 3897 | Register out = OutputRegister(cls); |
| 3898 | Register current_method = InputRegisterAt(cls, 0); |
| 3899 | if (cls->IsReferrersClass()) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3900 | DCHECK(!cls->CanCallRuntime()); |
| 3901 | DCHECK(!cls->MustGenerateClinitCheck()); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3902 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 3903 | GenerateGcRootFieldLoad( |
| 3904 | cls, out_loc, current_method, ArtMethod::DeclaringClassOffset().Int32Value()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3905 | } else { |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 3906 | MemberOffset resolved_types_offset = ArtMethod::DexCacheResolvedTypesOffset(kArm64PointerSize); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3907 | // /* GcRoot<mirror::Class>[] */ out = |
| 3908 | // current_method.ptr_sized_fields_->dex_cache_resolved_types_ |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 3909 | __ Ldr(out.X(), MemOperand(current_method, resolved_types_offset.Int32Value())); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3910 | // /* GcRoot<mirror::Class> */ out = out[type_index] |
| 3911 | GenerateGcRootFieldLoad( |
| 3912 | cls, out_loc, out.X(), CodeGenerator::GetCacheOffset(cls->GetTypeIndex())); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3913 | |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 3914 | if (!cls->IsInDexCache() || cls->MustGenerateClinitCheck()) { |
| 3915 | DCHECK(cls->CanCallRuntime()); |
| 3916 | SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM64( |
| 3917 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 3918 | codegen_->AddSlowPath(slow_path); |
| 3919 | if (!cls->IsInDexCache()) { |
| 3920 | __ Cbz(out, slow_path->GetEntryLabel()); |
| 3921 | } |
| 3922 | if (cls->MustGenerateClinitCheck()) { |
| 3923 | GenerateClassInitializationCheck(slow_path, out); |
| 3924 | } else { |
| 3925 | __ Bind(slow_path->GetExitLabel()); |
| 3926 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3927 | } |
| 3928 | } |
| 3929 | } |
| 3930 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 3931 | static MemOperand GetExceptionTlsAddress() { |
| 3932 | return MemOperand(tr, Thread::ExceptionOffset<kArm64WordSize>().Int32Value()); |
| 3933 | } |
| 3934 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3935 | void LocationsBuilderARM64::VisitLoadException(HLoadException* load) { |
| 3936 | LocationSummary* locations = |
| 3937 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 3938 | locations->SetOut(Location::RequiresRegister()); |
| 3939 | } |
| 3940 | |
| 3941 | void InstructionCodeGeneratorARM64::VisitLoadException(HLoadException* instruction) { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 3942 | __ Ldr(OutputRegister(instruction), GetExceptionTlsAddress()); |
| 3943 | } |
| 3944 | |
| 3945 | void LocationsBuilderARM64::VisitClearException(HClearException* clear) { |
| 3946 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 3947 | } |
| 3948 | |
| 3949 | void InstructionCodeGeneratorARM64::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 3950 | __ Str(wzr, GetExceptionTlsAddress()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3951 | } |
| 3952 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 3953 | HLoadString::LoadKind CodeGeneratorARM64::GetSupportedLoadStringKind( |
| 3954 | HLoadString::LoadKind desired_string_load_kind) { |
| 3955 | if (kEmitCompilerReadBarrier) { |
| 3956 | switch (desired_string_load_kind) { |
| 3957 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: |
| 3958 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
| 3959 | case HLoadString::LoadKind::kBootImageAddress: |
| 3960 | // TODO: Implement for read barrier. |
| 3961 | return HLoadString::LoadKind::kDexCacheViaMethod; |
| 3962 | default: |
| 3963 | break; |
| 3964 | } |
| 3965 | } |
| 3966 | switch (desired_string_load_kind) { |
| 3967 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: |
| 3968 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 3969 | break; |
| 3970 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
| 3971 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 3972 | break; |
| 3973 | case HLoadString::LoadKind::kBootImageAddress: |
| 3974 | break; |
| 3975 | case HLoadString::LoadKind::kDexCacheAddress: |
Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 3976 | DCHECK(Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 3977 | break; |
| 3978 | case HLoadString::LoadKind::kDexCachePcRelative: |
Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 3979 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 3980 | break; |
| 3981 | case HLoadString::LoadKind::kDexCacheViaMethod: |
| 3982 | break; |
| 3983 | } |
| 3984 | return desired_string_load_kind; |
| 3985 | } |
| 3986 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3987 | void LocationsBuilderARM64::VisitLoadString(HLoadString* load) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 3988 | LocationSummary::CallKind call_kind = (load->NeedsEnvironment() || kEmitCompilerReadBarrier) |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 3989 | ? LocationSummary::kCallOnSlowPath |
| 3990 | : LocationSummary::kNoCall; |
| 3991 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 3992 | if (load->GetLoadKind() == HLoadString::LoadKind::kDexCacheViaMethod) { |
| 3993 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3994 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3995 | locations->SetOut(Location::RequiresRegister()); |
| 3996 | } |
| 3997 | |
| 3998 | void InstructionCodeGeneratorARM64::VisitLoadString(HLoadString* load) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3999 | Location out_loc = load->GetLocations()->Out(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4000 | Register out = OutputRegister(load); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4001 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4002 | switch (load->GetLoadKind()) { |
| 4003 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: |
| 4004 | DCHECK(!kEmitCompilerReadBarrier); |
| 4005 | __ Ldr(out, codegen_->DeduplicateBootImageStringLiteral(load->GetDexFile(), |
| 4006 | load->GetStringIndex())); |
| 4007 | return; // No dex cache slow path. |
| 4008 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
| 4009 | DCHECK(!kEmitCompilerReadBarrier); |
| 4010 | // Add ADRP with its PC-relative String patch. |
| 4011 | const DexFile& dex_file = load->GetDexFile(); |
| 4012 | uint32_t string_index = load->GetStringIndex(); |
| 4013 | vixl::Label* adrp_label = codegen_->NewPcRelativeStringPatch(dex_file, string_index); |
| 4014 | { |
| 4015 | vixl::SingleEmissionCheckScope guard(GetVIXLAssembler()); |
| 4016 | __ Bind(adrp_label); |
| 4017 | __ adrp(out.X(), /* offset placeholder */ 0); |
| 4018 | } |
| 4019 | // Add ADD with its PC-relative String patch. |
| 4020 | vixl::Label* add_label = |
| 4021 | codegen_->NewPcRelativeStringPatch(dex_file, string_index, adrp_label); |
| 4022 | { |
| 4023 | vixl::SingleEmissionCheckScope guard(GetVIXLAssembler()); |
| 4024 | __ Bind(add_label); |
| 4025 | __ add(out.X(), out.X(), Operand(/* offset placeholder */ 0)); |
| 4026 | } |
| 4027 | return; // No dex cache slow path. |
| 4028 | } |
| 4029 | case HLoadString::LoadKind::kBootImageAddress: { |
| 4030 | DCHECK(!kEmitCompilerReadBarrier); |
| 4031 | DCHECK(load->GetAddress() != 0u && IsUint<32>(load->GetAddress())); |
| 4032 | __ Ldr(out.W(), codegen_->DeduplicateBootImageAddressLiteral(load->GetAddress())); |
| 4033 | return; // No dex cache slow path. |
| 4034 | } |
| 4035 | case HLoadString::LoadKind::kDexCacheAddress: { |
| 4036 | DCHECK_NE(load->GetAddress(), 0u); |
| 4037 | // LDR immediate has a 12-bit offset multiplied by the size and for 32-bit loads |
| 4038 | // that gives a 16KiB range. To try and reduce the number of literals if we load |
| 4039 | // multiple strings, simply split the dex cache address to a 16KiB aligned base |
| 4040 | // loaded from a literal and the remaining offset embedded in the load. |
| 4041 | static_assert(sizeof(GcRoot<mirror::String>) == 4u, "Expected GC root to be 4 bytes."); |
| 4042 | DCHECK_ALIGNED(load->GetAddress(), 4u); |
| 4043 | constexpr size_t offset_bits = /* encoded bits */ 12 + /* scale */ 2; |
| 4044 | uint64_t base_address = load->GetAddress() & ~MaxInt<uint64_t>(offset_bits); |
| 4045 | uint32_t offset = load->GetAddress() & MaxInt<uint64_t>(offset_bits); |
| 4046 | __ Ldr(out.X(), codegen_->DeduplicateDexCacheAddressLiteral(base_address)); |
| 4047 | GenerateGcRootFieldLoad(load, out_loc, out.X(), offset); |
| 4048 | break; |
| 4049 | } |
| 4050 | case HLoadString::LoadKind::kDexCachePcRelative: { |
| 4051 | // Add ADRP with its PC-relative DexCache access patch. |
| 4052 | const DexFile& dex_file = load->GetDexFile(); |
| 4053 | uint32_t element_offset = load->GetDexCacheElementOffset(); |
| 4054 | vixl::Label* adrp_label = codegen_->NewPcRelativeDexCacheArrayPatch(dex_file, element_offset); |
| 4055 | { |
| 4056 | vixl::SingleEmissionCheckScope guard(GetVIXLAssembler()); |
| 4057 | __ Bind(adrp_label); |
| 4058 | __ adrp(out.X(), /* offset placeholder */ 0); |
| 4059 | } |
| 4060 | // Add LDR with its PC-relative DexCache access patch. |
| 4061 | vixl::Label* ldr_label = |
| 4062 | codegen_->NewPcRelativeDexCacheArrayPatch(dex_file, element_offset, adrp_label); |
| 4063 | GenerateGcRootFieldLoad(load, out_loc, out.X(), /* offset placeholder */ 0, ldr_label); |
| 4064 | break; |
| 4065 | } |
| 4066 | case HLoadString::LoadKind::kDexCacheViaMethod: { |
| 4067 | Register current_method = InputRegisterAt(load, 0); |
| 4068 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 4069 | GenerateGcRootFieldLoad( |
| 4070 | load, out_loc, current_method, ArtMethod::DeclaringClassOffset().Int32Value()); |
| 4071 | // /* GcRoot<mirror::String>[] */ out = out->dex_cache_strings_ |
| 4072 | __ Ldr(out.X(), HeapOperand(out, mirror::Class::DexCacheStringsOffset().Uint32Value())); |
| 4073 | // /* GcRoot<mirror::String> */ out = out[string_index] |
| 4074 | GenerateGcRootFieldLoad( |
| 4075 | load, out_loc, out.X(), CodeGenerator::GetCacheOffset(load->GetStringIndex())); |
| 4076 | break; |
| 4077 | } |
| 4078 | default: |
| 4079 | LOG(FATAL) << "Unexpected load kind: " << load->GetLoadKind(); |
| 4080 | UNREACHABLE(); |
| 4081 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4082 | |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 4083 | if (!load->IsInDexCache()) { |
| 4084 | SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathARM64(load); |
| 4085 | codegen_->AddSlowPath(slow_path); |
| 4086 | __ Cbz(out, slow_path->GetEntryLabel()); |
| 4087 | __ Bind(slow_path->GetExitLabel()); |
| 4088 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4089 | } |
| 4090 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4091 | void LocationsBuilderARM64::VisitLongConstant(HLongConstant* constant) { |
| 4092 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant); |
| 4093 | locations->SetOut(Location::ConstantLocation(constant)); |
| 4094 | } |
| 4095 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4096 | void InstructionCodeGeneratorARM64::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4097 | // Will be generated at use site. |
| 4098 | } |
| 4099 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4100 | void LocationsBuilderARM64::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 4101 | LocationSummary* locations = |
| 4102 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 4103 | InvokeRuntimeCallingConvention calling_convention; |
| 4104 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 4105 | } |
| 4106 | |
| 4107 | void InstructionCodeGeneratorARM64::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 4108 | codegen_->InvokeRuntime(instruction->IsEnter() |
| 4109 | ? QUICK_ENTRY_POINT(pLockObject) : QUICK_ENTRY_POINT(pUnlockObject), |
| 4110 | instruction, |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 4111 | instruction->GetDexPc(), |
| 4112 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 4113 | if (instruction->IsEnter()) { |
| 4114 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 4115 | } else { |
| 4116 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 4117 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4118 | } |
| 4119 | |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 4120 | void LocationsBuilderARM64::VisitMul(HMul* mul) { |
| 4121 | LocationSummary* locations = |
| 4122 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 4123 | switch (mul->GetResultType()) { |
| 4124 | case Primitive::kPrimInt: |
| 4125 | case Primitive::kPrimLong: |
| 4126 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4127 | locations->SetInAt(1, Location::RequiresRegister()); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 4128 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 4129 | break; |
| 4130 | |
| 4131 | case Primitive::kPrimFloat: |
| 4132 | case Primitive::kPrimDouble: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 4133 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4134 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4135 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 4136 | break; |
| 4137 | |
| 4138 | default: |
| 4139 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 4140 | } |
| 4141 | } |
| 4142 | |
| 4143 | void InstructionCodeGeneratorARM64::VisitMul(HMul* mul) { |
| 4144 | switch (mul->GetResultType()) { |
| 4145 | case Primitive::kPrimInt: |
| 4146 | case Primitive::kPrimLong: |
| 4147 | __ Mul(OutputRegister(mul), InputRegisterAt(mul, 0), InputRegisterAt(mul, 1)); |
| 4148 | break; |
| 4149 | |
| 4150 | case Primitive::kPrimFloat: |
| 4151 | case Primitive::kPrimDouble: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 4152 | __ Fmul(OutputFPRegister(mul), InputFPRegisterAt(mul, 0), InputFPRegisterAt(mul, 1)); |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 4153 | break; |
| 4154 | |
| 4155 | default: |
| 4156 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 4157 | } |
| 4158 | } |
| 4159 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 4160 | void LocationsBuilderARM64::VisitNeg(HNeg* neg) { |
| 4161 | LocationSummary* locations = |
| 4162 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 4163 | switch (neg->GetResultType()) { |
| 4164 | case Primitive::kPrimInt: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4165 | case Primitive::kPrimLong: |
Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 4166 | locations->SetInAt(0, ARM64EncodableConstantOrRegister(neg->InputAt(0), neg)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4167 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 4168 | break; |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 4169 | |
| 4170 | case Primitive::kPrimFloat: |
| 4171 | case Primitive::kPrimDouble: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4172 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4173 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 4174 | break; |
| 4175 | |
| 4176 | default: |
| 4177 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 4178 | } |
| 4179 | } |
| 4180 | |
| 4181 | void InstructionCodeGeneratorARM64::VisitNeg(HNeg* neg) { |
| 4182 | switch (neg->GetResultType()) { |
| 4183 | case Primitive::kPrimInt: |
| 4184 | case Primitive::kPrimLong: |
| 4185 | __ Neg(OutputRegister(neg), InputOperandAt(neg, 0)); |
| 4186 | break; |
| 4187 | |
| 4188 | case Primitive::kPrimFloat: |
| 4189 | case Primitive::kPrimDouble: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4190 | __ Fneg(OutputFPRegister(neg), InputFPRegisterAt(neg, 0)); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 4191 | break; |
| 4192 | |
| 4193 | default: |
| 4194 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 4195 | } |
| 4196 | } |
| 4197 | |
| 4198 | void LocationsBuilderARM64::VisitNewArray(HNewArray* instruction) { |
| 4199 | LocationSummary* locations = |
| 4200 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 4201 | InvokeRuntimeCallingConvention calling_convention; |
| 4202 | locations->AddTemp(LocationFrom(calling_convention.GetRegisterAt(0))); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 4203 | locations->SetOut(LocationFrom(x0)); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 4204 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 4205 | locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(2))); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 4206 | } |
| 4207 | |
| 4208 | void InstructionCodeGeneratorARM64::VisitNewArray(HNewArray* instruction) { |
| 4209 | LocationSummary* locations = instruction->GetLocations(); |
| 4210 | InvokeRuntimeCallingConvention calling_convention; |
| 4211 | Register type_index = RegisterFrom(locations->GetTemp(0), Primitive::kPrimInt); |
| 4212 | DCHECK(type_index.Is(w0)); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 4213 | __ Mov(type_index, instruction->GetTypeIndex()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4214 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 4215 | // of poisoning the reference. |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4216 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), |
| 4217 | instruction, |
| 4218 | instruction->GetDexPc(), |
| 4219 | nullptr); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4220 | CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck, void*, uint32_t, int32_t, ArtMethod*>(); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 4221 | } |
| 4222 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4223 | void LocationsBuilderARM64::VisitNewInstance(HNewInstance* instruction) { |
| 4224 | LocationSummary* locations = |
| 4225 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 4226 | InvokeRuntimeCallingConvention calling_convention; |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4227 | if (instruction->IsStringAlloc()) { |
| 4228 | locations->AddTemp(LocationFrom(kArtMethodRegister)); |
| 4229 | } else { |
| 4230 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 4231 | locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(1))); |
| 4232 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4233 | locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimNot)); |
| 4234 | } |
| 4235 | |
| 4236 | void InstructionCodeGeneratorARM64::VisitNewInstance(HNewInstance* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4237 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 4238 | // of poisoning the reference. |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4239 | if (instruction->IsStringAlloc()) { |
| 4240 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 4241 | Location temp = instruction->GetLocations()->GetTemp(0); |
| 4242 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64WordSize); |
| 4243 | __ Ldr(XRegisterFrom(temp), MemOperand(tr, QUICK_ENTRY_POINT(pNewEmptyString))); |
| 4244 | __ Ldr(lr, MemOperand(XRegisterFrom(temp), code_offset.Int32Value())); |
| 4245 | __ Blr(lr); |
| 4246 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 4247 | } else { |
| 4248 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), |
| 4249 | instruction, |
| 4250 | instruction->GetDexPc(), |
| 4251 | nullptr); |
| 4252 | CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, ArtMethod*>(); |
| 4253 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4254 | } |
| 4255 | |
| 4256 | void LocationsBuilderARM64::VisitNot(HNot* instruction) { |
| 4257 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Alexandre Rames | 4e59651 | 2014-11-07 15:56:50 +0000 | [diff] [blame] | 4258 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 4259 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4260 | } |
| 4261 | |
| 4262 | void InstructionCodeGeneratorARM64::VisitNot(HNot* instruction) { |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 4263 | switch (instruction->GetResultType()) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4264 | case Primitive::kPrimInt: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4265 | case Primitive::kPrimLong: |
Roland Levillain | 55dcfb5 | 2014-10-24 18:09:09 +0100 | [diff] [blame] | 4266 | __ Mvn(OutputRegister(instruction), InputOperandAt(instruction, 0)); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4267 | break; |
| 4268 | |
| 4269 | default: |
| 4270 | LOG(FATAL) << "Unexpected type for not operation " << instruction->GetResultType(); |
| 4271 | } |
| 4272 | } |
| 4273 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4274 | void LocationsBuilderARM64::VisitBooleanNot(HBooleanNot* instruction) { |
| 4275 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 4276 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4277 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4278 | } |
| 4279 | |
| 4280 | void InstructionCodeGeneratorARM64::VisitBooleanNot(HBooleanNot* instruction) { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4281 | __ Eor(OutputRegister(instruction), InputRegisterAt(instruction, 0), vixl::Operand(1)); |
| 4282 | } |
| 4283 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4284 | void LocationsBuilderARM64::VisitNullCheck(HNullCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4285 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 4286 | ? LocationSummary::kCallOnSlowPath |
| 4287 | : LocationSummary::kNoCall; |
| 4288 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4289 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4290 | if (instruction->HasUses()) { |
| 4291 | locations->SetOut(Location::SameAsFirstInput()); |
| 4292 | } |
| 4293 | } |
| 4294 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4295 | void CodeGeneratorARM64::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 4296 | if (CanMoveNullCheckToUser(instruction)) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4297 | return; |
| 4298 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4299 | |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 4300 | BlockPoolsScope block_pools(GetVIXLAssembler()); |
| 4301 | Location obj = instruction->GetLocations()->InAt(0); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4302 | __ Ldr(wzr, HeapOperandFrom(obj, Offset(0))); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4303 | RecordPcInfo(instruction, instruction->GetDexPc()); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4304 | } |
| 4305 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4306 | void CodeGeneratorARM64::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4307 | SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM64(instruction); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4308 | AddSlowPath(slow_path); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4309 | |
| 4310 | LocationSummary* locations = instruction->GetLocations(); |
| 4311 | Location obj = locations->InAt(0); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4312 | |
| 4313 | __ Cbz(RegisterFrom(obj, instruction->InputAt(0)->GetType()), slow_path->GetEntryLabel()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4314 | } |
| 4315 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4316 | void InstructionCodeGeneratorARM64::VisitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4317 | codegen_->GenerateNullCheck(instruction); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4318 | } |
| 4319 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4320 | void LocationsBuilderARM64::VisitOr(HOr* instruction) { |
| 4321 | HandleBinaryOp(instruction); |
| 4322 | } |
| 4323 | |
| 4324 | void InstructionCodeGeneratorARM64::VisitOr(HOr* instruction) { |
| 4325 | HandleBinaryOp(instruction); |
| 4326 | } |
| 4327 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 4328 | void LocationsBuilderARM64::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
| 4329 | LOG(FATAL) << "Unreachable"; |
| 4330 | } |
| 4331 | |
| 4332 | void InstructionCodeGeneratorARM64::VisitParallelMove(HParallelMove* instruction) { |
| 4333 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 4334 | } |
| 4335 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4336 | void LocationsBuilderARM64::VisitParameterValue(HParameterValue* instruction) { |
| 4337 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 4338 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 4339 | if (location.IsStackSlot()) { |
| 4340 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 4341 | } else if (location.IsDoubleStackSlot()) { |
| 4342 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 4343 | } |
| 4344 | locations->SetOut(location); |
| 4345 | } |
| 4346 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4347 | void InstructionCodeGeneratorARM64::VisitParameterValue( |
| 4348 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4349 | // Nothing to do, the parameter is already at its location. |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4350 | } |
| 4351 | |
| 4352 | void LocationsBuilderARM64::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 4353 | LocationSummary* locations = |
| 4354 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 4355 | locations->SetOut(LocationFrom(kArtMethodRegister)); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4356 | } |
| 4357 | |
| 4358 | void InstructionCodeGeneratorARM64::VisitCurrentMethod( |
| 4359 | HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
| 4360 | // Nothing to do, the method is already at its location. |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4361 | } |
| 4362 | |
| 4363 | void LocationsBuilderARM64::VisitPhi(HPhi* instruction) { |
| 4364 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4365 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4366 | locations->SetInAt(i, Location::Any()); |
| 4367 | } |
| 4368 | locations->SetOut(Location::Any()); |
| 4369 | } |
| 4370 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4371 | void InstructionCodeGeneratorARM64::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4372 | LOG(FATAL) << "Unreachable"; |
| 4373 | } |
| 4374 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4375 | void LocationsBuilderARM64::VisitRem(HRem* rem) { |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 4376 | Primitive::Type type = rem->GetResultType(); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 4377 | LocationSummary::CallKind call_kind = |
| 4378 | Primitive::IsFloatingPointType(type) ? LocationSummary::kCall : LocationSummary::kNoCall; |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 4379 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind); |
| 4380 | |
| 4381 | switch (type) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4382 | case Primitive::kPrimInt: |
| 4383 | case Primitive::kPrimLong: |
| 4384 | locations->SetInAt(0, Location::RequiresRegister()); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 4385 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4386 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4387 | break; |
| 4388 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 4389 | case Primitive::kPrimFloat: |
| 4390 | case Primitive::kPrimDouble: { |
| 4391 | InvokeRuntimeCallingConvention calling_convention; |
| 4392 | locations->SetInAt(0, LocationFrom(calling_convention.GetFpuRegisterAt(0))); |
| 4393 | locations->SetInAt(1, LocationFrom(calling_convention.GetFpuRegisterAt(1))); |
| 4394 | locations->SetOut(calling_convention.GetReturnLocation(type)); |
| 4395 | |
| 4396 | break; |
| 4397 | } |
| 4398 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4399 | default: |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 4400 | LOG(FATAL) << "Unexpected rem type " << type; |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4401 | } |
| 4402 | } |
| 4403 | |
| 4404 | void InstructionCodeGeneratorARM64::VisitRem(HRem* rem) { |
| 4405 | Primitive::Type type = rem->GetResultType(); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 4406 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4407 | switch (type) { |
| 4408 | case Primitive::kPrimInt: |
| 4409 | case Primitive::kPrimLong: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 4410 | GenerateDivRemIntegral(rem); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4411 | break; |
| 4412 | } |
| 4413 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 4414 | case Primitive::kPrimFloat: |
| 4415 | case Primitive::kPrimDouble: { |
| 4416 | int32_t entry_offset = (type == Primitive::kPrimFloat) ? QUICK_ENTRY_POINT(pFmodf) |
| 4417 | : QUICK_ENTRY_POINT(pFmod); |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 4418 | codegen_->InvokeRuntime(entry_offset, rem, rem->GetDexPc(), nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 4419 | if (type == Primitive::kPrimFloat) { |
| 4420 | CheckEntrypointTypes<kQuickFmodf, float, float, float>(); |
| 4421 | } else { |
| 4422 | CheckEntrypointTypes<kQuickFmod, double, double, double>(); |
| 4423 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 4424 | break; |
| 4425 | } |
| 4426 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4427 | default: |
| 4428 | LOG(FATAL) << "Unexpected rem type " << type; |
Vladimir Marko | 351dddf | 2015-12-11 16:34:46 +0000 | [diff] [blame] | 4429 | UNREACHABLE(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4430 | } |
| 4431 | } |
| 4432 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 4433 | void LocationsBuilderARM64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 4434 | memory_barrier->SetLocations(nullptr); |
| 4435 | } |
| 4436 | |
| 4437 | void InstructionCodeGeneratorARM64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 4438 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 4439 | } |
| 4440 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4441 | void LocationsBuilderARM64::VisitReturn(HReturn* instruction) { |
| 4442 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 4443 | Primitive::Type return_type = instruction->InputAt(0)->GetType(); |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 4444 | locations->SetInAt(0, ARM64ReturnLocation(return_type)); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4445 | } |
| 4446 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4447 | void InstructionCodeGeneratorARM64::VisitReturn(HReturn* instruction ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4448 | codegen_->GenerateFrameExit(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4449 | } |
| 4450 | |
| 4451 | void LocationsBuilderARM64::VisitReturnVoid(HReturnVoid* instruction) { |
| 4452 | instruction->SetLocations(nullptr); |
| 4453 | } |
| 4454 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4455 | void InstructionCodeGeneratorARM64::VisitReturnVoid(HReturnVoid* instruction ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4456 | codegen_->GenerateFrameExit(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4457 | } |
| 4458 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4459 | void LocationsBuilderARM64::VisitRor(HRor* ror) { |
| 4460 | HandleBinaryOp(ror); |
| 4461 | } |
| 4462 | |
| 4463 | void InstructionCodeGeneratorARM64::VisitRor(HRor* ror) { |
| 4464 | HandleBinaryOp(ror); |
| 4465 | } |
| 4466 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4467 | void LocationsBuilderARM64::VisitShl(HShl* shl) { |
| 4468 | HandleShift(shl); |
| 4469 | } |
| 4470 | |
| 4471 | void InstructionCodeGeneratorARM64::VisitShl(HShl* shl) { |
| 4472 | HandleShift(shl); |
| 4473 | } |
| 4474 | |
| 4475 | void LocationsBuilderARM64::VisitShr(HShr* shr) { |
| 4476 | HandleShift(shr); |
| 4477 | } |
| 4478 | |
| 4479 | void InstructionCodeGeneratorARM64::VisitShr(HShr* shr) { |
| 4480 | HandleShift(shr); |
| 4481 | } |
| 4482 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4483 | void LocationsBuilderARM64::VisitSub(HSub* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4484 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4485 | } |
| 4486 | |
| 4487 | void InstructionCodeGeneratorARM64::VisitSub(HSub* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4488 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4489 | } |
| 4490 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4491 | void LocationsBuilderARM64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 4492 | HandleFieldGet(instruction); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4493 | } |
| 4494 | |
| 4495 | void InstructionCodeGeneratorARM64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 4496 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4497 | } |
| 4498 | |
| 4499 | void LocationsBuilderARM64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 4500 | HandleFieldSet(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4501 | } |
| 4502 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4503 | void InstructionCodeGeneratorARM64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4504 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4505 | } |
| 4506 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 4507 | void LocationsBuilderARM64::VisitUnresolvedInstanceFieldGet( |
| 4508 | HUnresolvedInstanceFieldGet* instruction) { |
| 4509 | FieldAccessCallingConventionARM64 calling_convention; |
| 4510 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4511 | instruction, instruction->GetFieldType(), calling_convention); |
| 4512 | } |
| 4513 | |
| 4514 | void InstructionCodeGeneratorARM64::VisitUnresolvedInstanceFieldGet( |
| 4515 | HUnresolvedInstanceFieldGet* instruction) { |
| 4516 | FieldAccessCallingConventionARM64 calling_convention; |
| 4517 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4518 | instruction->GetFieldType(), |
| 4519 | instruction->GetFieldIndex(), |
| 4520 | instruction->GetDexPc(), |
| 4521 | calling_convention); |
| 4522 | } |
| 4523 | |
| 4524 | void LocationsBuilderARM64::VisitUnresolvedInstanceFieldSet( |
| 4525 | HUnresolvedInstanceFieldSet* instruction) { |
| 4526 | FieldAccessCallingConventionARM64 calling_convention; |
| 4527 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4528 | instruction, instruction->GetFieldType(), calling_convention); |
| 4529 | } |
| 4530 | |
| 4531 | void InstructionCodeGeneratorARM64::VisitUnresolvedInstanceFieldSet( |
| 4532 | HUnresolvedInstanceFieldSet* instruction) { |
| 4533 | FieldAccessCallingConventionARM64 calling_convention; |
| 4534 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4535 | instruction->GetFieldType(), |
| 4536 | instruction->GetFieldIndex(), |
| 4537 | instruction->GetDexPc(), |
| 4538 | calling_convention); |
| 4539 | } |
| 4540 | |
| 4541 | void LocationsBuilderARM64::VisitUnresolvedStaticFieldGet( |
| 4542 | HUnresolvedStaticFieldGet* instruction) { |
| 4543 | FieldAccessCallingConventionARM64 calling_convention; |
| 4544 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4545 | instruction, instruction->GetFieldType(), calling_convention); |
| 4546 | } |
| 4547 | |
| 4548 | void InstructionCodeGeneratorARM64::VisitUnresolvedStaticFieldGet( |
| 4549 | HUnresolvedStaticFieldGet* instruction) { |
| 4550 | FieldAccessCallingConventionARM64 calling_convention; |
| 4551 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4552 | instruction->GetFieldType(), |
| 4553 | instruction->GetFieldIndex(), |
| 4554 | instruction->GetDexPc(), |
| 4555 | calling_convention); |
| 4556 | } |
| 4557 | |
| 4558 | void LocationsBuilderARM64::VisitUnresolvedStaticFieldSet( |
| 4559 | HUnresolvedStaticFieldSet* instruction) { |
| 4560 | FieldAccessCallingConventionARM64 calling_convention; |
| 4561 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4562 | instruction, instruction->GetFieldType(), calling_convention); |
| 4563 | } |
| 4564 | |
| 4565 | void InstructionCodeGeneratorARM64::VisitUnresolvedStaticFieldSet( |
| 4566 | HUnresolvedStaticFieldSet* instruction) { |
| 4567 | FieldAccessCallingConventionARM64 calling_convention; |
| 4568 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4569 | instruction->GetFieldType(), |
| 4570 | instruction->GetFieldIndex(), |
| 4571 | instruction->GetDexPc(), |
| 4572 | calling_convention); |
| 4573 | } |
| 4574 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4575 | void LocationsBuilderARM64::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 4576 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
| 4577 | } |
| 4578 | |
| 4579 | void InstructionCodeGeneratorARM64::VisitSuspendCheck(HSuspendCheck* instruction) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4580 | HBasicBlock* block = instruction->GetBlock(); |
| 4581 | if (block->GetLoopInformation() != nullptr) { |
| 4582 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 4583 | // The back edge will generate the suspend check. |
| 4584 | return; |
| 4585 | } |
| 4586 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 4587 | // The goto will generate the suspend check. |
| 4588 | return; |
| 4589 | } |
| 4590 | GenerateSuspendCheck(instruction, nullptr); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4591 | } |
| 4592 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4593 | void LocationsBuilderARM64::VisitThrow(HThrow* instruction) { |
| 4594 | LocationSummary* locations = |
| 4595 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 4596 | InvokeRuntimeCallingConvention calling_convention; |
| 4597 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 4598 | } |
| 4599 | |
| 4600 | void InstructionCodeGeneratorARM64::VisitThrow(HThrow* instruction) { |
| 4601 | codegen_->InvokeRuntime( |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 4602 | QUICK_ENTRY_POINT(pDeliverException), instruction, instruction->GetDexPc(), nullptr); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 4603 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4604 | } |
| 4605 | |
| 4606 | void LocationsBuilderARM64::VisitTypeConversion(HTypeConversion* conversion) { |
| 4607 | LocationSummary* locations = |
| 4608 | new (GetGraph()->GetArena()) LocationSummary(conversion, LocationSummary::kNoCall); |
| 4609 | Primitive::Type input_type = conversion->GetInputType(); |
| 4610 | Primitive::Type result_type = conversion->GetResultType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 4611 | DCHECK_NE(input_type, result_type); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4612 | if ((input_type == Primitive::kPrimNot) || (input_type == Primitive::kPrimVoid) || |
| 4613 | (result_type == Primitive::kPrimNot) || (result_type == Primitive::kPrimVoid)) { |
| 4614 | LOG(FATAL) << "Unexpected type conversion from " << input_type << " to " << result_type; |
| 4615 | } |
| 4616 | |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 4617 | if (Primitive::IsFloatingPointType(input_type)) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4618 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4619 | } else { |
| 4620 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4621 | } |
| 4622 | |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 4623 | if (Primitive::IsFloatingPointType(result_type)) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4624 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4625 | } else { |
| 4626 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4627 | } |
| 4628 | } |
| 4629 | |
| 4630 | void InstructionCodeGeneratorARM64::VisitTypeConversion(HTypeConversion* conversion) { |
| 4631 | Primitive::Type result_type = conversion->GetResultType(); |
| 4632 | Primitive::Type input_type = conversion->GetInputType(); |
| 4633 | |
| 4634 | DCHECK_NE(input_type, result_type); |
| 4635 | |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 4636 | if (Primitive::IsIntegralType(result_type) && Primitive::IsIntegralType(input_type)) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4637 | int result_size = Primitive::ComponentSize(result_type); |
| 4638 | int input_size = Primitive::ComponentSize(input_type); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 4639 | int min_size = std::min(result_size, input_size); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4640 | Register output = OutputRegister(conversion); |
| 4641 | Register source = InputRegisterAt(conversion, 0); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 4642 | if (result_type == Primitive::kPrimInt && input_type == Primitive::kPrimLong) { |
Alexandre Rames | 4dff2fd | 2015-08-20 13:36:35 +0100 | [diff] [blame] | 4643 | // 'int' values are used directly as W registers, discarding the top |
| 4644 | // bits, so we don't need to sign-extend and can just perform a move. |
| 4645 | // We do not pass the `kDiscardForSameWReg` argument to force clearing the |
| 4646 | // top 32 bits of the target register. We theoretically could leave those |
| 4647 | // bits unchanged, but we would have to make sure that no code uses a |
| 4648 | // 32bit input value as a 64bit value assuming that the top 32 bits are |
| 4649 | // zero. |
| 4650 | __ Mov(output.W(), source.W()); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 4651 | } else if (result_type == Primitive::kPrimChar || |
| 4652 | (input_type == Primitive::kPrimChar && input_size < result_size)) { |
| 4653 | __ Ubfx(output, |
| 4654 | output.IsX() ? source.X() : source.W(), |
| 4655 | 0, Primitive::ComponentSize(Primitive::kPrimChar) * kBitsPerByte); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4656 | } else { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 4657 | __ Sbfx(output, output.IsX() ? source.X() : source.W(), 0, min_size * kBitsPerByte); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4658 | } |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 4659 | } else if (Primitive::IsFloatingPointType(result_type) && Primitive::IsIntegralType(input_type)) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4660 | __ Scvtf(OutputFPRegister(conversion), InputRegisterAt(conversion, 0)); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 4661 | } else if (Primitive::IsIntegralType(result_type) && Primitive::IsFloatingPointType(input_type)) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4662 | CHECK(result_type == Primitive::kPrimInt || result_type == Primitive::kPrimLong); |
| 4663 | __ Fcvtzs(OutputRegister(conversion), InputFPRegisterAt(conversion, 0)); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 4664 | } else if (Primitive::IsFloatingPointType(result_type) && |
| 4665 | Primitive::IsFloatingPointType(input_type)) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4666 | __ Fcvt(OutputFPRegister(conversion), InputFPRegisterAt(conversion, 0)); |
| 4667 | } else { |
| 4668 | LOG(FATAL) << "Unexpected or unimplemented type conversion from " << input_type |
| 4669 | << " to " << result_type; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4670 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4671 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4672 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4673 | void LocationsBuilderARM64::VisitUShr(HUShr* ushr) { |
| 4674 | HandleShift(ushr); |
| 4675 | } |
| 4676 | |
| 4677 | void InstructionCodeGeneratorARM64::VisitUShr(HUShr* ushr) { |
| 4678 | HandleShift(ushr); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4679 | } |
| 4680 | |
| 4681 | void LocationsBuilderARM64::VisitXor(HXor* instruction) { |
| 4682 | HandleBinaryOp(instruction); |
| 4683 | } |
| 4684 | |
| 4685 | void InstructionCodeGeneratorARM64::VisitXor(HXor* instruction) { |
| 4686 | HandleBinaryOp(instruction); |
| 4687 | } |
| 4688 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4689 | void LocationsBuilderARM64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 4690 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 4691 | LOG(FATAL) << "Unreachable"; |
| 4692 | } |
| 4693 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4694 | void InstructionCodeGeneratorARM64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 4695 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 4696 | LOG(FATAL) << "Unreachable"; |
| 4697 | } |
| 4698 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 4699 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 4700 | void LocationsBuilderARM64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 4701 | LocationSummary* locations = |
| 4702 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 4703 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4704 | } |
| 4705 | |
| 4706 | void InstructionCodeGeneratorARM64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 4707 | int32_t lower_bound = switch_instr->GetStartValue(); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 4708 | uint32_t num_entries = switch_instr->GetNumEntries(); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 4709 | Register value_reg = InputRegisterAt(switch_instr, 0); |
| 4710 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 4711 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 4712 | // Roughly set 16 as max average assemblies generated per HIR in a graph. |
| 4713 | static constexpr int32_t kMaxExpectedSizePerHInstruction = 16 * vixl::kInstructionSize; |
| 4714 | // ADR has a limited range(+/-1MB), so we set a threshold for the number of HIRs in the graph to |
| 4715 | // make sure we don't emit it if the target may run out of range. |
| 4716 | // TODO: Instead of emitting all jump tables at the end of the code, we could keep track of ADR |
| 4717 | // ranges and emit the tables only as required. |
| 4718 | static constexpr int32_t kJumpTableInstructionThreshold = 1* MB / kMaxExpectedSizePerHInstruction; |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 4719 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 4720 | if (num_entries <= kPackedSwitchCompareJumpThreshold || |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 4721 | // Current instruction id is an upper bound of the number of HIRs in the graph. |
| 4722 | GetGraph()->GetCurrentInstructionId() > kJumpTableInstructionThreshold) { |
| 4723 | // Create a series of compare/jumps. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 4724 | UseScratchRegisterScope temps(codegen_->GetVIXLAssembler()); |
| 4725 | Register temp = temps.AcquireW(); |
| 4726 | __ Subs(temp, value_reg, Operand(lower_bound)); |
| 4727 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 4728 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 4729 | // Jump to successors[0] if value == lower_bound. |
| 4730 | __ B(eq, codegen_->GetLabelOf(successors[0])); |
| 4731 | int32_t last_index = 0; |
| 4732 | for (; num_entries - last_index > 2; last_index += 2) { |
| 4733 | __ Subs(temp, temp, Operand(2)); |
| 4734 | // Jump to successors[last_index + 1] if value < case_value[last_index + 2]. |
| 4735 | __ B(lo, codegen_->GetLabelOf(successors[last_index + 1])); |
| 4736 | // Jump to successors[last_index + 2] if value == case_value[last_index + 2]. |
| 4737 | __ B(eq, codegen_->GetLabelOf(successors[last_index + 2])); |
| 4738 | } |
| 4739 | if (num_entries - last_index == 2) { |
| 4740 | // The last missing case_value. |
| 4741 | __ Cmp(temp, Operand(1)); |
| 4742 | __ B(eq, codegen_->GetLabelOf(successors[last_index + 1])); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 4743 | } |
| 4744 | |
| 4745 | // And the default for any other value. |
| 4746 | if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) { |
| 4747 | __ B(codegen_->GetLabelOf(default_block)); |
| 4748 | } |
| 4749 | } else { |
Alexandre Rames | c01a664 | 2016-04-15 11:54:06 +0100 | [diff] [blame] | 4750 | JumpTableARM64* jump_table = codegen_->CreateJumpTable(switch_instr); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 4751 | |
| 4752 | UseScratchRegisterScope temps(codegen_->GetVIXLAssembler()); |
| 4753 | |
| 4754 | // Below instructions should use at most one blocked register. Since there are two blocked |
| 4755 | // registers, we are free to block one. |
| 4756 | Register temp_w = temps.AcquireW(); |
| 4757 | Register index; |
| 4758 | // Remove the bias. |
| 4759 | if (lower_bound != 0) { |
| 4760 | index = temp_w; |
| 4761 | __ Sub(index, value_reg, Operand(lower_bound)); |
| 4762 | } else { |
| 4763 | index = value_reg; |
| 4764 | } |
| 4765 | |
| 4766 | // Jump to default block if index is out of the range. |
| 4767 | __ Cmp(index, Operand(num_entries)); |
| 4768 | __ B(hs, codegen_->GetLabelOf(default_block)); |
| 4769 | |
| 4770 | // In current VIXL implementation, it won't require any blocked registers to encode the |
| 4771 | // immediate value for Adr. So we are free to use both VIXL blocked registers to reduce the |
| 4772 | // register pressure. |
| 4773 | Register table_base = temps.AcquireX(); |
| 4774 | // Load jump offset from the table. |
| 4775 | __ Adr(table_base, jump_table->GetTableStartLabel()); |
| 4776 | Register jump_offset = temp_w; |
| 4777 | __ Ldr(jump_offset, MemOperand(table_base, index, UXTW, 2)); |
| 4778 | |
| 4779 | // Jump to target block by branching to table_base(pc related) + offset. |
| 4780 | Register target_address = table_base; |
| 4781 | __ Add(target_address, table_base, Operand(jump_offset, SXTW)); |
| 4782 | __ Br(target_address); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 4783 | } |
| 4784 | } |
| 4785 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 4786 | void InstructionCodeGeneratorARM64::GenerateReferenceLoadOneRegister(HInstruction* instruction, |
| 4787 | Location out, |
| 4788 | uint32_t offset, |
| 4789 | Location maybe_temp) { |
| 4790 | Primitive::Type type = Primitive::kPrimNot; |
| 4791 | Register out_reg = RegisterFrom(out, type); |
| 4792 | if (kEmitCompilerReadBarrier) { |
| 4793 | Register temp_reg = RegisterFrom(maybe_temp, type); |
| 4794 | if (kUseBakerReadBarrier) { |
| 4795 | // Load with fast path based Baker's read barrier. |
| 4796 | // /* HeapReference<Object> */ out = *(out + offset) |
| 4797 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 4798 | out, |
| 4799 | out_reg, |
| 4800 | offset, |
| 4801 | temp_reg, |
| 4802 | /* needs_null_check */ false, |
| 4803 | /* use_load_acquire */ false); |
| 4804 | } else { |
| 4805 | // Load with slow path based read barrier. |
| 4806 | // Save the value of `out` into `maybe_temp` before overwriting it |
| 4807 | // in the following move operation, as we will need it for the |
| 4808 | // read barrier below. |
| 4809 | __ Mov(temp_reg, out_reg); |
| 4810 | // /* HeapReference<Object> */ out = *(out + offset) |
| 4811 | __ Ldr(out_reg, HeapOperand(out_reg, offset)); |
| 4812 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
| 4813 | } |
| 4814 | } else { |
| 4815 | // Plain load with no read barrier. |
| 4816 | // /* HeapReference<Object> */ out = *(out + offset) |
| 4817 | __ Ldr(out_reg, HeapOperand(out_reg, offset)); |
| 4818 | GetAssembler()->MaybeUnpoisonHeapReference(out_reg); |
| 4819 | } |
| 4820 | } |
| 4821 | |
| 4822 | void InstructionCodeGeneratorARM64::GenerateReferenceLoadTwoRegisters(HInstruction* instruction, |
| 4823 | Location out, |
| 4824 | Location obj, |
| 4825 | uint32_t offset, |
| 4826 | Location maybe_temp) { |
| 4827 | Primitive::Type type = Primitive::kPrimNot; |
| 4828 | Register out_reg = RegisterFrom(out, type); |
| 4829 | Register obj_reg = RegisterFrom(obj, type); |
| 4830 | if (kEmitCompilerReadBarrier) { |
| 4831 | if (kUseBakerReadBarrier) { |
| 4832 | // Load with fast path based Baker's read barrier. |
| 4833 | Register temp_reg = RegisterFrom(maybe_temp, type); |
| 4834 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 4835 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 4836 | out, |
| 4837 | obj_reg, |
| 4838 | offset, |
| 4839 | temp_reg, |
| 4840 | /* needs_null_check */ false, |
| 4841 | /* use_load_acquire */ false); |
| 4842 | } else { |
| 4843 | // Load with slow path based read barrier. |
| 4844 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 4845 | __ Ldr(out_reg, HeapOperand(obj_reg, offset)); |
| 4846 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 4847 | } |
| 4848 | } else { |
| 4849 | // Plain load with no read barrier. |
| 4850 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 4851 | __ Ldr(out_reg, HeapOperand(obj_reg, offset)); |
| 4852 | GetAssembler()->MaybeUnpoisonHeapReference(out_reg); |
| 4853 | } |
| 4854 | } |
| 4855 | |
| 4856 | void InstructionCodeGeneratorARM64::GenerateGcRootFieldLoad(HInstruction* instruction, |
| 4857 | Location root, |
| 4858 | vixl::Register obj, |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4859 | uint32_t offset, |
| 4860 | vixl::Label* fixup_label) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 4861 | Register root_reg = RegisterFrom(root, Primitive::kPrimNot); |
| 4862 | if (kEmitCompilerReadBarrier) { |
| 4863 | if (kUseBakerReadBarrier) { |
| 4864 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
| 4865 | // Baker's read barrier are used: |
| 4866 | // |
| 4867 | // root = obj.field; |
| 4868 | // if (Thread::Current()->GetIsGcMarking()) { |
| 4869 | // root = ReadBarrier::Mark(root) |
| 4870 | // } |
| 4871 | |
| 4872 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4873 | if (fixup_label == nullptr) { |
| 4874 | __ Ldr(root_reg, MemOperand(obj, offset)); |
| 4875 | } else { |
| 4876 | vixl::SingleEmissionCheckScope guard(GetVIXLAssembler()); |
| 4877 | __ Bind(fixup_label); |
| 4878 | __ ldr(root_reg, MemOperand(obj, offset)); |
| 4879 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 4880 | static_assert( |
| 4881 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 4882 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 4883 | "have different sizes."); |
| 4884 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 4885 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 4886 | "have different sizes."); |
| 4887 | |
| 4888 | // Slow path used to mark the GC root `root`. |
| 4889 | SlowPathCodeARM64* slow_path = |
| 4890 | new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathARM64(instruction, root, root); |
| 4891 | codegen_->AddSlowPath(slow_path); |
| 4892 | |
| 4893 | MacroAssembler* masm = GetVIXLAssembler(); |
| 4894 | UseScratchRegisterScope temps(masm); |
| 4895 | Register temp = temps.AcquireW(); |
| 4896 | // temp = Thread::Current()->GetIsGcMarking() |
| 4897 | __ Ldr(temp, MemOperand(tr, Thread::IsGcMarkingOffset<kArm64WordSize>().Int32Value())); |
| 4898 | __ Cbnz(temp, slow_path->GetEntryLabel()); |
| 4899 | __ Bind(slow_path->GetExitLabel()); |
| 4900 | } else { |
| 4901 | // GC root loaded through a slow path for read barriers other |
| 4902 | // than Baker's. |
| 4903 | // /* GcRoot<mirror::Object>* */ root = obj + offset |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4904 | if (fixup_label == nullptr) { |
| 4905 | __ Add(root_reg.X(), obj.X(), offset); |
| 4906 | } else { |
| 4907 | vixl::SingleEmissionCheckScope guard(GetVIXLAssembler()); |
| 4908 | __ Bind(fixup_label); |
| 4909 | __ add(root_reg.X(), obj.X(), offset); |
| 4910 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 4911 | // /* mirror::Object* */ root = root->Read() |
| 4912 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 4913 | } |
| 4914 | } else { |
| 4915 | // Plain GC root load with no read barrier. |
| 4916 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4917 | if (fixup_label == nullptr) { |
| 4918 | __ Ldr(root_reg, MemOperand(obj, offset)); |
| 4919 | } else { |
| 4920 | vixl::SingleEmissionCheckScope guard(GetVIXLAssembler()); |
| 4921 | __ Bind(fixup_label); |
| 4922 | __ ldr(root_reg, MemOperand(obj, offset)); |
| 4923 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 4924 | // Note that GC roots are not affected by heap poisoning, thus we |
| 4925 | // do not have to unpoison `root_reg` here. |
| 4926 | } |
| 4927 | } |
| 4928 | |
| 4929 | void CodeGeneratorARM64::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 4930 | Location ref, |
| 4931 | vixl::Register obj, |
| 4932 | uint32_t offset, |
| 4933 | Register temp, |
| 4934 | bool needs_null_check, |
| 4935 | bool use_load_acquire) { |
| 4936 | DCHECK(kEmitCompilerReadBarrier); |
| 4937 | DCHECK(kUseBakerReadBarrier); |
| 4938 | |
| 4939 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 4940 | Location no_index = Location::NoLocation(); |
| 4941 | GenerateReferenceLoadWithBakerReadBarrier( |
| 4942 | instruction, ref, obj, offset, no_index, temp, needs_null_check, use_load_acquire); |
| 4943 | } |
| 4944 | |
| 4945 | void CodeGeneratorARM64::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 4946 | Location ref, |
| 4947 | vixl::Register obj, |
| 4948 | uint32_t data_offset, |
| 4949 | Location index, |
| 4950 | Register temp, |
| 4951 | bool needs_null_check) { |
| 4952 | DCHECK(kEmitCompilerReadBarrier); |
| 4953 | DCHECK(kUseBakerReadBarrier); |
| 4954 | |
| 4955 | // Array cells are never volatile variables, therefore array loads |
| 4956 | // never use Load-Acquire instructions on ARM64. |
| 4957 | const bool use_load_acquire = false; |
| 4958 | |
| 4959 | // /* HeapReference<Object> */ ref = |
| 4960 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 4961 | GenerateReferenceLoadWithBakerReadBarrier( |
| 4962 | instruction, ref, obj, data_offset, index, temp, needs_null_check, use_load_acquire); |
| 4963 | } |
| 4964 | |
| 4965 | void CodeGeneratorARM64::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 4966 | Location ref, |
| 4967 | vixl::Register obj, |
| 4968 | uint32_t offset, |
| 4969 | Location index, |
| 4970 | Register temp, |
| 4971 | bool needs_null_check, |
| 4972 | bool use_load_acquire) { |
| 4973 | DCHECK(kEmitCompilerReadBarrier); |
| 4974 | DCHECK(kUseBakerReadBarrier); |
| 4975 | // If `index` is a valid location, then we are emitting an array |
| 4976 | // load, so we shouldn't be using a Load Acquire instruction. |
| 4977 | // In other words: `index.IsValid()` => `!use_load_acquire`. |
| 4978 | DCHECK(!index.IsValid() || !use_load_acquire); |
| 4979 | |
| 4980 | MacroAssembler* masm = GetVIXLAssembler(); |
| 4981 | UseScratchRegisterScope temps(masm); |
| 4982 | |
| 4983 | // In slow path based read barriers, the read barrier call is |
| 4984 | // inserted after the original load. However, in fast path based |
| 4985 | // Baker's read barriers, we need to perform the load of |
| 4986 | // mirror::Object::monitor_ *before* the original reference load. |
| 4987 | // This load-load ordering is required by the read barrier. |
| 4988 | // The fast path/slow path (for Baker's algorithm) should look like: |
| 4989 | // |
| 4990 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 4991 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 4992 | // HeapReference<Object> ref = *src; // Original reference load. |
| 4993 | // bool is_gray = (rb_state == ReadBarrier::gray_ptr_); |
| 4994 | // if (is_gray) { |
| 4995 | // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path. |
| 4996 | // } |
| 4997 | // |
| 4998 | // Note: the original implementation in ReadBarrier::Barrier is |
| 4999 | // slightly more complex as it performs additional checks that we do |
| 5000 | // not do here for performance reasons. |
| 5001 | |
| 5002 | Primitive::Type type = Primitive::kPrimNot; |
| 5003 | Register ref_reg = RegisterFrom(ref, type); |
| 5004 | DCHECK(obj.IsW()); |
| 5005 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 5006 | |
| 5007 | // /* int32_t */ monitor = obj->monitor_ |
| 5008 | __ Ldr(temp, HeapOperand(obj, monitor_offset)); |
| 5009 | if (needs_null_check) { |
| 5010 | MaybeRecordImplicitNullCheck(instruction); |
| 5011 | } |
| 5012 | // /* LockWord */ lock_word = LockWord(monitor) |
| 5013 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 5014 | "art::LockWord and int32_t have different sizes."); |
| 5015 | // /* uint32_t */ rb_state = lock_word.ReadBarrierState() |
| 5016 | __ Lsr(temp, temp, LockWord::kReadBarrierStateShift); |
| 5017 | __ And(temp, temp, Operand(LockWord::kReadBarrierStateMask)); |
| 5018 | static_assert( |
| 5019 | LockWord::kReadBarrierStateMask == ReadBarrier::rb_ptr_mask_, |
| 5020 | "art::LockWord::kReadBarrierStateMask is not equal to art::ReadBarrier::rb_ptr_mask_."); |
| 5021 | |
| 5022 | // Introduce a dependency on the high bits of rb_state, which shall |
| 5023 | // be all zeroes, to prevent load-load reordering, and without using |
| 5024 | // a memory barrier (which would be more expensive). |
| 5025 | // temp2 = rb_state & ~LockWord::kReadBarrierStateMask = 0 |
| 5026 | Register temp2 = temps.AcquireW(); |
| 5027 | __ Bic(temp2, temp, Operand(LockWord::kReadBarrierStateMask)); |
| 5028 | // obj is unchanged by this operation, but its value now depends on |
| 5029 | // temp2, which depends on temp. |
| 5030 | __ Add(obj, obj, Operand(temp2)); |
| 5031 | temps.Release(temp2); |
| 5032 | |
| 5033 | // The actual reference load. |
| 5034 | if (index.IsValid()) { |
| 5035 | static_assert( |
| 5036 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 5037 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5038 | // /* HeapReference<Object> */ ref = |
| 5039 | // *(obj + offset + index * sizeof(HeapReference<Object>)) |
Roland Levillain | ca0bf03 | 2016-02-09 12:49:18 +0000 | [diff] [blame] | 5040 | const size_t shift_amount = Primitive::ComponentSizeShift(type); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5041 | if (index.IsConstant()) { |
Roland Levillain | ca0bf03 | 2016-02-09 12:49:18 +0000 | [diff] [blame] | 5042 | uint32_t computed_offset = offset + (Int64ConstantFrom(index) << shift_amount); |
| 5043 | Load(type, ref_reg, HeapOperand(obj, computed_offset)); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5044 | } else { |
Roland Levillain | ca0bf03 | 2016-02-09 12:49:18 +0000 | [diff] [blame] | 5045 | temp2 = temps.AcquireW(); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5046 | __ Add(temp2, obj, offset); |
Roland Levillain | ca0bf03 | 2016-02-09 12:49:18 +0000 | [diff] [blame] | 5047 | Load(type, ref_reg, HeapOperand(temp2, XRegisterFrom(index), LSL, shift_amount)); |
| 5048 | temps.Release(temp2); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5049 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5050 | } else { |
| 5051 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 5052 | MemOperand field = HeapOperand(obj, offset); |
| 5053 | if (use_load_acquire) { |
| 5054 | LoadAcquire(instruction, ref_reg, field, /* needs_null_check */ false); |
| 5055 | } else { |
| 5056 | Load(type, ref_reg, field); |
| 5057 | } |
| 5058 | } |
| 5059 | |
| 5060 | // Object* ref = ref_addr->AsMirrorPtr() |
| 5061 | GetAssembler()->MaybeUnpoisonHeapReference(ref_reg); |
| 5062 | |
| 5063 | // Slow path used to mark the object `ref` when it is gray. |
| 5064 | SlowPathCodeARM64* slow_path = |
| 5065 | new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathARM64(instruction, ref, ref); |
| 5066 | AddSlowPath(slow_path); |
| 5067 | |
| 5068 | // if (rb_state == ReadBarrier::gray_ptr_) |
| 5069 | // ref = ReadBarrier::Mark(ref); |
| 5070 | __ Cmp(temp, ReadBarrier::gray_ptr_); |
| 5071 | __ B(eq, slow_path->GetEntryLabel()); |
| 5072 | __ Bind(slow_path->GetExitLabel()); |
| 5073 | } |
| 5074 | |
| 5075 | void CodeGeneratorARM64::GenerateReadBarrierSlow(HInstruction* instruction, |
| 5076 | Location out, |
| 5077 | Location ref, |
| 5078 | Location obj, |
| 5079 | uint32_t offset, |
| 5080 | Location index) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5081 | DCHECK(kEmitCompilerReadBarrier); |
| 5082 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5083 | // Insert a slow path based read barrier *after* the reference load. |
| 5084 | // |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5085 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 5086 | // reference will be carried out by the runtime within the slow |
| 5087 | // path. |
| 5088 | // |
| 5089 | // Note that `ref` currently does not get unpoisoned (when heap |
| 5090 | // poisoning is enabled), which is alright as the `ref` argument is |
| 5091 | // not used by the artReadBarrierSlow entry point. |
| 5092 | // |
| 5093 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
| 5094 | SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) |
| 5095 | ReadBarrierForHeapReferenceSlowPathARM64(instruction, out, ref, obj, offset, index); |
| 5096 | AddSlowPath(slow_path); |
| 5097 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5098 | __ B(slow_path->GetEntryLabel()); |
| 5099 | __ Bind(slow_path->GetExitLabel()); |
| 5100 | } |
| 5101 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5102 | void CodeGeneratorARM64::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 5103 | Location out, |
| 5104 | Location ref, |
| 5105 | Location obj, |
| 5106 | uint32_t offset, |
| 5107 | Location index) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5108 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5109 | // Baker's read barriers shall be handled by the fast path |
| 5110 | // (CodeGeneratorARM64::GenerateReferenceLoadWithBakerReadBarrier). |
| 5111 | DCHECK(!kUseBakerReadBarrier); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5112 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 5113 | // by the runtime within the slow path. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5114 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5115 | } else if (kPoisonHeapReferences) { |
| 5116 | GetAssembler()->UnpoisonHeapReference(WRegisterFrom(out)); |
| 5117 | } |
| 5118 | } |
| 5119 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5120 | void CodeGeneratorARM64::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 5121 | Location out, |
| 5122 | Location root) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5123 | DCHECK(kEmitCompilerReadBarrier); |
| 5124 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5125 | // Insert a slow path based read barrier *after* the GC root load. |
| 5126 | // |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5127 | // Note that GC roots are not affected by heap poisoning, so we do |
| 5128 | // not need to do anything special for this here. |
| 5129 | SlowPathCodeARM64* slow_path = |
| 5130 | new (GetGraph()->GetArena()) ReadBarrierForRootSlowPathARM64(instruction, out, root); |
| 5131 | AddSlowPath(slow_path); |
| 5132 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5133 | __ B(slow_path->GetEntryLabel()); |
| 5134 | __ Bind(slow_path->GetExitLabel()); |
| 5135 | } |
| 5136 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 5137 | void LocationsBuilderARM64::VisitClassTableGet(HClassTableGet* instruction) { |
| 5138 | LocationSummary* locations = |
| 5139 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 5140 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5141 | locations->SetOut(Location::RequiresRegister()); |
| 5142 | } |
| 5143 | |
| 5144 | void InstructionCodeGeneratorARM64::VisitClassTableGet(HClassTableGet* instruction) { |
| 5145 | LocationSummary* locations = instruction->GetLocations(); |
| 5146 | uint32_t method_offset = 0; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5147 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 5148 | method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 5149 | instruction->GetIndex(), kArm64PointerSize).SizeValue(); |
| 5150 | } else { |
| 5151 | method_offset = mirror::Class::EmbeddedImTableEntryOffset( |
| 5152 | instruction->GetIndex() % mirror::Class::kImtSize, kArm64PointerSize).Uint32Value(); |
| 5153 | } |
| 5154 | __ Ldr(XRegisterFrom(locations->Out()), |
| 5155 | MemOperand(XRegisterFrom(locations->InAt(0)), method_offset)); |
| 5156 | } |
| 5157 | |
| 5158 | |
| 5159 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5160 | #undef __ |
| 5161 | #undef QUICK_ENTRY_POINT |
| 5162 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5163 | } // namespace arm64 |
| 5164 | } // namespace art |