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 | |
| 45 | namespace arm64 { |
| 46 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 47 | using helpers::CPURegisterFrom; |
| 48 | using helpers::DRegisterFrom; |
| 49 | using helpers::FPRegisterFrom; |
| 50 | using helpers::HeapOperand; |
| 51 | using helpers::HeapOperandFrom; |
| 52 | using helpers::InputCPURegisterAt; |
| 53 | using helpers::InputFPRegisterAt; |
| 54 | using helpers::InputRegisterAt; |
| 55 | using helpers::InputOperandAt; |
| 56 | using helpers::Int64ConstantFrom; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 57 | using helpers::LocationFrom; |
| 58 | using helpers::OperandFromMemOperand; |
| 59 | using helpers::OutputCPURegister; |
| 60 | using helpers::OutputFPRegister; |
| 61 | using helpers::OutputRegister; |
| 62 | using helpers::RegisterFrom; |
| 63 | using helpers::StackOperandFrom; |
| 64 | using helpers::VIXLRegCodeFromART; |
| 65 | using helpers::WRegisterFrom; |
| 66 | using helpers::XRegisterFrom; |
Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 67 | using helpers::ARM64EncodableConstantOrRegister; |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 68 | using helpers::ArtVixlRegCodeCoherentForRegSet; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 69 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 70 | static constexpr int kCurrentMethodStackOffset = 0; |
| 71 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 72 | inline Condition ARM64Condition(IfCondition cond) { |
| 73 | switch (cond) { |
| 74 | case kCondEQ: return eq; |
| 75 | case kCondNE: return ne; |
| 76 | case kCondLT: return lt; |
| 77 | case kCondLE: return le; |
| 78 | case kCondGT: return gt; |
| 79 | case kCondGE: return ge; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 80 | case kCondB: return lo; |
| 81 | case kCondBE: return ls; |
| 82 | case kCondA: return hi; |
| 83 | case kCondAE: return hs; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 84 | } |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 85 | LOG(FATAL) << "Unreachable"; |
| 86 | UNREACHABLE(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 87 | } |
| 88 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 89 | Location ARM64ReturnLocation(Primitive::Type return_type) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 90 | // Note that in practice, `LocationFrom(x0)` and `LocationFrom(w0)` create the |
| 91 | // same Location object, and so do `LocationFrom(d0)` and `LocationFrom(s0)`, |
| 92 | // but we use the exact registers for clarity. |
| 93 | if (return_type == Primitive::kPrimFloat) { |
| 94 | return LocationFrom(s0); |
| 95 | } else if (return_type == Primitive::kPrimDouble) { |
| 96 | return LocationFrom(d0); |
| 97 | } else if (return_type == Primitive::kPrimLong) { |
| 98 | return LocationFrom(x0); |
Nicolas Geoffray | 925e562 | 2015-06-03 12:23:32 +0100 | [diff] [blame] | 99 | } else if (return_type == Primitive::kPrimVoid) { |
| 100 | return Location::NoLocation(); |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 101 | } else { |
| 102 | return LocationFrom(w0); |
| 103 | } |
| 104 | } |
| 105 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 106 | Location InvokeRuntimeCallingConvention::GetReturnLocation(Primitive::Type return_type) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 107 | return ARM64ReturnLocation(return_type); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 108 | } |
| 109 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 110 | #define __ down_cast<CodeGeneratorARM64*>(codegen)->GetVIXLAssembler()-> |
| 111 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kArm64WordSize, x).Int32Value() |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 112 | |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 113 | // Calculate memory accessing operand for save/restore live registers. |
| 114 | static void SaveRestoreLiveRegistersHelper(CodeGenerator* codegen, |
| 115 | RegisterSet* register_set, |
| 116 | int64_t spill_offset, |
| 117 | bool is_save) { |
| 118 | DCHECK(ArtVixlRegCodeCoherentForRegSet(register_set->GetCoreRegisters(), |
| 119 | codegen->GetNumberOfCoreRegisters(), |
| 120 | register_set->GetFloatingPointRegisters(), |
| 121 | codegen->GetNumberOfFloatingPointRegisters())); |
| 122 | |
| 123 | CPURegList core_list = CPURegList(CPURegister::kRegister, kXRegSize, |
| 124 | register_set->GetCoreRegisters() & (~callee_saved_core_registers.list())); |
Nicolas Geoffray | 75d5b9b | 2015-10-05 07:40:35 +0000 | [diff] [blame] | 125 | CPURegList fp_list = CPURegList(CPURegister::kFPRegister, kDRegSize, |
| 126 | register_set->GetFloatingPointRegisters() & (~callee_saved_fp_registers.list())); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 127 | |
| 128 | MacroAssembler* masm = down_cast<CodeGeneratorARM64*>(codegen)->GetVIXLAssembler(); |
| 129 | UseScratchRegisterScope temps(masm); |
| 130 | |
| 131 | Register base = masm->StackPointer(); |
| 132 | int64_t core_spill_size = core_list.TotalSizeInBytes(); |
| 133 | int64_t fp_spill_size = fp_list.TotalSizeInBytes(); |
| 134 | int64_t reg_size = kXRegSizeInBytes; |
| 135 | int64_t max_ls_pair_offset = spill_offset + core_spill_size + fp_spill_size - 2 * reg_size; |
| 136 | uint32_t ls_access_size = WhichPowerOf2(reg_size); |
| 137 | if (((core_list.Count() > 1) || (fp_list.Count() > 1)) && |
| 138 | !masm->IsImmLSPair(max_ls_pair_offset, ls_access_size)) { |
| 139 | // If the offset does not fit in the instruction's immediate field, use an alternate register |
| 140 | // to compute the base address(float point registers spill base address). |
| 141 | Register new_base = temps.AcquireSameSizeAs(base); |
| 142 | __ Add(new_base, base, Operand(spill_offset + core_spill_size)); |
| 143 | base = new_base; |
| 144 | spill_offset = -core_spill_size; |
| 145 | int64_t new_max_ls_pair_offset = fp_spill_size - 2 * reg_size; |
| 146 | DCHECK(masm->IsImmLSPair(spill_offset, ls_access_size)); |
| 147 | DCHECK(masm->IsImmLSPair(new_max_ls_pair_offset, ls_access_size)); |
| 148 | } |
| 149 | |
| 150 | if (is_save) { |
| 151 | __ StoreCPURegList(core_list, MemOperand(base, spill_offset)); |
| 152 | __ StoreCPURegList(fp_list, MemOperand(base, spill_offset + core_spill_size)); |
| 153 | } else { |
| 154 | __ LoadCPURegList(core_list, MemOperand(base, spill_offset)); |
| 155 | __ LoadCPURegList(fp_list, MemOperand(base, spill_offset + core_spill_size)); |
| 156 | } |
| 157 | } |
| 158 | |
| 159 | void SlowPathCodeARM64::SaveLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) { |
| 160 | RegisterSet* register_set = locations->GetLiveRegisters(); |
| 161 | size_t stack_offset = codegen->GetFirstRegisterSlotInSlowPath(); |
| 162 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 163 | if (!codegen->IsCoreCalleeSaveRegister(i) && register_set->ContainsCoreRegister(i)) { |
| 164 | // If the register holds an object, update the stack mask. |
| 165 | if (locations->RegisterContainsObject(i)) { |
| 166 | locations->SetStackBit(stack_offset / kVRegSize); |
| 167 | } |
| 168 | DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 169 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 170 | saved_core_stack_offsets_[i] = stack_offset; |
| 171 | stack_offset += kXRegSizeInBytes; |
| 172 | } |
| 173 | } |
| 174 | |
| 175 | for (size_t i = 0, e = codegen->GetNumberOfFloatingPointRegisters(); i < e; ++i) { |
| 176 | if (!codegen->IsFloatingPointCalleeSaveRegister(i) && |
| 177 | register_set->ContainsFloatingPointRegister(i)) { |
| 178 | DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 179 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 180 | saved_fpu_stack_offsets_[i] = stack_offset; |
| 181 | stack_offset += kDRegSizeInBytes; |
| 182 | } |
| 183 | } |
| 184 | |
| 185 | SaveRestoreLiveRegistersHelper(codegen, register_set, |
| 186 | codegen->GetFirstRegisterSlotInSlowPath(), true /* is_save */); |
| 187 | } |
| 188 | |
| 189 | void SlowPathCodeARM64::RestoreLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) { |
| 190 | RegisterSet* register_set = locations->GetLiveRegisters(); |
| 191 | SaveRestoreLiveRegistersHelper(codegen, register_set, |
| 192 | codegen->GetFirstRegisterSlotInSlowPath(), false /* is_save */); |
| 193 | } |
| 194 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 195 | class BoundsCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 196 | public: |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 197 | explicit BoundsCheckSlowPathARM64(HBoundsCheck* instruction) : instruction_(instruction) {} |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 198 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 199 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 200 | LocationSummary* locations = instruction_->GetLocations(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 201 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 202 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 203 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 204 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 205 | // Live registers will be restored in the catch block if caught. |
| 206 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 207 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 208 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 209 | // move resolver. |
| 210 | InvokeRuntimeCallingConvention calling_convention; |
| 211 | codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 212 | locations->InAt(0), LocationFrom(calling_convention.GetRegisterAt(0)), Primitive::kPrimInt, |
| 213 | locations->InAt(1), LocationFrom(calling_convention.GetRegisterAt(1)), Primitive::kPrimInt); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 214 | arm64_codegen->InvokeRuntime( |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 215 | QUICK_ENTRY_POINT(pThrowArrayBounds), instruction_, instruction_->GetDexPc(), this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 216 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 217 | } |
| 218 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 219 | bool IsFatal() const OVERRIDE { return true; } |
| 220 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 221 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathARM64"; } |
| 222 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 223 | private: |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 224 | HBoundsCheck* const instruction_; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 225 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 226 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathARM64); |
| 227 | }; |
| 228 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 229 | class DivZeroCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 230 | public: |
| 231 | explicit DivZeroCheckSlowPathARM64(HDivZeroCheck* instruction) : instruction_(instruction) {} |
| 232 | |
| 233 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 234 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 235 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 236 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 237 | // Live registers will be restored in the catch block if caught. |
| 238 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 239 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 240 | arm64_codegen->InvokeRuntime( |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 241 | QUICK_ENTRY_POINT(pThrowDivZero), instruction_, instruction_->GetDexPc(), this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 242 | CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [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 "DivZeroCheckSlowPathARM64"; } |
| 248 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 249 | private: |
| 250 | HDivZeroCheck* const instruction_; |
| 251 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathARM64); |
| 252 | }; |
| 253 | |
| 254 | class LoadClassSlowPathARM64 : public SlowPathCodeARM64 { |
| 255 | public: |
| 256 | LoadClassSlowPathARM64(HLoadClass* cls, |
| 257 | HInstruction* at, |
| 258 | uint32_t dex_pc, |
| 259 | bool do_clinit) |
| 260 | : cls_(cls), at_(at), dex_pc_(dex_pc), do_clinit_(do_clinit) { |
| 261 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 262 | } |
| 263 | |
| 264 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 265 | LocationSummary* locations = at_->GetLocations(); |
| 266 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 267 | |
| 268 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 269 | SaveLiveRegisters(codegen, locations); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 270 | |
| 271 | InvokeRuntimeCallingConvention calling_convention; |
| 272 | __ Mov(calling_convention.GetRegisterAt(0).W(), cls_->GetTypeIndex()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 273 | int32_t entry_point_offset = do_clinit_ ? QUICK_ENTRY_POINT(pInitializeStaticStorage) |
| 274 | : QUICK_ENTRY_POINT(pInitializeType); |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 275 | arm64_codegen->InvokeRuntime(entry_point_offset, at_, dex_pc_, this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 276 | if (do_clinit_) { |
Vladimir Marko | 5ea536a | 2015-04-20 20:11:30 +0100 | [diff] [blame] | 277 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>(); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 278 | } else { |
Vladimir Marko | 5ea536a | 2015-04-20 20:11:30 +0100 | [diff] [blame] | 279 | CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>(); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 280 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 281 | |
| 282 | // Move the class to the desired location. |
| 283 | Location out = locations->Out(); |
| 284 | if (out.IsValid()) { |
| 285 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
| 286 | Primitive::Type type = at_->GetType(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 287 | arm64_codegen->MoveLocation(out, calling_convention.GetReturnLocation(type), type); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 288 | } |
| 289 | |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 290 | RestoreLiveRegisters(codegen, locations); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 291 | __ B(GetExitLabel()); |
| 292 | } |
| 293 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 294 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathARM64"; } |
| 295 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 296 | private: |
| 297 | // The class this slow path will load. |
| 298 | HLoadClass* const cls_; |
| 299 | |
| 300 | // The instruction where this slow path is happening. |
| 301 | // (Might be the load class or an initialization check). |
| 302 | HInstruction* const at_; |
| 303 | |
| 304 | // The dex PC of `at_`. |
| 305 | const uint32_t dex_pc_; |
| 306 | |
| 307 | // Whether to initialize the class. |
| 308 | const bool do_clinit_; |
| 309 | |
| 310 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathARM64); |
| 311 | }; |
| 312 | |
| 313 | class LoadStringSlowPathARM64 : public SlowPathCodeARM64 { |
| 314 | public: |
| 315 | explicit LoadStringSlowPathARM64(HLoadString* instruction) : instruction_(instruction) {} |
| 316 | |
| 317 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 318 | LocationSummary* locations = instruction_->GetLocations(); |
| 319 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 320 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 321 | |
| 322 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 323 | SaveLiveRegisters(codegen, locations); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 324 | |
| 325 | InvokeRuntimeCallingConvention calling_convention; |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 326 | __ Mov(calling_convention.GetRegisterAt(0).W(), instruction_->GetStringIndex()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 327 | arm64_codegen->InvokeRuntime( |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 328 | QUICK_ENTRY_POINT(pResolveString), instruction_, instruction_->GetDexPc(), this); |
Vladimir Marko | 5ea536a | 2015-04-20 20:11:30 +0100 | [diff] [blame] | 329 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 330 | Primitive::Type type = instruction_->GetType(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 331 | arm64_codegen->MoveLocation(locations->Out(), calling_convention.GetReturnLocation(type), type); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 332 | |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 333 | RestoreLiveRegisters(codegen, locations); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 334 | __ B(GetExitLabel()); |
| 335 | } |
| 336 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 337 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathARM64"; } |
| 338 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 339 | private: |
| 340 | HLoadString* const instruction_; |
| 341 | |
| 342 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathARM64); |
| 343 | }; |
| 344 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 345 | class NullCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 346 | public: |
| 347 | explicit NullCheckSlowPathARM64(HNullCheck* instr) : instruction_(instr) {} |
| 348 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 349 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 350 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 351 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 352 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 353 | // Live registers will be restored in the catch block if caught. |
| 354 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 355 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 356 | arm64_codegen->InvokeRuntime( |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 357 | QUICK_ENTRY_POINT(pThrowNullPointer), instruction_, instruction_->GetDexPc(), this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 358 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 359 | } |
| 360 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 361 | bool IsFatal() const OVERRIDE { return true; } |
| 362 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 363 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathARM64"; } |
| 364 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 365 | private: |
| 366 | HNullCheck* const instruction_; |
| 367 | |
| 368 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathARM64); |
| 369 | }; |
| 370 | |
| 371 | class SuspendCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 372 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 373 | SuspendCheckSlowPathARM64(HSuspendCheck* instruction, HBasicBlock* successor) |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 374 | : instruction_(instruction), successor_(successor) {} |
| 375 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 376 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 377 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 378 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 379 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 380 | arm64_codegen->InvokeRuntime( |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 381 | QUICK_ENTRY_POINT(pTestSuspend), instruction_, instruction_->GetDexPc(), this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 382 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 383 | RestoreLiveRegisters(codegen, instruction_->GetLocations()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 384 | if (successor_ == nullptr) { |
| 385 | __ B(GetReturnLabel()); |
| 386 | } else { |
| 387 | __ B(arm64_codegen->GetLabelOf(successor_)); |
| 388 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 389 | } |
| 390 | |
| 391 | vixl::Label* GetReturnLabel() { |
| 392 | DCHECK(successor_ == nullptr); |
| 393 | return &return_label_; |
| 394 | } |
| 395 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 396 | HBasicBlock* GetSuccessor() const { |
| 397 | return successor_; |
| 398 | } |
| 399 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 400 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathARM64"; } |
| 401 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 402 | private: |
| 403 | HSuspendCheck* const instruction_; |
| 404 | // If not null, the block to branch to after the suspend check. |
| 405 | HBasicBlock* const successor_; |
| 406 | |
| 407 | // If `successor_` is null, the label to branch to after the suspend check. |
| 408 | vixl::Label return_label_; |
| 409 | |
| 410 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathARM64); |
| 411 | }; |
| 412 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 413 | class TypeCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 414 | public: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 415 | TypeCheckSlowPathARM64(HInstruction* instruction, bool is_fatal) |
| 416 | : instruction_(instruction), is_fatal_(is_fatal) {} |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 417 | |
| 418 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 419 | LocationSummary* locations = instruction_->GetLocations(); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 420 | Location class_to_check = locations->InAt(1); |
| 421 | Location object_class = instruction_->IsCheckCast() ? locations->GetTemp(0) |
| 422 | : locations->Out(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 423 | DCHECK(instruction_->IsCheckCast() |
| 424 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 425 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 426 | uint32_t dex_pc = instruction_->GetDexPc(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 427 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 428 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 429 | |
| 430 | if (instruction_->IsCheckCast()) { |
| 431 | // The codegen for the instruction overwrites `temp`, so put it back in place. |
| 432 | Register obj = InputRegisterAt(instruction_, 0); |
| 433 | Register temp = WRegisterFrom(locations->GetTemp(0)); |
| 434 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 435 | __ Ldr(temp, HeapOperand(obj, class_offset)); |
| 436 | arm64_codegen->GetAssembler()->MaybeUnpoisonHeapReference(temp); |
| 437 | } |
| 438 | |
| 439 | if (!is_fatal_) { |
| 440 | SaveLiveRegisters(codegen, locations); |
| 441 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 442 | |
| 443 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 444 | // move resolver. |
| 445 | InvokeRuntimeCallingConvention calling_convention; |
| 446 | codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 447 | class_to_check, LocationFrom(calling_convention.GetRegisterAt(0)), Primitive::kPrimNot, |
| 448 | object_class, LocationFrom(calling_convention.GetRegisterAt(1)), Primitive::kPrimNot); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 449 | |
| 450 | if (instruction_->IsInstanceOf()) { |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 451 | arm64_codegen->InvokeRuntime( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 452 | QUICK_ENTRY_POINT(pInstanceofNonTrivial), instruction_, dex_pc, this); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 453 | Primitive::Type ret_type = instruction_->GetType(); |
| 454 | Location ret_loc = calling_convention.GetReturnLocation(ret_type); |
| 455 | arm64_codegen->MoveLocation(locations->Out(), ret_loc, ret_type); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 456 | CheckEntrypointTypes<kQuickInstanceofNonTrivial, uint32_t, |
| 457 | const mirror::Class*, const mirror::Class*>(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 458 | } else { |
| 459 | DCHECK(instruction_->IsCheckCast()); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 460 | arm64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pCheckCast), instruction_, dex_pc, this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 461 | CheckEntrypointTypes<kQuickCheckCast, void, const mirror::Class*, const mirror::Class*>(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 462 | } |
| 463 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 464 | if (!is_fatal_) { |
| 465 | RestoreLiveRegisters(codegen, locations); |
| 466 | __ B(GetExitLabel()); |
| 467 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 468 | } |
| 469 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 470 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathARM64"; } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 471 | bool IsFatal() const { return is_fatal_; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 472 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 473 | private: |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 474 | HInstruction* const instruction_; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 475 | const bool is_fatal_; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 476 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 477 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathARM64); |
| 478 | }; |
| 479 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 480 | class DeoptimizationSlowPathARM64 : public SlowPathCodeARM64 { |
| 481 | public: |
| 482 | explicit DeoptimizationSlowPathARM64(HInstruction* instruction) |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 483 | : instruction_(instruction) {} |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 484 | |
| 485 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 486 | __ Bind(GetEntryLabel()); |
| 487 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 488 | DCHECK(instruction_->IsDeoptimize()); |
| 489 | HDeoptimize* deoptimize = instruction_->AsDeoptimize(); |
| 490 | uint32_t dex_pc = deoptimize->GetDexPc(); |
| 491 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 492 | arm64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pDeoptimize), instruction_, dex_pc, this); |
| 493 | } |
| 494 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 495 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathARM64"; } |
| 496 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 497 | private: |
| 498 | HInstruction* const instruction_; |
| 499 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathARM64); |
| 500 | }; |
| 501 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 502 | class ArraySetSlowPathARM64 : public SlowPathCodeARM64 { |
| 503 | public: |
| 504 | explicit ArraySetSlowPathARM64(HInstruction* instruction) : instruction_(instruction) {} |
| 505 | |
| 506 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 507 | LocationSummary* locations = instruction_->GetLocations(); |
| 508 | __ Bind(GetEntryLabel()); |
| 509 | SaveLiveRegisters(codegen, locations); |
| 510 | |
| 511 | InvokeRuntimeCallingConvention calling_convention; |
| 512 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 513 | parallel_move.AddMove( |
| 514 | locations->InAt(0), |
| 515 | LocationFrom(calling_convention.GetRegisterAt(0)), |
| 516 | Primitive::kPrimNot, |
| 517 | nullptr); |
| 518 | parallel_move.AddMove( |
| 519 | locations->InAt(1), |
| 520 | LocationFrom(calling_convention.GetRegisterAt(1)), |
| 521 | Primitive::kPrimInt, |
| 522 | nullptr); |
| 523 | parallel_move.AddMove( |
| 524 | locations->InAt(2), |
| 525 | LocationFrom(calling_convention.GetRegisterAt(2)), |
| 526 | Primitive::kPrimNot, |
| 527 | nullptr); |
| 528 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 529 | |
| 530 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 531 | arm64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject), |
| 532 | instruction_, |
| 533 | instruction_->GetDexPc(), |
| 534 | this); |
| 535 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
| 536 | RestoreLiveRegisters(codegen, locations); |
| 537 | __ B(GetExitLabel()); |
| 538 | } |
| 539 | |
| 540 | const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathARM64"; } |
| 541 | |
| 542 | private: |
| 543 | HInstruction* const instruction_; |
| 544 | |
| 545 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathARM64); |
| 546 | }; |
| 547 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 548 | #undef __ |
| 549 | |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 550 | Location InvokeDexCallingConventionVisitorARM64::GetNextLocation(Primitive::Type type) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 551 | Location next_location; |
| 552 | if (type == Primitive::kPrimVoid) { |
| 553 | LOG(FATAL) << "Unreachable type " << type; |
| 554 | } |
| 555 | |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 556 | if (Primitive::IsFloatingPointType(type) && |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 557 | (float_index_ < calling_convention.GetNumberOfFpuRegisters())) { |
| 558 | next_location = LocationFrom(calling_convention.GetFpuRegisterAt(float_index_++)); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 559 | } else if (!Primitive::IsFloatingPointType(type) && |
| 560 | (gp_index_ < calling_convention.GetNumberOfRegisters())) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 561 | next_location = LocationFrom(calling_convention.GetRegisterAt(gp_index_++)); |
| 562 | } else { |
| 563 | size_t stack_offset = calling_convention.GetStackOffsetOf(stack_index_); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 564 | next_location = Primitive::Is64BitType(type) ? Location::DoubleStackSlot(stack_offset) |
| 565 | : Location::StackSlot(stack_offset); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 566 | } |
| 567 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 568 | // Space on the stack is reserved for all arguments. |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 569 | stack_index_ += Primitive::Is64BitType(type) ? 2 : 1; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 570 | return next_location; |
| 571 | } |
| 572 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 573 | Location InvokeDexCallingConventionVisitorARM64::GetMethodLocation() const { |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 574 | return LocationFrom(kArtMethodRegister); |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 575 | } |
| 576 | |
Serban Constantinescu | 579885a | 2015-02-22 20:51:33 +0000 | [diff] [blame] | 577 | CodeGeneratorARM64::CodeGeneratorARM64(HGraph* graph, |
| 578 | const Arm64InstructionSetFeatures& isa_features, |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 579 | const CompilerOptions& compiler_options, |
| 580 | OptimizingCompilerStats* stats) |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 581 | : CodeGenerator(graph, |
| 582 | kNumberOfAllocatableRegisters, |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 583 | kNumberOfAllocatableFPRegisters, |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 584 | kNumberOfAllocatableRegisterPairs, |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 585 | callee_saved_core_registers.list(), |
Nicolas Geoffray | 75d5b9b | 2015-10-05 07:40:35 +0000 | [diff] [blame] | 586 | callee_saved_fp_registers.list(), |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 587 | compiler_options, |
| 588 | stats), |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 589 | block_labels_(nullptr), |
| 590 | location_builder_(graph, this), |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 591 | instruction_visitor_(graph, this), |
Serban Constantinescu | 579885a | 2015-02-22 20:51:33 +0000 | [diff] [blame] | 592 | move_resolver_(graph->GetArena(), this), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 593 | isa_features_(isa_features), |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 594 | uint64_literals_(std::less<uint64_t>(), |
| 595 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 596 | method_patches_(MethodReferenceComparator(), |
| 597 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 598 | call_patches_(MethodReferenceComparator(), |
| 599 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 600 | relative_call_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 601 | pc_rel_dex_cache_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 602 | // Save the link register (containing the return address) to mimic Quick. |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 603 | AddAllocatedRegister(LocationFrom(lr)); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 604 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 605 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 606 | #undef __ |
| 607 | #define __ GetVIXLAssembler()-> |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 608 | |
Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 609 | void CodeGeneratorARM64::Finalize(CodeAllocator* allocator) { |
| 610 | // Ensure we emit the literal pool. |
| 611 | __ FinalizeCode(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 612 | |
Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 613 | CodeGenerator::Finalize(allocator); |
| 614 | } |
| 615 | |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 616 | void ParallelMoveResolverARM64::PrepareForEmitNativeCode() { |
| 617 | // Note: There are 6 kinds of moves: |
| 618 | // 1. constant -> GPR/FPR (non-cycle) |
| 619 | // 2. constant -> stack (non-cycle) |
| 620 | // 3. GPR/FPR -> GPR/FPR |
| 621 | // 4. GPR/FPR -> stack |
| 622 | // 5. stack -> GPR/FPR |
| 623 | // 6. stack -> stack (non-cycle) |
| 624 | // Case 1, 2 and 6 should never be included in a dependency cycle on ARM64. For case 3, 4, and 5 |
| 625 | // VIXL uses at most 1 GPR. VIXL has 2 GPR and 1 FPR temps, and there should be no intersecting |
| 626 | // cycles on ARM64, so we always have 1 GPR and 1 FPR available VIXL temps to resolve the |
| 627 | // dependency. |
| 628 | vixl_temps_.Open(GetVIXLAssembler()); |
| 629 | } |
| 630 | |
| 631 | void ParallelMoveResolverARM64::FinishEmitNativeCode() { |
| 632 | vixl_temps_.Close(); |
| 633 | } |
| 634 | |
| 635 | Location ParallelMoveResolverARM64::AllocateScratchLocationFor(Location::Kind kind) { |
| 636 | DCHECK(kind == Location::kRegister || kind == Location::kFpuRegister || |
| 637 | kind == Location::kStackSlot || kind == Location::kDoubleStackSlot); |
| 638 | kind = (kind == Location::kFpuRegister) ? Location::kFpuRegister : Location::kRegister; |
| 639 | Location scratch = GetScratchLocation(kind); |
| 640 | if (!scratch.Equals(Location::NoLocation())) { |
| 641 | return scratch; |
| 642 | } |
| 643 | // Allocate from VIXL temp registers. |
| 644 | if (kind == Location::kRegister) { |
| 645 | scratch = LocationFrom(vixl_temps_.AcquireX()); |
| 646 | } else { |
| 647 | DCHECK(kind == Location::kFpuRegister); |
| 648 | scratch = LocationFrom(vixl_temps_.AcquireD()); |
| 649 | } |
| 650 | AddScratchLocation(scratch); |
| 651 | return scratch; |
| 652 | } |
| 653 | |
| 654 | void ParallelMoveResolverARM64::FreeScratchLocation(Location loc) { |
| 655 | if (loc.IsRegister()) { |
| 656 | vixl_temps_.Release(XRegisterFrom(loc)); |
| 657 | } else { |
| 658 | DCHECK(loc.IsFpuRegister()); |
| 659 | vixl_temps_.Release(DRegisterFrom(loc)); |
| 660 | } |
| 661 | RemoveScratchLocation(loc); |
| 662 | } |
| 663 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 664 | void ParallelMoveResolverARM64::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 665 | MoveOperands* move = moves_[index]; |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 666 | codegen_->MoveLocation(move->GetDestination(), move->GetSource(), Primitive::kPrimVoid); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 667 | } |
| 668 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 669 | void CodeGeneratorARM64::GenerateFrameEntry() { |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 670 | MacroAssembler* masm = GetVIXLAssembler(); |
| 671 | BlockPoolsScope block_pools(masm); |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 672 | __ Bind(&frame_entry_label_); |
| 673 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 674 | bool do_overflow_check = FrameNeedsStackCheck(GetFrameSize(), kArm64) || !IsLeafMethod(); |
| 675 | if (do_overflow_check) { |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 676 | UseScratchRegisterScope temps(masm); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 677 | Register temp = temps.AcquireX(); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 678 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 679 | __ Sub(temp, sp, static_cast<int32_t>(GetStackOverflowReservedBytes(kArm64))); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 680 | __ Ldr(wzr, MemOperand(temp, 0)); |
| 681 | RecordPcInfo(nullptr, 0); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 682 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 683 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 684 | if (!HasEmptyFrame()) { |
| 685 | int frame_size = GetFrameSize(); |
| 686 | // Stack layout: |
| 687 | // sp[frame_size - 8] : lr. |
| 688 | // ... : other preserved core registers. |
| 689 | // ... : other preserved fp registers. |
| 690 | // ... : reserved frame space. |
| 691 | // sp[0] : current method. |
| 692 | __ Str(kArtMethodRegister, MemOperand(sp, -frame_size, PreIndex)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 693 | GetAssembler()->cfi().AdjustCFAOffset(frame_size); |
Zheng Xu | 69a5030 | 2015-04-14 20:04:41 +0800 | [diff] [blame] | 694 | GetAssembler()->SpillRegisters(GetFramePreservedCoreRegisters(), |
| 695 | frame_size - GetCoreSpillSize()); |
| 696 | GetAssembler()->SpillRegisters(GetFramePreservedFPRegisters(), |
| 697 | frame_size - FrameEntrySpillSize()); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 698 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 699 | } |
| 700 | |
| 701 | void CodeGeneratorARM64::GenerateFrameExit() { |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 702 | BlockPoolsScope block_pools(GetVIXLAssembler()); |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 703 | GetAssembler()->cfi().RememberState(); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 704 | if (!HasEmptyFrame()) { |
| 705 | int frame_size = GetFrameSize(); |
Zheng Xu | 69a5030 | 2015-04-14 20:04:41 +0800 | [diff] [blame] | 706 | GetAssembler()->UnspillRegisters(GetFramePreservedFPRegisters(), |
| 707 | frame_size - FrameEntrySpillSize()); |
| 708 | GetAssembler()->UnspillRegisters(GetFramePreservedCoreRegisters(), |
| 709 | frame_size - GetCoreSpillSize()); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 710 | __ Drop(frame_size); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 711 | GetAssembler()->cfi().AdjustCFAOffset(-frame_size); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 712 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 713 | __ Ret(); |
| 714 | GetAssembler()->cfi().RestoreState(); |
| 715 | GetAssembler()->cfi().DefCFAOffset(GetFrameSize()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 716 | } |
| 717 | |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 718 | vixl::CPURegList CodeGeneratorARM64::GetFramePreservedCoreRegisters() const { |
| 719 | DCHECK(ArtVixlRegCodeCoherentForRegSet(core_spill_mask_, GetNumberOfCoreRegisters(), 0, 0)); |
| 720 | return vixl::CPURegList(vixl::CPURegister::kRegister, vixl::kXRegSize, |
| 721 | core_spill_mask_); |
| 722 | } |
| 723 | |
| 724 | vixl::CPURegList CodeGeneratorARM64::GetFramePreservedFPRegisters() const { |
| 725 | DCHECK(ArtVixlRegCodeCoherentForRegSet(0, 0, fpu_spill_mask_, |
| 726 | GetNumberOfFloatingPointRegisters())); |
| 727 | return vixl::CPURegList(vixl::CPURegister::kFPRegister, vixl::kDRegSize, |
| 728 | fpu_spill_mask_); |
| 729 | } |
| 730 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 731 | void CodeGeneratorARM64::Bind(HBasicBlock* block) { |
| 732 | __ Bind(GetLabelOf(block)); |
| 733 | } |
| 734 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 735 | void CodeGeneratorARM64::Move(HInstruction* instruction, |
| 736 | Location location, |
| 737 | HInstruction* move_for) { |
| 738 | LocationSummary* locations = instruction->GetLocations(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 739 | Primitive::Type type = instruction->GetType(); |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 740 | DCHECK_NE(type, Primitive::kPrimVoid); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 741 | |
Nicolas Geoffray | 9b1eba3 | 2015-07-13 15:55:26 +0100 | [diff] [blame] | 742 | if (instruction->IsFakeString()) { |
| 743 | // The fake string is an alias for null. |
| 744 | DCHECK(IsBaseline()); |
| 745 | instruction = locations->Out().GetConstant(); |
| 746 | DCHECK(instruction->IsNullConstant()) << instruction->DebugName(); |
| 747 | } |
| 748 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 749 | if (instruction->IsCurrentMethod()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 750 | MoveLocation(location, |
| 751 | Location::DoubleStackSlot(kCurrentMethodStackOffset), |
| 752 | Primitive::kPrimVoid); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 753 | } else if (locations != nullptr && locations->Out().Equals(location)) { |
| 754 | return; |
| 755 | } else if (instruction->IsIntConstant() |
| 756 | || instruction->IsLongConstant() |
| 757 | || instruction->IsNullConstant()) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 758 | int64_t value = GetInt64ValueOf(instruction->AsConstant()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 759 | if (location.IsRegister()) { |
| 760 | Register dst = RegisterFrom(location, type); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 761 | DCHECK(((instruction->IsIntConstant() || instruction->IsNullConstant()) && dst.Is32Bits()) || |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 762 | (instruction->IsLongConstant() && dst.Is64Bits())); |
| 763 | __ Mov(dst, value); |
| 764 | } else { |
| 765 | DCHECK(location.IsStackSlot() || location.IsDoubleStackSlot()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 766 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 767 | Register temp = (instruction->IsIntConstant() || instruction->IsNullConstant()) |
| 768 | ? temps.AcquireW() |
| 769 | : temps.AcquireX(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 770 | __ Mov(temp, value); |
| 771 | __ Str(temp, StackOperandFrom(location)); |
| 772 | } |
Nicolas Geoffray | f43083d | 2014-11-07 10:48:10 +0000 | [diff] [blame] | 773 | } else if (instruction->IsTemporary()) { |
| 774 | Location temp_location = GetTemporaryLocation(instruction->AsTemporary()); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 775 | MoveLocation(location, temp_location, type); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 776 | } else if (instruction->IsLoadLocal()) { |
| 777 | uint32_t stack_slot = GetStackSlot(instruction->AsLoadLocal()->GetLocal()); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 778 | if (Primitive::Is64BitType(type)) { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 779 | MoveLocation(location, Location::DoubleStackSlot(stack_slot), type); |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 780 | } else { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 781 | MoveLocation(location, Location::StackSlot(stack_slot), type); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 782 | } |
| 783 | |
| 784 | } else { |
| 785 | DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary()); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 786 | MoveLocation(location, locations->Out(), type); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 787 | } |
| 788 | } |
| 789 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 790 | void CodeGeneratorARM64::MoveConstant(Location location, int32_t value) { |
| 791 | DCHECK(location.IsRegister()); |
| 792 | __ Mov(RegisterFrom(location, Primitive::kPrimInt), value); |
| 793 | } |
| 794 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 795 | void CodeGeneratorARM64::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 796 | if (location.IsRegister()) { |
| 797 | locations->AddTemp(location); |
| 798 | } else { |
| 799 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 800 | } |
| 801 | } |
| 802 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 803 | Location CodeGeneratorARM64::GetStackLocation(HLoadLocal* load) const { |
| 804 | Primitive::Type type = load->GetType(); |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 805 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 806 | switch (type) { |
| 807 | case Primitive::kPrimNot: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 808 | case Primitive::kPrimInt: |
| 809 | case Primitive::kPrimFloat: |
| 810 | return Location::StackSlot(GetStackSlot(load->GetLocal())); |
| 811 | |
| 812 | case Primitive::kPrimLong: |
| 813 | case Primitive::kPrimDouble: |
| 814 | return Location::DoubleStackSlot(GetStackSlot(load->GetLocal())); |
| 815 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 816 | case Primitive::kPrimBoolean: |
| 817 | case Primitive::kPrimByte: |
| 818 | case Primitive::kPrimChar: |
| 819 | case Primitive::kPrimShort: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 820 | case Primitive::kPrimVoid: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 821 | LOG(FATAL) << "Unexpected type " << type; |
| 822 | } |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 823 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 824 | LOG(FATAL) << "Unreachable"; |
| 825 | return Location::NoLocation(); |
| 826 | } |
| 827 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 828 | void CodeGeneratorARM64::MarkGCCard(Register object, Register value, bool value_can_be_null) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 829 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 830 | Register card = temps.AcquireX(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 831 | Register temp = temps.AcquireW(); // Index within the CardTable - 32bit. |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 832 | vixl::Label done; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 833 | if (value_can_be_null) { |
| 834 | __ Cbz(value, &done); |
| 835 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 836 | __ Ldr(card, MemOperand(tr, Thread::CardTableOffset<kArm64WordSize>().Int32Value())); |
| 837 | __ Lsr(temp, object, gc::accounting::CardTable::kCardShift); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 838 | __ Strb(card, MemOperand(card, temp.X())); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 839 | if (value_can_be_null) { |
| 840 | __ Bind(&done); |
| 841 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 842 | } |
| 843 | |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 844 | void CodeGeneratorARM64::SetupBlockedRegisters(bool is_baseline) const { |
| 845 | // Blocked core registers: |
| 846 | // lr : Runtime reserved. |
| 847 | // tr : Runtime reserved. |
| 848 | // xSuspend : Runtime reserved. TODO: Unblock this when the runtime stops using it. |
| 849 | // ip1 : VIXL core temp. |
| 850 | // ip0 : VIXL core temp. |
| 851 | // |
| 852 | // Blocked fp registers: |
| 853 | // d31 : VIXL fp temp. |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 854 | CPURegList reserved_core_registers = vixl_reserved_core_registers; |
| 855 | reserved_core_registers.Combine(runtime_reserved_core_registers); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 856 | while (!reserved_core_registers.IsEmpty()) { |
| 857 | blocked_core_registers_[reserved_core_registers.PopLowestIndex().code()] = true; |
| 858 | } |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 859 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 860 | CPURegList reserved_fp_registers = vixl_reserved_fp_registers; |
Zheng Xu | a3ec394 | 2015-02-15 18:39:46 +0800 | [diff] [blame] | 861 | while (!reserved_fp_registers.IsEmpty()) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 862 | blocked_fpu_registers_[reserved_fp_registers.PopLowestIndex().code()] = true; |
| 863 | } |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 864 | |
| 865 | if (is_baseline) { |
| 866 | CPURegList reserved_core_baseline_registers = callee_saved_core_registers; |
| 867 | while (!reserved_core_baseline_registers.IsEmpty()) { |
| 868 | blocked_core_registers_[reserved_core_baseline_registers.PopLowestIndex().code()] = true; |
| 869 | } |
Nicolas Geoffray | ecf680d | 2015-10-05 11:15:37 +0100 | [diff] [blame] | 870 | } |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 871 | |
Nicolas Geoffray | ecf680d | 2015-10-05 11:15:37 +0100 | [diff] [blame] | 872 | if (is_baseline || GetGraph()->IsDebuggable()) { |
| 873 | // Stubs do not save callee-save floating point registers. If the graph |
| 874 | // is debuggable, we need to deal with these registers differently. For |
| 875 | // now, just block them. |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 876 | CPURegList reserved_fp_baseline_registers = callee_saved_fp_registers; |
| 877 | while (!reserved_fp_baseline_registers.IsEmpty()) { |
| 878 | blocked_fpu_registers_[reserved_fp_baseline_registers.PopLowestIndex().code()] = true; |
| 879 | } |
| 880 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 881 | } |
| 882 | |
| 883 | Location CodeGeneratorARM64::AllocateFreeRegister(Primitive::Type type) const { |
| 884 | if (type == Primitive::kPrimVoid) { |
| 885 | LOG(FATAL) << "Unreachable type " << type; |
| 886 | } |
| 887 | |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 888 | if (Primitive::IsFloatingPointType(type)) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 889 | ssize_t reg = FindFreeEntry(blocked_fpu_registers_, kNumberOfAllocatableFPRegisters); |
| 890 | DCHECK_NE(reg, -1); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 891 | return Location::FpuRegisterLocation(reg); |
| 892 | } else { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 893 | ssize_t reg = FindFreeEntry(blocked_core_registers_, kNumberOfAllocatableRegisters); |
| 894 | DCHECK_NE(reg, -1); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 895 | return Location::RegisterLocation(reg); |
| 896 | } |
| 897 | } |
| 898 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 899 | size_t CodeGeneratorARM64::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 900 | Register reg = Register(VIXLRegCodeFromART(reg_id), kXRegSize); |
| 901 | __ Str(reg, MemOperand(sp, stack_index)); |
| 902 | return kArm64WordSize; |
| 903 | } |
| 904 | |
| 905 | size_t CodeGeneratorARM64::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 906 | Register reg = Register(VIXLRegCodeFromART(reg_id), kXRegSize); |
| 907 | __ Ldr(reg, MemOperand(sp, stack_index)); |
| 908 | return kArm64WordSize; |
| 909 | } |
| 910 | |
| 911 | size_t CodeGeneratorARM64::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 912 | FPRegister reg = FPRegister(reg_id, kDRegSize); |
| 913 | __ Str(reg, MemOperand(sp, stack_index)); |
| 914 | return kArm64WordSize; |
| 915 | } |
| 916 | |
| 917 | size_t CodeGeneratorARM64::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 918 | FPRegister reg = FPRegister(reg_id, kDRegSize); |
| 919 | __ Ldr(reg, MemOperand(sp, stack_index)); |
| 920 | return kArm64WordSize; |
| 921 | } |
| 922 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 923 | void CodeGeneratorARM64::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 924 | stream << XRegister(reg); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 925 | } |
| 926 | |
| 927 | void CodeGeneratorARM64::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 928 | stream << DRegister(reg); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 929 | } |
| 930 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 931 | void CodeGeneratorARM64::MoveConstant(CPURegister destination, HConstant* constant) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 932 | if (constant->IsIntConstant()) { |
| 933 | __ Mov(Register(destination), constant->AsIntConstant()->GetValue()); |
| 934 | } else if (constant->IsLongConstant()) { |
| 935 | __ Mov(Register(destination), constant->AsLongConstant()->GetValue()); |
| 936 | } else if (constant->IsNullConstant()) { |
| 937 | __ Mov(Register(destination), 0); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 938 | } else if (constant->IsFloatConstant()) { |
| 939 | __ Fmov(FPRegister(destination), constant->AsFloatConstant()->GetValue()); |
| 940 | } else { |
| 941 | DCHECK(constant->IsDoubleConstant()); |
| 942 | __ Fmov(FPRegister(destination), constant->AsDoubleConstant()->GetValue()); |
| 943 | } |
| 944 | } |
| 945 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 946 | |
| 947 | static bool CoherentConstantAndType(Location constant, Primitive::Type type) { |
| 948 | DCHECK(constant.IsConstant()); |
| 949 | HConstant* cst = constant.GetConstant(); |
| 950 | return (cst->IsIntConstant() && type == Primitive::kPrimInt) || |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 951 | // Null is mapped to a core W register, which we associate with kPrimInt. |
| 952 | (cst->IsNullConstant() && type == Primitive::kPrimInt) || |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 953 | (cst->IsLongConstant() && type == Primitive::kPrimLong) || |
| 954 | (cst->IsFloatConstant() && type == Primitive::kPrimFloat) || |
| 955 | (cst->IsDoubleConstant() && type == Primitive::kPrimDouble); |
| 956 | } |
| 957 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 958 | void CodeGeneratorARM64::MoveLocation(Location destination, |
| 959 | Location source, |
| 960 | Primitive::Type dst_type) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 961 | if (source.Equals(destination)) { |
| 962 | return; |
| 963 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 964 | |
| 965 | // A valid move can always be inferred from the destination and source |
| 966 | // locations. When moving from and to a register, the argument type can be |
| 967 | // used to generate 32bit instead of 64bit moves. In debug mode we also |
| 968 | // checks the coherency of the locations and the type. |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 969 | bool unspecified_type = (dst_type == Primitive::kPrimVoid); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 970 | |
| 971 | if (destination.IsRegister() || destination.IsFpuRegister()) { |
| 972 | if (unspecified_type) { |
| 973 | HConstant* src_cst = source.IsConstant() ? source.GetConstant() : nullptr; |
| 974 | if (source.IsStackSlot() || |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 975 | (src_cst != nullptr && (src_cst->IsIntConstant() |
| 976 | || src_cst->IsFloatConstant() |
| 977 | || src_cst->IsNullConstant()))) { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 978 | // For stack slots and 32bit constants, a 64bit type is appropriate. |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 979 | dst_type = destination.IsRegister() ? Primitive::kPrimInt : Primitive::kPrimFloat; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 980 | } else { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 981 | // If the source is a double stack slot or a 64bit constant, a 64bit |
| 982 | // type is appropriate. Else the source is a register, and since the |
| 983 | // type has not been specified, we chose a 64bit type to force a 64bit |
| 984 | // move. |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 985 | dst_type = destination.IsRegister() ? Primitive::kPrimLong : Primitive::kPrimDouble; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 986 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 987 | } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 988 | DCHECK((destination.IsFpuRegister() && Primitive::IsFloatingPointType(dst_type)) || |
| 989 | (destination.IsRegister() && !Primitive::IsFloatingPointType(dst_type))); |
| 990 | CPURegister dst = CPURegisterFrom(destination, dst_type); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 991 | if (source.IsStackSlot() || source.IsDoubleStackSlot()) { |
| 992 | DCHECK(dst.Is64Bits() == source.IsDoubleStackSlot()); |
| 993 | __ Ldr(dst, StackOperandFrom(source)); |
| 994 | } else if (source.IsConstant()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 995 | DCHECK(CoherentConstantAndType(source, dst_type)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 996 | MoveConstant(dst, source.GetConstant()); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 997 | } else if (source.IsRegister()) { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 998 | if (destination.IsRegister()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 999 | __ Mov(Register(dst), RegisterFrom(source, dst_type)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1000 | } else { |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1001 | DCHECK(destination.IsFpuRegister()); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1002 | Primitive::Type source_type = Primitive::Is64BitType(dst_type) |
| 1003 | ? Primitive::kPrimLong |
| 1004 | : Primitive::kPrimInt; |
| 1005 | __ Fmov(FPRegisterFrom(destination, dst_type), RegisterFrom(source, source_type)); |
| 1006 | } |
| 1007 | } else { |
| 1008 | DCHECK(source.IsFpuRegister()); |
| 1009 | if (destination.IsRegister()) { |
| 1010 | Primitive::Type source_type = Primitive::Is64BitType(dst_type) |
| 1011 | ? Primitive::kPrimDouble |
| 1012 | : Primitive::kPrimFloat; |
| 1013 | __ Fmov(RegisterFrom(destination, dst_type), FPRegisterFrom(source, source_type)); |
| 1014 | } else { |
| 1015 | DCHECK(destination.IsFpuRegister()); |
| 1016 | __ Fmov(FPRegister(dst), FPRegisterFrom(source, dst_type)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1017 | } |
| 1018 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1019 | } else { // The destination is not a register. It must be a stack slot. |
| 1020 | DCHECK(destination.IsStackSlot() || destination.IsDoubleStackSlot()); |
| 1021 | if (source.IsRegister() || source.IsFpuRegister()) { |
| 1022 | if (unspecified_type) { |
| 1023 | if (source.IsRegister()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1024 | dst_type = destination.IsStackSlot() ? Primitive::kPrimInt : Primitive::kPrimLong; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1025 | } else { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1026 | dst_type = destination.IsStackSlot() ? Primitive::kPrimFloat : Primitive::kPrimDouble; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1027 | } |
| 1028 | } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1029 | DCHECK((destination.IsDoubleStackSlot() == Primitive::Is64BitType(dst_type)) && |
| 1030 | (source.IsFpuRegister() == Primitive::IsFloatingPointType(dst_type))); |
| 1031 | __ Str(CPURegisterFrom(source, dst_type), StackOperandFrom(destination)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1032 | } else if (source.IsConstant()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1033 | DCHECK(unspecified_type || CoherentConstantAndType(source, dst_type)) |
| 1034 | << source << " " << dst_type; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1035 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 1036 | HConstant* src_cst = source.GetConstant(); |
| 1037 | CPURegister temp; |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1038 | if (src_cst->IsIntConstant() || src_cst->IsNullConstant()) { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1039 | temp = temps.AcquireW(); |
| 1040 | } else if (src_cst->IsLongConstant()) { |
| 1041 | temp = temps.AcquireX(); |
| 1042 | } else if (src_cst->IsFloatConstant()) { |
| 1043 | temp = temps.AcquireS(); |
| 1044 | } else { |
| 1045 | DCHECK(src_cst->IsDoubleConstant()); |
| 1046 | temp = temps.AcquireD(); |
| 1047 | } |
| 1048 | MoveConstant(temp, src_cst); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1049 | __ Str(temp, StackOperandFrom(destination)); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1050 | } else { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1051 | DCHECK(source.IsStackSlot() || source.IsDoubleStackSlot()); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1052 | DCHECK(source.IsDoubleStackSlot() == destination.IsDoubleStackSlot()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1053 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1054 | // There is generally less pressure on FP registers. |
| 1055 | FPRegister temp = destination.IsDoubleStackSlot() ? temps.AcquireD() : temps.AcquireS(); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1056 | __ Ldr(temp, StackOperandFrom(source)); |
| 1057 | __ Str(temp, StackOperandFrom(destination)); |
| 1058 | } |
| 1059 | } |
| 1060 | } |
| 1061 | |
| 1062 | void CodeGeneratorARM64::Load(Primitive::Type type, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1063 | CPURegister dst, |
| 1064 | const MemOperand& src) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1065 | switch (type) { |
| 1066 | case Primitive::kPrimBoolean: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1067 | __ Ldrb(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1068 | break; |
| 1069 | case Primitive::kPrimByte: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1070 | __ Ldrsb(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1071 | break; |
| 1072 | case Primitive::kPrimShort: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1073 | __ Ldrsh(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1074 | break; |
| 1075 | case Primitive::kPrimChar: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1076 | __ Ldrh(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1077 | break; |
| 1078 | case Primitive::kPrimInt: |
| 1079 | case Primitive::kPrimNot: |
| 1080 | case Primitive::kPrimLong: |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1081 | case Primitive::kPrimFloat: |
| 1082 | case Primitive::kPrimDouble: |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 1083 | DCHECK_EQ(dst.Is64Bits(), Primitive::Is64BitType(type)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1084 | __ Ldr(dst, src); |
| 1085 | break; |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1086 | case Primitive::kPrimVoid: |
| 1087 | LOG(FATAL) << "Unreachable type " << type; |
| 1088 | } |
| 1089 | } |
| 1090 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1091 | void CodeGeneratorARM64::LoadAcquire(HInstruction* instruction, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1092 | CPURegister dst, |
| 1093 | const MemOperand& src) { |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1094 | MacroAssembler* masm = GetVIXLAssembler(); |
| 1095 | BlockPoolsScope block_pools(masm); |
| 1096 | UseScratchRegisterScope temps(masm); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1097 | Register temp_base = temps.AcquireX(); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1098 | Primitive::Type type = instruction->GetType(); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1099 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1100 | DCHECK(!src.IsPreIndex()); |
| 1101 | DCHECK(!src.IsPostIndex()); |
| 1102 | |
| 1103 | // TODO(vixl): Let the MacroAssembler handle MemOperand. |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 1104 | __ Add(temp_base, src.base(), OperandFromMemOperand(src)); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1105 | MemOperand base = MemOperand(temp_base); |
| 1106 | switch (type) { |
| 1107 | case Primitive::kPrimBoolean: |
| 1108 | __ Ldarb(Register(dst), base); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1109 | MaybeRecordImplicitNullCheck(instruction); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1110 | break; |
| 1111 | case Primitive::kPrimByte: |
| 1112 | __ Ldarb(Register(dst), base); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1113 | MaybeRecordImplicitNullCheck(instruction); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1114 | __ Sbfx(Register(dst), Register(dst), 0, Primitive::ComponentSize(type) * kBitsPerByte); |
| 1115 | break; |
| 1116 | case Primitive::kPrimChar: |
| 1117 | __ Ldarh(Register(dst), base); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1118 | MaybeRecordImplicitNullCheck(instruction); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1119 | break; |
| 1120 | case Primitive::kPrimShort: |
| 1121 | __ Ldarh(Register(dst), base); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1122 | MaybeRecordImplicitNullCheck(instruction); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1123 | __ Sbfx(Register(dst), Register(dst), 0, Primitive::ComponentSize(type) * kBitsPerByte); |
| 1124 | break; |
| 1125 | case Primitive::kPrimInt: |
| 1126 | case Primitive::kPrimNot: |
| 1127 | case Primitive::kPrimLong: |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 1128 | DCHECK_EQ(dst.Is64Bits(), Primitive::Is64BitType(type)); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1129 | __ Ldar(Register(dst), base); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1130 | MaybeRecordImplicitNullCheck(instruction); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1131 | break; |
| 1132 | case Primitive::kPrimFloat: |
| 1133 | case Primitive::kPrimDouble: { |
| 1134 | DCHECK(dst.IsFPRegister()); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 1135 | DCHECK_EQ(dst.Is64Bits(), Primitive::Is64BitType(type)); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1136 | |
| 1137 | Register temp = dst.Is64Bits() ? temps.AcquireX() : temps.AcquireW(); |
| 1138 | __ Ldar(temp, base); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1139 | MaybeRecordImplicitNullCheck(instruction); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1140 | __ Fmov(FPRegister(dst), temp); |
| 1141 | break; |
| 1142 | } |
| 1143 | case Primitive::kPrimVoid: |
| 1144 | LOG(FATAL) << "Unreachable type " << type; |
| 1145 | } |
| 1146 | } |
| 1147 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1148 | void CodeGeneratorARM64::Store(Primitive::Type type, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1149 | CPURegister src, |
| 1150 | const MemOperand& dst) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1151 | switch (type) { |
| 1152 | case Primitive::kPrimBoolean: |
| 1153 | case Primitive::kPrimByte: |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1154 | __ Strb(Register(src), dst); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1155 | break; |
| 1156 | case Primitive::kPrimChar: |
| 1157 | case Primitive::kPrimShort: |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1158 | __ Strh(Register(src), dst); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1159 | break; |
| 1160 | case Primitive::kPrimInt: |
| 1161 | case Primitive::kPrimNot: |
| 1162 | case Primitive::kPrimLong: |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1163 | case Primitive::kPrimFloat: |
| 1164 | case Primitive::kPrimDouble: |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 1165 | DCHECK_EQ(src.Is64Bits(), Primitive::Is64BitType(type)); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1166 | __ Str(src, dst); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1167 | break; |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1168 | case Primitive::kPrimVoid: |
| 1169 | LOG(FATAL) << "Unreachable type " << type; |
| 1170 | } |
| 1171 | } |
| 1172 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1173 | void CodeGeneratorARM64::StoreRelease(Primitive::Type type, |
| 1174 | CPURegister src, |
| 1175 | const MemOperand& dst) { |
| 1176 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 1177 | Register temp_base = temps.AcquireX(); |
| 1178 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1179 | DCHECK(!dst.IsPreIndex()); |
| 1180 | DCHECK(!dst.IsPostIndex()); |
| 1181 | |
| 1182 | // TODO(vixl): Let the MacroAssembler handle this. |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 1183 | Operand op = OperandFromMemOperand(dst); |
| 1184 | __ Add(temp_base, dst.base(), op); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1185 | MemOperand base = MemOperand(temp_base); |
| 1186 | switch (type) { |
| 1187 | case Primitive::kPrimBoolean: |
| 1188 | case Primitive::kPrimByte: |
| 1189 | __ Stlrb(Register(src), base); |
| 1190 | break; |
| 1191 | case Primitive::kPrimChar: |
| 1192 | case Primitive::kPrimShort: |
| 1193 | __ Stlrh(Register(src), base); |
| 1194 | break; |
| 1195 | case Primitive::kPrimInt: |
| 1196 | case Primitive::kPrimNot: |
| 1197 | case Primitive::kPrimLong: |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 1198 | DCHECK_EQ(src.Is64Bits(), Primitive::Is64BitType(type)); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1199 | __ Stlr(Register(src), base); |
| 1200 | break; |
| 1201 | case Primitive::kPrimFloat: |
| 1202 | case Primitive::kPrimDouble: { |
| 1203 | DCHECK(src.IsFPRegister()); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 1204 | DCHECK_EQ(src.Is64Bits(), Primitive::Is64BitType(type)); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1205 | |
| 1206 | Register temp = src.Is64Bits() ? temps.AcquireX() : temps.AcquireW(); |
| 1207 | __ Fmov(temp, FPRegister(src)); |
| 1208 | __ Stlr(temp, base); |
| 1209 | break; |
| 1210 | } |
| 1211 | case Primitive::kPrimVoid: |
| 1212 | LOG(FATAL) << "Unreachable type " << type; |
| 1213 | } |
| 1214 | } |
| 1215 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1216 | void CodeGeneratorARM64::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 1217 | HInstruction* instruction, |
| 1218 | uint32_t dex_pc, |
| 1219 | SlowPathCode* slow_path) { |
| 1220 | InvokeRuntime(GetThreadOffset<kArm64WordSize>(entrypoint).Int32Value(), |
| 1221 | instruction, |
| 1222 | dex_pc, |
| 1223 | slow_path); |
| 1224 | } |
| 1225 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1226 | void CodeGeneratorARM64::InvokeRuntime(int32_t entry_point_offset, |
| 1227 | HInstruction* instruction, |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 1228 | uint32_t dex_pc, |
| 1229 | SlowPathCode* slow_path) { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1230 | ValidateInvokeRuntime(instruction, slow_path); |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1231 | BlockPoolsScope block_pools(GetVIXLAssembler()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1232 | __ Ldr(lr, MemOperand(tr, entry_point_offset)); |
| 1233 | __ Blr(lr); |
Roland Levillain | 896e32d | 2015-05-05 18:07:10 +0100 | [diff] [blame] | 1234 | RecordPcInfo(instruction, dex_pc, slow_path); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1235 | } |
| 1236 | |
| 1237 | void InstructionCodeGeneratorARM64::GenerateClassInitializationCheck(SlowPathCodeARM64* slow_path, |
| 1238 | vixl::Register class_reg) { |
| 1239 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 1240 | Register temp = temps.AcquireW(); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1241 | size_t status_offset = mirror::Class::StatusOffset().SizeValue(); |
Serban Constantinescu | 579885a | 2015-02-22 20:51:33 +0000 | [diff] [blame] | 1242 | bool use_acquire_release = codegen_->GetInstructionSetFeatures().PreferAcquireRelease(); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1243 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1244 | // Even if the initialized flag is set, we need to ensure consistent memory ordering. |
Serban Constantinescu | 579885a | 2015-02-22 20:51:33 +0000 | [diff] [blame] | 1245 | if (use_acquire_release) { |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1246 | // TODO(vixl): Let the MacroAssembler handle MemOperand. |
| 1247 | __ Add(temp, class_reg, status_offset); |
| 1248 | __ Ldar(temp, HeapOperand(temp)); |
| 1249 | __ Cmp(temp, mirror::Class::kStatusInitialized); |
| 1250 | __ B(lt, slow_path->GetEntryLabel()); |
| 1251 | } else { |
| 1252 | __ Ldr(temp, HeapOperand(class_reg, status_offset)); |
| 1253 | __ Cmp(temp, mirror::Class::kStatusInitialized); |
| 1254 | __ B(lt, slow_path->GetEntryLabel()); |
| 1255 | __ Dmb(InnerShareable, BarrierReads); |
| 1256 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1257 | __ Bind(slow_path->GetExitLabel()); |
| 1258 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1259 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1260 | void InstructionCodeGeneratorARM64::GenerateMemoryBarrier(MemBarrierKind kind) { |
| 1261 | BarrierType type = BarrierAll; |
| 1262 | |
| 1263 | switch (kind) { |
| 1264 | case MemBarrierKind::kAnyAny: |
| 1265 | case MemBarrierKind::kAnyStore: { |
| 1266 | type = BarrierAll; |
| 1267 | break; |
| 1268 | } |
| 1269 | case MemBarrierKind::kLoadAny: { |
| 1270 | type = BarrierReads; |
| 1271 | break; |
| 1272 | } |
| 1273 | case MemBarrierKind::kStoreStore: { |
| 1274 | type = BarrierWrites; |
| 1275 | break; |
| 1276 | } |
| 1277 | default: |
| 1278 | LOG(FATAL) << "Unexpected memory barrier " << kind; |
| 1279 | } |
| 1280 | __ Dmb(InnerShareable, type); |
| 1281 | } |
| 1282 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1283 | void InstructionCodeGeneratorARM64::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 1284 | HBasicBlock* successor) { |
| 1285 | SuspendCheckSlowPathARM64* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 1286 | down_cast<SuspendCheckSlowPathARM64*>(instruction->GetSlowPath()); |
| 1287 | if (slow_path == nullptr) { |
| 1288 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathARM64(instruction, successor); |
| 1289 | instruction->SetSlowPath(slow_path); |
| 1290 | codegen_->AddSlowPath(slow_path); |
| 1291 | if (successor != nullptr) { |
| 1292 | DCHECK(successor->IsLoopHeader()); |
| 1293 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 1294 | } |
| 1295 | } else { |
| 1296 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 1297 | } |
| 1298 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1299 | UseScratchRegisterScope temps(codegen_->GetVIXLAssembler()); |
| 1300 | Register temp = temps.AcquireW(); |
| 1301 | |
| 1302 | __ Ldrh(temp, MemOperand(tr, Thread::ThreadFlagsOffset<kArm64WordSize>().SizeValue())); |
| 1303 | if (successor == nullptr) { |
| 1304 | __ Cbnz(temp, slow_path->GetEntryLabel()); |
| 1305 | __ Bind(slow_path->GetReturnLabel()); |
| 1306 | } else { |
| 1307 | __ Cbz(temp, codegen_->GetLabelOf(successor)); |
| 1308 | __ B(slow_path->GetEntryLabel()); |
| 1309 | // slow_path will return to GetLabelOf(successor). |
| 1310 | } |
| 1311 | } |
| 1312 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1313 | InstructionCodeGeneratorARM64::InstructionCodeGeneratorARM64(HGraph* graph, |
| 1314 | CodeGeneratorARM64* codegen) |
| 1315 | : HGraphVisitor(graph), |
| 1316 | assembler_(codegen->GetAssembler()), |
| 1317 | codegen_(codegen) {} |
| 1318 | |
| 1319 | #define FOR_EACH_UNIMPLEMENTED_INSTRUCTION(M) \ |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1320 | /* No unimplemented IR. */ |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1321 | |
| 1322 | #define UNIMPLEMENTED_INSTRUCTION_BREAK_CODE(name) name##UnimplementedInstructionBreakCode |
| 1323 | |
| 1324 | enum UnimplementedInstructionBreakCode { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1325 | // Using a base helps identify when we hit such breakpoints. |
| 1326 | UnimplementedInstructionBreakCodeBaseCode = 0x900, |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1327 | #define ENUM_UNIMPLEMENTED_INSTRUCTION(name) UNIMPLEMENTED_INSTRUCTION_BREAK_CODE(name), |
| 1328 | FOR_EACH_UNIMPLEMENTED_INSTRUCTION(ENUM_UNIMPLEMENTED_INSTRUCTION) |
| 1329 | #undef ENUM_UNIMPLEMENTED_INSTRUCTION |
| 1330 | }; |
| 1331 | |
| 1332 | #define DEFINE_UNIMPLEMENTED_INSTRUCTION_VISITORS(name) \ |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1333 | void InstructionCodeGeneratorARM64::Visit##name(H##name* instr ATTRIBUTE_UNUSED) { \ |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1334 | __ Brk(UNIMPLEMENTED_INSTRUCTION_BREAK_CODE(name)); \ |
| 1335 | } \ |
| 1336 | void LocationsBuilderARM64::Visit##name(H##name* instr) { \ |
| 1337 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr); \ |
| 1338 | locations->SetOut(Location::Any()); \ |
| 1339 | } |
| 1340 | FOR_EACH_UNIMPLEMENTED_INSTRUCTION(DEFINE_UNIMPLEMENTED_INSTRUCTION_VISITORS) |
| 1341 | #undef DEFINE_UNIMPLEMENTED_INSTRUCTION_VISITORS |
| 1342 | |
| 1343 | #undef UNIMPLEMENTED_INSTRUCTION_BREAK_CODE |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1344 | #undef FOR_EACH_UNIMPLEMENTED_INSTRUCTION |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1345 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1346 | void LocationsBuilderARM64::HandleBinaryOp(HBinaryOperation* instr) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1347 | DCHECK_EQ(instr->InputCount(), 2U); |
| 1348 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr); |
| 1349 | Primitive::Type type = instr->GetResultType(); |
| 1350 | switch (type) { |
| 1351 | case Primitive::kPrimInt: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1352 | case Primitive::kPrimLong: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1353 | locations->SetInAt(0, Location::RequiresRegister()); |
Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 1354 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instr->InputAt(1), instr)); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 1355 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1356 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1357 | |
| 1358 | case Primitive::kPrimFloat: |
| 1359 | case Primitive::kPrimDouble: |
| 1360 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1361 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1362 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1363 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1364 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1365 | default: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1366 | LOG(FATAL) << "Unexpected " << instr->DebugName() << " type " << type; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1367 | } |
| 1368 | } |
| 1369 | |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1370 | void LocationsBuilderARM64::HandleFieldGet(HInstruction* instruction) { |
| 1371 | LocationSummary* locations = |
| 1372 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 1373 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1374 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 1375 | locations->SetOut(Location::RequiresFpuRegister()); |
| 1376 | } else { |
| 1377 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1378 | } |
| 1379 | } |
| 1380 | |
| 1381 | void InstructionCodeGeneratorARM64::HandleFieldGet(HInstruction* instruction, |
| 1382 | const FieldInfo& field_info) { |
| 1383 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1384 | Primitive::Type field_type = field_info.GetFieldType(); |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1385 | BlockPoolsScope block_pools(GetVIXLAssembler()); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1386 | |
| 1387 | MemOperand field = HeapOperand(InputRegisterAt(instruction, 0), field_info.GetFieldOffset()); |
| 1388 | bool use_acquire_release = codegen_->GetInstructionSetFeatures().PreferAcquireRelease(); |
| 1389 | |
| 1390 | if (field_info.IsVolatile()) { |
| 1391 | if (use_acquire_release) { |
| 1392 | // NB: LoadAcquire will record the pc info if needed. |
| 1393 | codegen_->LoadAcquire(instruction, OutputCPURegister(instruction), field); |
| 1394 | } else { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1395 | codegen_->Load(field_type, OutputCPURegister(instruction), field); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1396 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 1397 | // For IRIW sequential consistency kLoadAny is not sufficient. |
| 1398 | GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
| 1399 | } |
| 1400 | } else { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1401 | codegen_->Load(field_type, OutputCPURegister(instruction), field); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1402 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 1403 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1404 | |
| 1405 | if (field_type == Primitive::kPrimNot) { |
| 1406 | GetAssembler()->MaybeUnpoisonHeapReference(OutputCPURegister(instruction).W()); |
| 1407 | } |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1408 | } |
| 1409 | |
| 1410 | void LocationsBuilderARM64::HandleFieldSet(HInstruction* instruction) { |
| 1411 | LocationSummary* locations = |
| 1412 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 1413 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1414 | if (Primitive::IsFloatingPointType(instruction->InputAt(1)->GetType())) { |
| 1415 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1416 | } else { |
| 1417 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1418 | } |
| 1419 | } |
| 1420 | |
| 1421 | void InstructionCodeGeneratorARM64::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1422 | const FieldInfo& field_info, |
| 1423 | bool value_can_be_null) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1424 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1425 | BlockPoolsScope block_pools(GetVIXLAssembler()); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1426 | |
| 1427 | Register obj = InputRegisterAt(instruction, 0); |
| 1428 | CPURegister value = InputCPURegisterAt(instruction, 1); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1429 | CPURegister source = value; |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1430 | Offset offset = field_info.GetFieldOffset(); |
| 1431 | Primitive::Type field_type = field_info.GetFieldType(); |
| 1432 | bool use_acquire_release = codegen_->GetInstructionSetFeatures().PreferAcquireRelease(); |
| 1433 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1434 | { |
| 1435 | // We use a block to end the scratch scope before the write barrier, thus |
| 1436 | // freeing the temporary registers so they can be used in `MarkGCCard`. |
| 1437 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 1438 | |
| 1439 | if (kPoisonHeapReferences && field_type == Primitive::kPrimNot) { |
| 1440 | DCHECK(value.IsW()); |
| 1441 | Register temp = temps.AcquireW(); |
| 1442 | __ Mov(temp, value.W()); |
| 1443 | GetAssembler()->PoisonHeapReference(temp.W()); |
| 1444 | source = temp; |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1445 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1446 | |
| 1447 | if (field_info.IsVolatile()) { |
| 1448 | if (use_acquire_release) { |
| 1449 | codegen_->StoreRelease(field_type, source, HeapOperand(obj, offset)); |
| 1450 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 1451 | } else { |
| 1452 | GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
| 1453 | codegen_->Store(field_type, source, HeapOperand(obj, offset)); |
| 1454 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 1455 | GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
| 1456 | } |
| 1457 | } else { |
| 1458 | codegen_->Store(field_type, source, HeapOperand(obj, offset)); |
| 1459 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 1460 | } |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1461 | } |
| 1462 | |
| 1463 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1464 | codegen_->MarkGCCard(obj, Register(value), value_can_be_null); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1465 | } |
| 1466 | } |
| 1467 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1468 | void InstructionCodeGeneratorARM64::HandleBinaryOp(HBinaryOperation* instr) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1469 | Primitive::Type type = instr->GetType(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1470 | |
| 1471 | switch (type) { |
| 1472 | case Primitive::kPrimInt: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1473 | case Primitive::kPrimLong: { |
| 1474 | Register dst = OutputRegister(instr); |
| 1475 | Register lhs = InputRegisterAt(instr, 0); |
| 1476 | Operand rhs = InputOperandAt(instr, 1); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1477 | if (instr->IsAdd()) { |
| 1478 | __ Add(dst, lhs, rhs); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1479 | } else if (instr->IsAnd()) { |
| 1480 | __ And(dst, lhs, rhs); |
| 1481 | } else if (instr->IsOr()) { |
| 1482 | __ Orr(dst, lhs, rhs); |
| 1483 | } else if (instr->IsSub()) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1484 | __ Sub(dst, lhs, rhs); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1485 | } else { |
| 1486 | DCHECK(instr->IsXor()); |
| 1487 | __ Eor(dst, lhs, rhs); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1488 | } |
| 1489 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1490 | } |
| 1491 | case Primitive::kPrimFloat: |
| 1492 | case Primitive::kPrimDouble: { |
| 1493 | FPRegister dst = OutputFPRegister(instr); |
| 1494 | FPRegister lhs = InputFPRegisterAt(instr, 0); |
| 1495 | FPRegister rhs = InputFPRegisterAt(instr, 1); |
| 1496 | if (instr->IsAdd()) { |
| 1497 | __ Fadd(dst, lhs, rhs); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1498 | } else if (instr->IsSub()) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1499 | __ Fsub(dst, lhs, rhs); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1500 | } else { |
| 1501 | LOG(FATAL) << "Unexpected floating-point binary operation"; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1502 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1503 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1504 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1505 | default: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1506 | LOG(FATAL) << "Unexpected binary operation type " << type; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1507 | } |
| 1508 | } |
| 1509 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1510 | void LocationsBuilderARM64::HandleShift(HBinaryOperation* instr) { |
| 1511 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr()); |
| 1512 | |
| 1513 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr); |
| 1514 | Primitive::Type type = instr->GetResultType(); |
| 1515 | switch (type) { |
| 1516 | case Primitive::kPrimInt: |
| 1517 | case Primitive::kPrimLong: { |
| 1518 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1519 | locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1))); |
| 1520 | locations->SetOut(Location::RequiresRegister()); |
| 1521 | break; |
| 1522 | } |
| 1523 | default: |
| 1524 | LOG(FATAL) << "Unexpected shift type " << type; |
| 1525 | } |
| 1526 | } |
| 1527 | |
| 1528 | void InstructionCodeGeneratorARM64::HandleShift(HBinaryOperation* instr) { |
| 1529 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr()); |
| 1530 | |
| 1531 | Primitive::Type type = instr->GetType(); |
| 1532 | switch (type) { |
| 1533 | case Primitive::kPrimInt: |
| 1534 | case Primitive::kPrimLong: { |
| 1535 | Register dst = OutputRegister(instr); |
| 1536 | Register lhs = InputRegisterAt(instr, 0); |
| 1537 | Operand rhs = InputOperandAt(instr, 1); |
| 1538 | if (rhs.IsImmediate()) { |
| 1539 | uint32_t shift_value = (type == Primitive::kPrimInt) |
| 1540 | ? static_cast<uint32_t>(rhs.immediate() & kMaxIntShiftValue) |
| 1541 | : static_cast<uint32_t>(rhs.immediate() & kMaxLongShiftValue); |
| 1542 | if (instr->IsShl()) { |
| 1543 | __ Lsl(dst, lhs, shift_value); |
| 1544 | } else if (instr->IsShr()) { |
| 1545 | __ Asr(dst, lhs, shift_value); |
| 1546 | } else { |
| 1547 | __ Lsr(dst, lhs, shift_value); |
| 1548 | } |
| 1549 | } else { |
| 1550 | Register rhs_reg = dst.IsX() ? rhs.reg().X() : rhs.reg().W(); |
| 1551 | |
| 1552 | if (instr->IsShl()) { |
| 1553 | __ Lsl(dst, lhs, rhs_reg); |
| 1554 | } else if (instr->IsShr()) { |
| 1555 | __ Asr(dst, lhs, rhs_reg); |
| 1556 | } else { |
| 1557 | __ Lsr(dst, lhs, rhs_reg); |
| 1558 | } |
| 1559 | } |
| 1560 | break; |
| 1561 | } |
| 1562 | default: |
| 1563 | LOG(FATAL) << "Unexpected shift operation type " << type; |
| 1564 | } |
| 1565 | } |
| 1566 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1567 | void LocationsBuilderARM64::VisitAdd(HAdd* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1568 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1569 | } |
| 1570 | |
| 1571 | void InstructionCodeGeneratorARM64::VisitAdd(HAdd* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1572 | HandleBinaryOp(instruction); |
| 1573 | } |
| 1574 | |
| 1575 | void LocationsBuilderARM64::VisitAnd(HAnd* instruction) { |
| 1576 | HandleBinaryOp(instruction); |
| 1577 | } |
| 1578 | |
| 1579 | void InstructionCodeGeneratorARM64::VisitAnd(HAnd* instruction) { |
| 1580 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1581 | } |
| 1582 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1583 | void LocationsBuilderARM64::VisitArrayGet(HArrayGet* instruction) { |
| 1584 | LocationSummary* locations = |
| 1585 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 1586 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1587 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 1588 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 1589 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 1590 | } else { |
| 1591 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1592 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1593 | } |
| 1594 | |
| 1595 | void InstructionCodeGeneratorARM64::VisitArrayGet(HArrayGet* instruction) { |
| 1596 | LocationSummary* locations = instruction->GetLocations(); |
| 1597 | Primitive::Type type = instruction->GetType(); |
| 1598 | Register obj = InputRegisterAt(instruction, 0); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1599 | Location index = locations->InAt(1); |
| 1600 | size_t offset = mirror::Array::DataOffset(Primitive::ComponentSize(type)).Uint32Value(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1601 | MemOperand source = HeapOperand(obj); |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1602 | MacroAssembler* masm = GetVIXLAssembler(); |
| 1603 | UseScratchRegisterScope temps(masm); |
| 1604 | BlockPoolsScope block_pools(masm); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1605 | |
| 1606 | if (index.IsConstant()) { |
| 1607 | offset += Int64ConstantFrom(index) << Primitive::ComponentSizeShift(type); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1608 | source = HeapOperand(obj, offset); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1609 | } else { |
| 1610 | Register temp = temps.AcquireSameSizeAs(obj); |
Alexandre Rames | 82000b0 | 2015-07-07 11:34:16 +0100 | [diff] [blame] | 1611 | __ Add(temp, obj, offset); |
| 1612 | source = HeapOperand(temp, XRegisterFrom(index), LSL, Primitive::ComponentSizeShift(type)); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1613 | } |
| 1614 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1615 | codegen_->Load(type, OutputCPURegister(instruction), source); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1616 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1617 | |
| 1618 | if (type == Primitive::kPrimNot) { |
| 1619 | GetAssembler()->MaybeUnpoisonHeapReference(OutputCPURegister(instruction).W()); |
| 1620 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1621 | } |
| 1622 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1623 | void LocationsBuilderARM64::VisitArrayLength(HArrayLength* instruction) { |
| 1624 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 1625 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 1626 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1627 | } |
| 1628 | |
| 1629 | void InstructionCodeGeneratorARM64::VisitArrayLength(HArrayLength* instruction) { |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1630 | BlockPoolsScope block_pools(GetVIXLAssembler()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1631 | __ Ldr(OutputRegister(instruction), |
| 1632 | HeapOperand(InputRegisterAt(instruction, 0), mirror::Array::LengthOffset())); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1633 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1634 | } |
| 1635 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1636 | void LocationsBuilderARM64::VisitArraySet(HArraySet* instruction) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 1637 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 1638 | instruction, |
| 1639 | instruction->NeedsTypeCheck() ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall); |
| 1640 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1641 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 1642 | if (Primitive::IsFloatingPointType(instruction->InputAt(2)->GetType())) { |
| 1643 | locations->SetInAt(2, Location::RequiresFpuRegister()); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1644 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 1645 | locations->SetInAt(2, Location::RequiresRegister()); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1646 | } |
| 1647 | } |
| 1648 | |
| 1649 | void InstructionCodeGeneratorARM64::VisitArraySet(HArraySet* instruction) { |
| 1650 | Primitive::Type value_type = instruction->GetComponentType(); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 1651 | LocationSummary* locations = instruction->GetLocations(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 1652 | bool may_need_runtime_call = locations->CanCall(); |
| 1653 | bool needs_write_barrier = |
| 1654 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 1655 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 1656 | Register array = InputRegisterAt(instruction, 0); |
| 1657 | CPURegister value = InputCPURegisterAt(instruction, 2); |
| 1658 | CPURegister source = value; |
| 1659 | Location index = locations->InAt(1); |
| 1660 | size_t offset = mirror::Array::DataOffset(Primitive::ComponentSize(value_type)).Uint32Value(); |
| 1661 | MemOperand destination = HeapOperand(array); |
| 1662 | MacroAssembler* masm = GetVIXLAssembler(); |
| 1663 | BlockPoolsScope block_pools(masm); |
| 1664 | |
| 1665 | if (!needs_write_barrier) { |
| 1666 | DCHECK(!may_need_runtime_call); |
| 1667 | if (index.IsConstant()) { |
| 1668 | offset += Int64ConstantFrom(index) << Primitive::ComponentSizeShift(value_type); |
| 1669 | destination = HeapOperand(array, offset); |
| 1670 | } else { |
| 1671 | UseScratchRegisterScope temps(masm); |
| 1672 | Register temp = temps.AcquireSameSizeAs(array); |
| 1673 | __ Add(temp, array, offset); |
| 1674 | destination = HeapOperand(temp, |
| 1675 | XRegisterFrom(index), |
| 1676 | LSL, |
| 1677 | Primitive::ComponentSizeShift(value_type)); |
| 1678 | } |
| 1679 | codegen_->Store(value_type, value, destination); |
| 1680 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1681 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 1682 | DCHECK(needs_write_barrier); |
| 1683 | vixl::Label done; |
| 1684 | SlowPathCodeARM64* slow_path = nullptr; |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 1685 | { |
| 1686 | // We use a block to end the scratch scope before the write barrier, thus |
| 1687 | // freeing the temporary registers so they can be used in `MarkGCCard`. |
| 1688 | UseScratchRegisterScope temps(masm); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 1689 | Register temp = temps.AcquireSameSizeAs(array); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 1690 | if (index.IsConstant()) { |
| 1691 | offset += Int64ConstantFrom(index) << Primitive::ComponentSizeShift(value_type); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 1692 | destination = HeapOperand(array, offset); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 1693 | } else { |
Alexandre Rames | 82000b0 | 2015-07-07 11:34:16 +0100 | [diff] [blame] | 1694 | destination = HeapOperand(temp, |
| 1695 | XRegisterFrom(index), |
| 1696 | LSL, |
| 1697 | Primitive::ComponentSizeShift(value_type)); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 1698 | } |
| 1699 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 1700 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 1701 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 1702 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 1703 | |
| 1704 | if (may_need_runtime_call) { |
| 1705 | slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathARM64(instruction); |
| 1706 | codegen_->AddSlowPath(slow_path); |
| 1707 | if (instruction->GetValueCanBeNull()) { |
| 1708 | vixl::Label non_zero; |
| 1709 | __ Cbnz(Register(value), &non_zero); |
| 1710 | if (!index.IsConstant()) { |
| 1711 | __ Add(temp, array, offset); |
| 1712 | } |
| 1713 | __ Str(wzr, destination); |
| 1714 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 1715 | __ B(&done); |
| 1716 | __ Bind(&non_zero); |
| 1717 | } |
| 1718 | |
| 1719 | Register temp2 = temps.AcquireSameSizeAs(array); |
| 1720 | __ Ldr(temp, HeapOperand(array, class_offset)); |
| 1721 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 1722 | GetAssembler()->MaybeUnpoisonHeapReference(temp); |
| 1723 | __ Ldr(temp, HeapOperand(temp, component_offset)); |
| 1724 | __ Ldr(temp2, HeapOperand(Register(value), class_offset)); |
| 1725 | // No need to poison/unpoison, we're comparing two poisoned references. |
| 1726 | __ Cmp(temp, temp2); |
| 1727 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 1728 | vixl::Label do_put; |
| 1729 | __ B(eq, &do_put); |
| 1730 | GetAssembler()->MaybeUnpoisonHeapReference(temp); |
| 1731 | __ Ldr(temp, HeapOperand(temp, super_offset)); |
| 1732 | // No need to unpoison, we're comparing against null. |
| 1733 | __ Cbnz(temp, slow_path->GetEntryLabel()); |
| 1734 | __ Bind(&do_put); |
| 1735 | } else { |
| 1736 | __ B(ne, slow_path->GetEntryLabel()); |
| 1737 | } |
Nicolas Geoffray | a8a0fe2 | 2015-10-01 15:50:27 +0100 | [diff] [blame] | 1738 | temps.Release(temp2); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 1739 | } |
| 1740 | |
| 1741 | if (kPoisonHeapReferences) { |
Nicolas Geoffray | a8a0fe2 | 2015-10-01 15:50:27 +0100 | [diff] [blame] | 1742 | Register temp2 = temps.AcquireSameSizeAs(array); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 1743 | DCHECK(value.IsW()); |
Nicolas Geoffray | a8a0fe2 | 2015-10-01 15:50:27 +0100 | [diff] [blame] | 1744 | __ Mov(temp2, value.W()); |
| 1745 | GetAssembler()->PoisonHeapReference(temp2); |
| 1746 | source = temp2; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 1747 | } |
| 1748 | |
| 1749 | if (!index.IsConstant()) { |
| 1750 | __ Add(temp, array, offset); |
| 1751 | } |
Nicolas Geoffray | 61b1dbe | 2015-10-01 10:27:52 +0100 | [diff] [blame] | 1752 | __ Str(source, destination); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 1753 | |
| 1754 | if (!may_need_runtime_call) { |
| 1755 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 1756 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1757 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 1758 | |
| 1759 | codegen_->MarkGCCard(array, value.W(), instruction->GetValueCanBeNull()); |
| 1760 | |
| 1761 | if (done.IsLinked()) { |
| 1762 | __ Bind(&done); |
| 1763 | } |
| 1764 | |
| 1765 | if (slow_path != nullptr) { |
| 1766 | __ Bind(slow_path->GetExitLabel()); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 1767 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1768 | } |
| 1769 | } |
| 1770 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1771 | void LocationsBuilderARM64::VisitBoundsCheck(HBoundsCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 1772 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 1773 | ? LocationSummary::kCallOnSlowPath |
| 1774 | : LocationSummary::kNoCall; |
| 1775 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1776 | locations->SetInAt(0, Location::RequiresRegister()); |
Serban Constantinescu | 760d8ef | 2015-03-28 18:09:56 +0000 | [diff] [blame] | 1777 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->InputAt(1), instruction)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1778 | if (instruction->HasUses()) { |
| 1779 | locations->SetOut(Location::SameAsFirstInput()); |
| 1780 | } |
| 1781 | } |
| 1782 | |
| 1783 | void InstructionCodeGeneratorARM64::VisitBoundsCheck(HBoundsCheck* instruction) { |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 1784 | BoundsCheckSlowPathARM64* slow_path = |
| 1785 | new (GetGraph()->GetArena()) BoundsCheckSlowPathARM64(instruction); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1786 | codegen_->AddSlowPath(slow_path); |
| 1787 | |
| 1788 | __ Cmp(InputRegisterAt(instruction, 0), InputOperandAt(instruction, 1)); |
| 1789 | __ B(slow_path->GetEntryLabel(), hs); |
| 1790 | } |
| 1791 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1792 | void LocationsBuilderARM64::VisitClinitCheck(HClinitCheck* check) { |
| 1793 | LocationSummary* locations = |
| 1794 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 1795 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1796 | if (check->HasUses()) { |
| 1797 | locations->SetOut(Location::SameAsFirstInput()); |
| 1798 | } |
| 1799 | } |
| 1800 | |
| 1801 | void InstructionCodeGeneratorARM64::VisitClinitCheck(HClinitCheck* check) { |
| 1802 | // We assume the class is not null. |
| 1803 | SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM64( |
| 1804 | check->GetLoadClass(), check, check->GetDexPc(), true); |
| 1805 | codegen_->AddSlowPath(slow_path); |
| 1806 | GenerateClassInitializationCheck(slow_path, InputRegisterAt(check, 0)); |
| 1807 | } |
| 1808 | |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 1809 | static bool IsFloatingPointZeroConstant(HInstruction* instruction) { |
| 1810 | return (instruction->IsFloatConstant() && (instruction->AsFloatConstant()->GetValue() == 0.0f)) |
| 1811 | || (instruction->IsDoubleConstant() && (instruction->AsDoubleConstant()->GetValue() == 0.0)); |
| 1812 | } |
| 1813 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1814 | void LocationsBuilderARM64::VisitCompare(HCompare* compare) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1815 | LocationSummary* locations = |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1816 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
| 1817 | Primitive::Type in_type = compare->InputAt(0)->GetType(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1818 | switch (in_type) { |
| 1819 | case Primitive::kPrimLong: { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1820 | locations->SetInAt(0, Location::RequiresRegister()); |
Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 1821 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(compare->InputAt(1), compare)); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1822 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1823 | break; |
| 1824 | } |
| 1825 | case Primitive::kPrimFloat: |
| 1826 | case Primitive::kPrimDouble: { |
| 1827 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 1828 | locations->SetInAt(1, |
| 1829 | IsFloatingPointZeroConstant(compare->InputAt(1)) |
| 1830 | ? Location::ConstantLocation(compare->InputAt(1)->AsConstant()) |
| 1831 | : Location::RequiresFpuRegister()); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1832 | locations->SetOut(Location::RequiresRegister()); |
| 1833 | break; |
| 1834 | } |
| 1835 | default: |
| 1836 | LOG(FATAL) << "Unexpected type for compare operation " << in_type; |
| 1837 | } |
| 1838 | } |
| 1839 | |
| 1840 | void InstructionCodeGeneratorARM64::VisitCompare(HCompare* compare) { |
| 1841 | Primitive::Type in_type = compare->InputAt(0)->GetType(); |
| 1842 | |
| 1843 | // 0 if: left == right |
| 1844 | // 1 if: left > right |
| 1845 | // -1 if: left < right |
| 1846 | switch (in_type) { |
| 1847 | case Primitive::kPrimLong: { |
| 1848 | Register result = OutputRegister(compare); |
| 1849 | Register left = InputRegisterAt(compare, 0); |
| 1850 | Operand right = InputOperandAt(compare, 1); |
| 1851 | |
| 1852 | __ Cmp(left, right); |
| 1853 | __ Cset(result, ne); |
| 1854 | __ Cneg(result, result, lt); |
| 1855 | break; |
| 1856 | } |
| 1857 | case Primitive::kPrimFloat: |
| 1858 | case Primitive::kPrimDouble: { |
| 1859 | Register result = OutputRegister(compare); |
| 1860 | FPRegister left = InputFPRegisterAt(compare, 0); |
Alexandre Rames | 9341546 | 2015-02-17 15:08:20 +0000 | [diff] [blame] | 1861 | if (compare->GetLocations()->InAt(1).IsConstant()) { |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 1862 | DCHECK(IsFloatingPointZeroConstant(compare->GetLocations()->InAt(1).GetConstant())); |
| 1863 | // 0.0 is the only immediate that can be encoded directly in an FCMP instruction. |
Alexandre Rames | 9341546 | 2015-02-17 15:08:20 +0000 | [diff] [blame] | 1864 | __ Fcmp(left, 0.0); |
| 1865 | } else { |
| 1866 | __ Fcmp(left, InputFPRegisterAt(compare, 1)); |
| 1867 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1868 | if (compare->IsGtBias()) { |
| 1869 | __ Cset(result, ne); |
| 1870 | } else { |
| 1871 | __ Csetm(result, ne); |
| 1872 | } |
| 1873 | __ Cneg(result, result, compare->IsGtBias() ? mi : gt); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1874 | break; |
| 1875 | } |
| 1876 | default: |
| 1877 | LOG(FATAL) << "Unimplemented compare type " << in_type; |
| 1878 | } |
| 1879 | } |
| 1880 | |
| 1881 | void LocationsBuilderARM64::VisitCondition(HCondition* instruction) { |
| 1882 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 1883 | |
| 1884 | if (Primitive::IsFloatingPointType(instruction->InputAt(0)->GetType())) { |
| 1885 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1886 | locations->SetInAt(1, |
| 1887 | IsFloatingPointZeroConstant(instruction->InputAt(1)) |
| 1888 | ? Location::ConstantLocation(instruction->InputAt(1)->AsConstant()) |
| 1889 | : Location::RequiresFpuRegister()); |
| 1890 | } else { |
| 1891 | // Integer cases. |
| 1892 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1893 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->InputAt(1), instruction)); |
| 1894 | } |
| 1895 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1896 | if (instruction->NeedsMaterialization()) { |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 1897 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1898 | } |
| 1899 | } |
| 1900 | |
| 1901 | void InstructionCodeGeneratorARM64::VisitCondition(HCondition* instruction) { |
| 1902 | if (!instruction->NeedsMaterialization()) { |
| 1903 | return; |
| 1904 | } |
| 1905 | |
| 1906 | LocationSummary* locations = instruction->GetLocations(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1907 | Register res = RegisterFrom(locations->Out(), instruction->GetType()); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 1908 | IfCondition if_cond = instruction->GetCondition(); |
| 1909 | Condition arm64_cond = ARM64Condition(if_cond); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1910 | |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 1911 | if (Primitive::IsFloatingPointType(instruction->InputAt(0)->GetType())) { |
| 1912 | FPRegister lhs = InputFPRegisterAt(instruction, 0); |
| 1913 | if (locations->InAt(1).IsConstant()) { |
| 1914 | DCHECK(IsFloatingPointZeroConstant(locations->InAt(1).GetConstant())); |
| 1915 | // 0.0 is the only immediate that can be encoded directly in an FCMP instruction. |
| 1916 | __ Fcmp(lhs, 0.0); |
| 1917 | } else { |
| 1918 | __ Fcmp(lhs, InputFPRegisterAt(instruction, 1)); |
| 1919 | } |
| 1920 | __ Cset(res, arm64_cond); |
| 1921 | if (instruction->IsFPConditionTrueIfNaN()) { |
| 1922 | // res = IsUnordered(arm64_cond) ? 1 : res <=> res = IsNotUnordered(arm64_cond) ? res : 1 |
| 1923 | __ Csel(res, res, Operand(1), vc); // VC for "not unordered". |
| 1924 | } else if (instruction->IsFPConditionFalseIfNaN()) { |
| 1925 | // res = IsUnordered(arm64_cond) ? 0 : res <=> res = IsNotUnordered(arm64_cond) ? res : 0 |
| 1926 | __ Csel(res, res, Operand(0), vc); // VC for "not unordered". |
| 1927 | } |
| 1928 | } else { |
| 1929 | // Integer cases. |
| 1930 | Register lhs = InputRegisterAt(instruction, 0); |
| 1931 | Operand rhs = InputOperandAt(instruction, 1); |
| 1932 | __ Cmp(lhs, rhs); |
| 1933 | __ Cset(res, arm64_cond); |
| 1934 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1935 | } |
| 1936 | |
| 1937 | #define FOR_EACH_CONDITION_INSTRUCTION(M) \ |
| 1938 | M(Equal) \ |
| 1939 | M(NotEqual) \ |
| 1940 | M(LessThan) \ |
| 1941 | M(LessThanOrEqual) \ |
| 1942 | M(GreaterThan) \ |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1943 | M(GreaterThanOrEqual) \ |
| 1944 | M(Below) \ |
| 1945 | M(BelowOrEqual) \ |
| 1946 | M(Above) \ |
| 1947 | M(AboveOrEqual) |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1948 | #define DEFINE_CONDITION_VISITORS(Name) \ |
| 1949 | void LocationsBuilderARM64::Visit##Name(H##Name* comp) { VisitCondition(comp); } \ |
| 1950 | void InstructionCodeGeneratorARM64::Visit##Name(H##Name* comp) { VisitCondition(comp); } |
| 1951 | FOR_EACH_CONDITION_INSTRUCTION(DEFINE_CONDITION_VISITORS) |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1952 | #undef DEFINE_CONDITION_VISITORS |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1953 | #undef FOR_EACH_CONDITION_INSTRUCTION |
| 1954 | |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 1955 | void InstructionCodeGeneratorARM64::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 1956 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 1957 | |
| 1958 | LocationSummary* locations = instruction->GetLocations(); |
| 1959 | Location second = locations->InAt(1); |
| 1960 | DCHECK(second.IsConstant()); |
| 1961 | |
| 1962 | Register out = OutputRegister(instruction); |
| 1963 | Register dividend = InputRegisterAt(instruction, 0); |
| 1964 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 1965 | DCHECK(imm == 1 || imm == -1); |
| 1966 | |
| 1967 | if (instruction->IsRem()) { |
| 1968 | __ Mov(out, 0); |
| 1969 | } else { |
| 1970 | if (imm == 1) { |
| 1971 | __ Mov(out, dividend); |
| 1972 | } else { |
| 1973 | __ Neg(out, dividend); |
| 1974 | } |
| 1975 | } |
| 1976 | } |
| 1977 | |
| 1978 | void InstructionCodeGeneratorARM64::DivRemByPowerOfTwo(HBinaryOperation* instruction) { |
| 1979 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 1980 | |
| 1981 | LocationSummary* locations = instruction->GetLocations(); |
| 1982 | Location second = locations->InAt(1); |
| 1983 | DCHECK(second.IsConstant()); |
| 1984 | |
| 1985 | Register out = OutputRegister(instruction); |
| 1986 | Register dividend = InputRegisterAt(instruction, 0); |
| 1987 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Vladimir Marko | 80afd02 | 2015-05-19 18:08:00 +0100 | [diff] [blame] | 1988 | uint64_t abs_imm = static_cast<uint64_t>(std::abs(imm)); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 1989 | DCHECK(IsPowerOfTwo(abs_imm)); |
| 1990 | int ctz_imm = CTZ(abs_imm); |
| 1991 | |
| 1992 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 1993 | Register temp = temps.AcquireSameSizeAs(out); |
| 1994 | |
| 1995 | if (instruction->IsDiv()) { |
| 1996 | __ Add(temp, dividend, abs_imm - 1); |
| 1997 | __ Cmp(dividend, 0); |
| 1998 | __ Csel(out, temp, dividend, lt); |
| 1999 | if (imm > 0) { |
| 2000 | __ Asr(out, out, ctz_imm); |
| 2001 | } else { |
| 2002 | __ Neg(out, Operand(out, ASR, ctz_imm)); |
| 2003 | } |
| 2004 | } else { |
| 2005 | int bits = instruction->GetResultType() == Primitive::kPrimInt ? 32 : 64; |
| 2006 | __ Asr(temp, dividend, bits - 1); |
| 2007 | __ Lsr(temp, temp, bits - ctz_imm); |
| 2008 | __ Add(out, dividend, temp); |
| 2009 | __ And(out, out, abs_imm - 1); |
| 2010 | __ Sub(out, out, temp); |
| 2011 | } |
| 2012 | } |
| 2013 | |
| 2014 | void InstructionCodeGeneratorARM64::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 2015 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2016 | |
| 2017 | LocationSummary* locations = instruction->GetLocations(); |
| 2018 | Location second = locations->InAt(1); |
| 2019 | DCHECK(second.IsConstant()); |
| 2020 | |
| 2021 | Register out = OutputRegister(instruction); |
| 2022 | Register dividend = InputRegisterAt(instruction, 0); |
| 2023 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 2024 | |
| 2025 | Primitive::Type type = instruction->GetResultType(); |
| 2026 | DCHECK(type == Primitive::kPrimInt || type == Primitive::kPrimLong); |
| 2027 | |
| 2028 | int64_t magic; |
| 2029 | int shift; |
| 2030 | CalculateMagicAndShiftForDivRem(imm, type == Primitive::kPrimLong /* is_long */, &magic, &shift); |
| 2031 | |
| 2032 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2033 | Register temp = temps.AcquireSameSizeAs(out); |
| 2034 | |
| 2035 | // temp = get_high(dividend * magic) |
| 2036 | __ Mov(temp, magic); |
| 2037 | if (type == Primitive::kPrimLong) { |
| 2038 | __ Smulh(temp, dividend, temp); |
| 2039 | } else { |
| 2040 | __ Smull(temp.X(), dividend, temp); |
| 2041 | __ Lsr(temp.X(), temp.X(), 32); |
| 2042 | } |
| 2043 | |
| 2044 | if (imm > 0 && magic < 0) { |
| 2045 | __ Add(temp, temp, dividend); |
| 2046 | } else if (imm < 0 && magic > 0) { |
| 2047 | __ Sub(temp, temp, dividend); |
| 2048 | } |
| 2049 | |
| 2050 | if (shift != 0) { |
| 2051 | __ Asr(temp, temp, shift); |
| 2052 | } |
| 2053 | |
| 2054 | if (instruction->IsDiv()) { |
| 2055 | __ Sub(out, temp, Operand(temp, ASR, type == Primitive::kPrimLong ? 63 : 31)); |
| 2056 | } else { |
| 2057 | __ Sub(temp, temp, Operand(temp, ASR, type == Primitive::kPrimLong ? 63 : 31)); |
| 2058 | // TODO: Strength reduction for msub. |
| 2059 | Register temp_imm = temps.AcquireSameSizeAs(out); |
| 2060 | __ Mov(temp_imm, imm); |
| 2061 | __ Msub(out, temp, temp_imm, dividend); |
| 2062 | } |
| 2063 | } |
| 2064 | |
| 2065 | void InstructionCodeGeneratorARM64::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 2066 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2067 | Primitive::Type type = instruction->GetResultType(); |
| 2068 | DCHECK(type == Primitive::kPrimInt || Primitive::kPrimLong); |
| 2069 | |
| 2070 | LocationSummary* locations = instruction->GetLocations(); |
| 2071 | Register out = OutputRegister(instruction); |
| 2072 | Location second = locations->InAt(1); |
| 2073 | |
| 2074 | if (second.IsConstant()) { |
| 2075 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 2076 | |
| 2077 | if (imm == 0) { |
| 2078 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 2079 | } else if (imm == 1 || imm == -1) { |
| 2080 | DivRemOneOrMinusOne(instruction); |
| 2081 | } else if (IsPowerOfTwo(std::abs(imm))) { |
| 2082 | DivRemByPowerOfTwo(instruction); |
| 2083 | } else { |
| 2084 | DCHECK(imm <= -2 || imm >= 2); |
| 2085 | GenerateDivRemWithAnyConstant(instruction); |
| 2086 | } |
| 2087 | } else { |
| 2088 | Register dividend = InputRegisterAt(instruction, 0); |
| 2089 | Register divisor = InputRegisterAt(instruction, 1); |
| 2090 | if (instruction->IsDiv()) { |
| 2091 | __ Sdiv(out, dividend, divisor); |
| 2092 | } else { |
| 2093 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2094 | Register temp = temps.AcquireSameSizeAs(out); |
| 2095 | __ Sdiv(temp, dividend, divisor); |
| 2096 | __ Msub(out, temp, divisor, dividend); |
| 2097 | } |
| 2098 | } |
| 2099 | } |
| 2100 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2101 | void LocationsBuilderARM64::VisitDiv(HDiv* div) { |
| 2102 | LocationSummary* locations = |
| 2103 | new (GetGraph()->GetArena()) LocationSummary(div, LocationSummary::kNoCall); |
| 2104 | switch (div->GetResultType()) { |
| 2105 | case Primitive::kPrimInt: |
| 2106 | case Primitive::kPrimLong: |
| 2107 | locations->SetInAt(0, Location::RequiresRegister()); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2108 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2109 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2110 | break; |
| 2111 | |
| 2112 | case Primitive::kPrimFloat: |
| 2113 | case Primitive::kPrimDouble: |
| 2114 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2115 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2116 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 2117 | break; |
| 2118 | |
| 2119 | default: |
| 2120 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 2121 | } |
| 2122 | } |
| 2123 | |
| 2124 | void InstructionCodeGeneratorARM64::VisitDiv(HDiv* div) { |
| 2125 | Primitive::Type type = div->GetResultType(); |
| 2126 | switch (type) { |
| 2127 | case Primitive::kPrimInt: |
| 2128 | case Primitive::kPrimLong: |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2129 | GenerateDivRemIntegral(div); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2130 | break; |
| 2131 | |
| 2132 | case Primitive::kPrimFloat: |
| 2133 | case Primitive::kPrimDouble: |
| 2134 | __ Fdiv(OutputFPRegister(div), InputFPRegisterAt(div, 0), InputFPRegisterAt(div, 1)); |
| 2135 | break; |
| 2136 | |
| 2137 | default: |
| 2138 | LOG(FATAL) << "Unexpected div type " << type; |
| 2139 | } |
| 2140 | } |
| 2141 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2142 | void LocationsBuilderARM64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2143 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 2144 | ? LocationSummary::kCallOnSlowPath |
| 2145 | : LocationSummary::kNoCall; |
| 2146 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2147 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
| 2148 | if (instruction->HasUses()) { |
| 2149 | locations->SetOut(Location::SameAsFirstInput()); |
| 2150 | } |
| 2151 | } |
| 2152 | |
| 2153 | void InstructionCodeGeneratorARM64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 2154 | SlowPathCodeARM64* slow_path = |
| 2155 | new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM64(instruction); |
| 2156 | codegen_->AddSlowPath(slow_path); |
| 2157 | Location value = instruction->GetLocations()->InAt(0); |
| 2158 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 2159 | Primitive::Type type = instruction->GetType(); |
| 2160 | |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 2161 | if ((type == Primitive::kPrimBoolean) || !Primitive::IsIntegralType(type)) { |
| 2162 | LOG(FATAL) << "Unexpected type " << type << " for DivZeroCheck."; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 2163 | return; |
| 2164 | } |
| 2165 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2166 | if (value.IsConstant()) { |
| 2167 | int64_t divisor = Int64ConstantFrom(value); |
| 2168 | if (divisor == 0) { |
| 2169 | __ B(slow_path->GetEntryLabel()); |
| 2170 | } else { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 2171 | // A division by a non-null constant is valid. We don't need to perform |
| 2172 | // any check, so simply fall through. |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2173 | } |
| 2174 | } else { |
| 2175 | __ Cbz(InputRegisterAt(instruction, 0), slow_path->GetEntryLabel()); |
| 2176 | } |
| 2177 | } |
| 2178 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2179 | void LocationsBuilderARM64::VisitDoubleConstant(HDoubleConstant* constant) { |
| 2180 | LocationSummary* locations = |
| 2181 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 2182 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2183 | } |
| 2184 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2185 | void InstructionCodeGeneratorARM64::VisitDoubleConstant( |
| 2186 | HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2187 | // Will be generated at use site. |
| 2188 | } |
| 2189 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2190 | void LocationsBuilderARM64::VisitExit(HExit* exit) { |
| 2191 | exit->SetLocations(nullptr); |
| 2192 | } |
| 2193 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2194 | void InstructionCodeGeneratorARM64::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2195 | } |
| 2196 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2197 | void LocationsBuilderARM64::VisitFloatConstant(HFloatConstant* constant) { |
| 2198 | LocationSummary* locations = |
| 2199 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 2200 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2201 | } |
| 2202 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2203 | void InstructionCodeGeneratorARM64::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2204 | // Will be generated at use site. |
| 2205 | } |
| 2206 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2207 | void InstructionCodeGeneratorARM64::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2208 | DCHECK(!successor->IsExitBlock()); |
| 2209 | HBasicBlock* block = got->GetBlock(); |
| 2210 | HInstruction* previous = got->GetPrevious(); |
| 2211 | HLoopInformation* info = block->GetLoopInformation(); |
| 2212 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2213 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2214 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck()); |
| 2215 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 2216 | return; |
| 2217 | } |
| 2218 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 2219 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 2220 | } |
| 2221 | if (!codegen_->GoesToNextBlock(block, successor)) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2222 | __ B(codegen_->GetLabelOf(successor)); |
| 2223 | } |
| 2224 | } |
| 2225 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2226 | void LocationsBuilderARM64::VisitGoto(HGoto* got) { |
| 2227 | got->SetLocations(nullptr); |
| 2228 | } |
| 2229 | |
| 2230 | void InstructionCodeGeneratorARM64::VisitGoto(HGoto* got) { |
| 2231 | HandleGoto(got, got->GetSuccessor()); |
| 2232 | } |
| 2233 | |
| 2234 | void LocationsBuilderARM64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 2235 | try_boundary->SetLocations(nullptr); |
| 2236 | } |
| 2237 | |
| 2238 | void InstructionCodeGeneratorARM64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 2239 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 2240 | if (!successor->IsExitBlock()) { |
| 2241 | HandleGoto(try_boundary, successor); |
| 2242 | } |
| 2243 | } |
| 2244 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2245 | void InstructionCodeGeneratorARM64::GenerateTestAndBranch(HInstruction* instruction, |
| 2246 | vixl::Label* true_target, |
| 2247 | vixl::Label* false_target, |
| 2248 | vixl::Label* always_true_target) { |
| 2249 | HInstruction* cond = instruction->InputAt(0); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2250 | HCondition* condition = cond->AsCondition(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2251 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2252 | if (cond->IsIntConstant()) { |
| 2253 | int32_t cond_value = cond->AsIntConstant()->GetValue(); |
| 2254 | if (cond_value == 1) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2255 | if (always_true_target != nullptr) { |
| 2256 | __ B(always_true_target); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2257 | } |
| 2258 | return; |
| 2259 | } else { |
| 2260 | DCHECK_EQ(cond_value, 0); |
| 2261 | } |
| 2262 | } else if (!cond->IsCondition() || condition->NeedsMaterialization()) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2263 | // The condition instruction has been materialized, compare the output to 0. |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2264 | Location cond_val = instruction->GetLocations()->InAt(0); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2265 | DCHECK(cond_val.IsRegister()); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2266 | __ Cbnz(InputRegisterAt(instruction, 0), true_target); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2267 | } else { |
| 2268 | // The condition instruction has not been materialized, use its inputs as |
| 2269 | // the comparison and its condition as the branch condition. |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2270 | Primitive::Type type = |
| 2271 | cond->IsCondition() ? cond->InputAt(0)->GetType() : Primitive::kPrimInt; |
| 2272 | |
| 2273 | if (Primitive::IsFloatingPointType(type)) { |
| 2274 | // FP compares don't like null false_targets. |
| 2275 | if (false_target == nullptr) { |
| 2276 | false_target = codegen_->GetLabelOf(instruction->AsIf()->IfFalseSuccessor()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2277 | } |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2278 | FPRegister lhs = InputFPRegisterAt(condition, 0); |
| 2279 | if (condition->GetLocations()->InAt(1).IsConstant()) { |
| 2280 | DCHECK(IsFloatingPointZeroConstant(condition->GetLocations()->InAt(1).GetConstant())); |
| 2281 | // 0.0 is the only immediate that can be encoded directly in an FCMP instruction. |
| 2282 | __ Fcmp(lhs, 0.0); |
| 2283 | } else { |
| 2284 | __ Fcmp(lhs, InputFPRegisterAt(condition, 1)); |
| 2285 | } |
| 2286 | if (condition->IsFPConditionTrueIfNaN()) { |
| 2287 | __ B(vs, true_target); // VS for unordered. |
| 2288 | } else if (condition->IsFPConditionFalseIfNaN()) { |
| 2289 | __ B(vs, false_target); // VS for unordered. |
| 2290 | } |
| 2291 | __ B(ARM64Condition(condition->GetCondition()), true_target); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2292 | } else { |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2293 | // Integer cases. |
| 2294 | Register lhs = InputRegisterAt(condition, 0); |
| 2295 | Operand rhs = InputOperandAt(condition, 1); |
| 2296 | Condition arm64_cond = ARM64Condition(condition->GetCondition()); |
| 2297 | if ((arm64_cond != gt && arm64_cond != le) && rhs.IsImmediate() && (rhs.immediate() == 0)) { |
| 2298 | switch (arm64_cond) { |
| 2299 | case eq: |
| 2300 | __ Cbz(lhs, true_target); |
| 2301 | break; |
| 2302 | case ne: |
| 2303 | __ Cbnz(lhs, true_target); |
| 2304 | break; |
| 2305 | case lt: |
| 2306 | // Test the sign bit and branch accordingly. |
| 2307 | __ Tbnz(lhs, (lhs.IsX() ? kXRegSize : kWRegSize) - 1, true_target); |
| 2308 | break; |
| 2309 | case ge: |
| 2310 | // Test the sign bit and branch accordingly. |
| 2311 | __ Tbz(lhs, (lhs.IsX() ? kXRegSize : kWRegSize) - 1, true_target); |
| 2312 | break; |
| 2313 | default: |
| 2314 | // Without the `static_cast` the compiler throws an error for |
| 2315 | // `-Werror=sign-promo`. |
| 2316 | LOG(FATAL) << "Unexpected condition: " << static_cast<int>(arm64_cond); |
| 2317 | } |
| 2318 | } else { |
| 2319 | __ Cmp(lhs, rhs); |
| 2320 | __ B(arm64_cond, true_target); |
| 2321 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2322 | } |
| 2323 | } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2324 | if (false_target != nullptr) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2325 | __ B(false_target); |
| 2326 | } |
| 2327 | } |
| 2328 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2329 | void LocationsBuilderARM64::VisitIf(HIf* if_instr) { |
| 2330 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); |
| 2331 | HInstruction* cond = if_instr->InputAt(0); |
| 2332 | if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) { |
| 2333 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2334 | } |
| 2335 | } |
| 2336 | |
| 2337 | void InstructionCodeGeneratorARM64::VisitIf(HIf* if_instr) { |
| 2338 | vixl::Label* true_target = codegen_->GetLabelOf(if_instr->IfTrueSuccessor()); |
| 2339 | vixl::Label* false_target = codegen_->GetLabelOf(if_instr->IfFalseSuccessor()); |
| 2340 | vixl::Label* always_true_target = true_target; |
| 2341 | if (codegen_->GoesToNextBlock(if_instr->GetBlock(), |
| 2342 | if_instr->IfTrueSuccessor())) { |
| 2343 | always_true_target = nullptr; |
| 2344 | } |
| 2345 | if (codegen_->GoesToNextBlock(if_instr->GetBlock(), |
| 2346 | if_instr->IfFalseSuccessor())) { |
| 2347 | false_target = nullptr; |
| 2348 | } |
| 2349 | GenerateTestAndBranch(if_instr, true_target, false_target, always_true_target); |
| 2350 | } |
| 2351 | |
| 2352 | void LocationsBuilderARM64::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 2353 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 2354 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
| 2355 | HInstruction* cond = deoptimize->InputAt(0); |
Aart Bik | bb245d1 | 2015-10-19 11:05:03 -0700 | [diff] [blame] | 2356 | if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2357 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2358 | } |
| 2359 | } |
| 2360 | |
| 2361 | void InstructionCodeGeneratorARM64::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 2362 | SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) |
| 2363 | DeoptimizationSlowPathARM64(deoptimize); |
| 2364 | codegen_->AddSlowPath(slow_path); |
| 2365 | vixl::Label* slow_path_entry = slow_path->GetEntryLabel(); |
| 2366 | GenerateTestAndBranch(deoptimize, slow_path_entry, nullptr, slow_path_entry); |
| 2367 | } |
| 2368 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2369 | void LocationsBuilderARM64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2370 | HandleFieldGet(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2371 | } |
| 2372 | |
| 2373 | void InstructionCodeGeneratorARM64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2374 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2375 | } |
| 2376 | |
| 2377 | void LocationsBuilderARM64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2378 | HandleFieldSet(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2379 | } |
| 2380 | |
| 2381 | void InstructionCodeGeneratorARM64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 2382 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2383 | } |
| 2384 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2385 | void LocationsBuilderARM64::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 2386 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 2387 | switch (instruction->GetTypeCheckKind()) { |
| 2388 | case TypeCheckKind::kExactCheck: |
| 2389 | case TypeCheckKind::kAbstractClassCheck: |
| 2390 | case TypeCheckKind::kClassHierarchyCheck: |
| 2391 | case TypeCheckKind::kArrayObjectCheck: |
| 2392 | call_kind = LocationSummary::kNoCall; |
| 2393 | break; |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 2394 | case TypeCheckKind::kUnresolvedCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 2395 | case TypeCheckKind::kInterfaceCheck: |
| 2396 | call_kind = LocationSummary::kCall; |
| 2397 | break; |
| 2398 | case TypeCheckKind::kArrayCheck: |
| 2399 | call_kind = LocationSummary::kCallOnSlowPath; |
| 2400 | break; |
| 2401 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2402 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 2403 | if (call_kind != LocationSummary::kCall) { |
| 2404 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2405 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2406 | // The out register is used as a temporary, so it overlaps with the inputs. |
| 2407 | // Note that TypeCheckSlowPathARM64 uses this register too. |
| 2408 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 2409 | } else { |
| 2410 | InvokeRuntimeCallingConvention calling_convention; |
| 2411 | locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 2412 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(1))); |
| 2413 | locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimInt)); |
| 2414 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2415 | } |
| 2416 | |
| 2417 | void InstructionCodeGeneratorARM64::VisitInstanceOf(HInstanceOf* instruction) { |
| 2418 | LocationSummary* locations = instruction->GetLocations(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 2419 | Register obj = InputRegisterAt(instruction, 0); |
| 2420 | Register cls = InputRegisterAt(instruction, 1); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2421 | Register out = OutputRegister(instruction); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 2422 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2423 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 2424 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 2425 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2426 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 2427 | vixl::Label done, zero; |
| 2428 | SlowPathCodeARM64* slow_path = nullptr; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2429 | |
| 2430 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 2431 | // Avoid null check if we know `obj` is not null. |
| 2432 | if (instruction->MustDoNullCheck()) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 2433 | __ Cbz(obj, &zero); |
| 2434 | } |
| 2435 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 2436 | // In case of an interface/unresolved check, we put the object class into the object register. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 2437 | // This is safe, as the register is caller-save, and the object must be in another |
| 2438 | // register if it survives the runtime call. |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 2439 | Register target = (instruction->GetTypeCheckKind() == TypeCheckKind::kInterfaceCheck) || |
| 2440 | (instruction->GetTypeCheckKind() == TypeCheckKind::kUnresolvedCheck) |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 2441 | ? obj |
| 2442 | : out; |
| 2443 | __ Ldr(target, HeapOperand(obj.W(), class_offset)); |
| 2444 | GetAssembler()->MaybeUnpoisonHeapReference(target); |
| 2445 | |
| 2446 | switch (instruction->GetTypeCheckKind()) { |
| 2447 | case TypeCheckKind::kExactCheck: { |
| 2448 | __ Cmp(out, cls); |
| 2449 | __ Cset(out, eq); |
| 2450 | if (zero.IsLinked()) { |
| 2451 | __ B(&done); |
| 2452 | } |
| 2453 | break; |
| 2454 | } |
| 2455 | case TypeCheckKind::kAbstractClassCheck: { |
| 2456 | // If the class is abstract, we eagerly fetch the super class of the |
| 2457 | // object to avoid doing a comparison we know will fail. |
| 2458 | vixl::Label loop, success; |
| 2459 | __ Bind(&loop); |
| 2460 | __ Ldr(out, HeapOperand(out, super_offset)); |
| 2461 | GetAssembler()->MaybeUnpoisonHeapReference(out); |
| 2462 | // If `out` is null, we use it for the result, and jump to `done`. |
| 2463 | __ Cbz(out, &done); |
| 2464 | __ Cmp(out, cls); |
| 2465 | __ B(ne, &loop); |
| 2466 | __ Mov(out, 1); |
| 2467 | if (zero.IsLinked()) { |
| 2468 | __ B(&done); |
| 2469 | } |
| 2470 | break; |
| 2471 | } |
| 2472 | case TypeCheckKind::kClassHierarchyCheck: { |
| 2473 | // Walk over the class hierarchy to find a match. |
| 2474 | vixl::Label loop, success; |
| 2475 | __ Bind(&loop); |
| 2476 | __ Cmp(out, cls); |
| 2477 | __ B(eq, &success); |
| 2478 | __ Ldr(out, HeapOperand(out, super_offset)); |
| 2479 | GetAssembler()->MaybeUnpoisonHeapReference(out); |
| 2480 | __ Cbnz(out, &loop); |
| 2481 | // If `out` is null, we use it for the result, and jump to `done`. |
| 2482 | __ B(&done); |
| 2483 | __ Bind(&success); |
| 2484 | __ Mov(out, 1); |
| 2485 | if (zero.IsLinked()) { |
| 2486 | __ B(&done); |
| 2487 | } |
| 2488 | break; |
| 2489 | } |
| 2490 | case TypeCheckKind::kArrayObjectCheck: { |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 2491 | // Do an exact check. |
| 2492 | vixl::Label exact_check; |
| 2493 | __ Cmp(out, cls); |
| 2494 | __ B(eq, &exact_check); |
| 2495 | // Otherwise, we need to check that the object's class is a non primitive array. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 2496 | __ Ldr(out, HeapOperand(out, component_offset)); |
| 2497 | GetAssembler()->MaybeUnpoisonHeapReference(out); |
| 2498 | // If `out` is null, we use it for the result, and jump to `done`. |
| 2499 | __ Cbz(out, &done); |
| 2500 | __ Ldrh(out, HeapOperand(out, primitive_offset)); |
| 2501 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
| 2502 | __ Cbnz(out, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 2503 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 2504 | __ Mov(out, 1); |
| 2505 | __ B(&done); |
| 2506 | break; |
| 2507 | } |
| 2508 | case TypeCheckKind::kArrayCheck: { |
| 2509 | __ Cmp(out, cls); |
| 2510 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 2511 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM64( |
| 2512 | instruction, /* is_fatal */ false); |
| 2513 | codegen_->AddSlowPath(slow_path); |
| 2514 | __ B(ne, slow_path->GetEntryLabel()); |
| 2515 | __ Mov(out, 1); |
| 2516 | if (zero.IsLinked()) { |
| 2517 | __ B(&done); |
| 2518 | } |
| 2519 | break; |
| 2520 | } |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 2521 | case TypeCheckKind::kUnresolvedCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 2522 | case TypeCheckKind::kInterfaceCheck: |
| 2523 | default: { |
| 2524 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pInstanceofNonTrivial), |
| 2525 | instruction, |
| 2526 | instruction->GetDexPc(), |
| 2527 | nullptr); |
| 2528 | if (zero.IsLinked()) { |
| 2529 | __ B(&done); |
| 2530 | } |
| 2531 | break; |
| 2532 | } |
| 2533 | } |
| 2534 | |
| 2535 | if (zero.IsLinked()) { |
| 2536 | __ Bind(&zero); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 2537 | __ Mov(out, 0); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 2538 | } |
| 2539 | |
| 2540 | if (done.IsLinked()) { |
| 2541 | __ Bind(&done); |
| 2542 | } |
| 2543 | |
| 2544 | if (slow_path != nullptr) { |
| 2545 | __ Bind(slow_path->GetExitLabel()); |
| 2546 | } |
| 2547 | } |
| 2548 | |
| 2549 | void LocationsBuilderARM64::VisitCheckCast(HCheckCast* instruction) { |
| 2550 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 2551 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
| 2552 | |
| 2553 | switch (instruction->GetTypeCheckKind()) { |
| 2554 | case TypeCheckKind::kExactCheck: |
| 2555 | case TypeCheckKind::kAbstractClassCheck: |
| 2556 | case TypeCheckKind::kClassHierarchyCheck: |
| 2557 | case TypeCheckKind::kArrayObjectCheck: |
| 2558 | call_kind = throws_into_catch |
| 2559 | ? LocationSummary::kCallOnSlowPath |
| 2560 | : LocationSummary::kNoCall; |
| 2561 | break; |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 2562 | case TypeCheckKind::kUnresolvedCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 2563 | case TypeCheckKind::kInterfaceCheck: |
| 2564 | call_kind = LocationSummary::kCall; |
| 2565 | break; |
| 2566 | case TypeCheckKind::kArrayCheck: |
| 2567 | call_kind = LocationSummary::kCallOnSlowPath; |
| 2568 | break; |
| 2569 | } |
| 2570 | |
| 2571 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 2572 | instruction, call_kind); |
| 2573 | if (call_kind != LocationSummary::kCall) { |
| 2574 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2575 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2576 | // Note that TypeCheckSlowPathARM64 uses this register too. |
| 2577 | locations->AddTemp(Location::RequiresRegister()); |
| 2578 | } else { |
| 2579 | InvokeRuntimeCallingConvention calling_convention; |
| 2580 | locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 2581 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(1))); |
| 2582 | } |
| 2583 | } |
| 2584 | |
| 2585 | void InstructionCodeGeneratorARM64::VisitCheckCast(HCheckCast* instruction) { |
| 2586 | LocationSummary* locations = instruction->GetLocations(); |
| 2587 | Register obj = InputRegisterAt(instruction, 0); |
| 2588 | Register cls = InputRegisterAt(instruction, 1); |
| 2589 | Register temp; |
| 2590 | if (!locations->WillCall()) { |
| 2591 | temp = WRegisterFrom(instruction->GetLocations()->GetTemp(0)); |
| 2592 | } |
| 2593 | |
| 2594 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2595 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 2596 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 2597 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 2598 | SlowPathCodeARM64* slow_path = nullptr; |
| 2599 | |
| 2600 | if (!locations->WillCall()) { |
| 2601 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM64( |
| 2602 | instruction, !locations->CanCall()); |
| 2603 | codegen_->AddSlowPath(slow_path); |
| 2604 | } |
| 2605 | |
| 2606 | vixl::Label done; |
| 2607 | // Avoid null check if we know obj is not null. |
| 2608 | if (instruction->MustDoNullCheck()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 2609 | __ Cbz(obj, &done); |
| 2610 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2611 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 2612 | if (locations->WillCall()) { |
| 2613 | __ Ldr(obj, HeapOperand(obj, class_offset)); |
| 2614 | GetAssembler()->MaybeUnpoisonHeapReference(obj); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2615 | } else { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 2616 | __ Ldr(temp, HeapOperand(obj, class_offset)); |
| 2617 | GetAssembler()->MaybeUnpoisonHeapReference(temp); |
Nicolas Geoffray | 64acf30 | 2015-09-14 22:20:29 +0100 | [diff] [blame] | 2618 | } |
Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame] | 2619 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 2620 | switch (instruction->GetTypeCheckKind()) { |
| 2621 | case TypeCheckKind::kExactCheck: |
| 2622 | case TypeCheckKind::kArrayCheck: { |
| 2623 | __ Cmp(temp, cls); |
| 2624 | // Jump to slow path for throwing the exception or doing a |
| 2625 | // more involved array check. |
| 2626 | __ B(ne, slow_path->GetEntryLabel()); |
| 2627 | break; |
| 2628 | } |
| 2629 | case TypeCheckKind::kAbstractClassCheck: { |
| 2630 | // If the class is abstract, we eagerly fetch the super class of the |
| 2631 | // object to avoid doing a comparison we know will fail. |
| 2632 | vixl::Label loop; |
| 2633 | __ Bind(&loop); |
| 2634 | __ Ldr(temp, HeapOperand(temp, super_offset)); |
| 2635 | GetAssembler()->MaybeUnpoisonHeapReference(temp); |
| 2636 | // Jump to the slow path to throw the exception. |
| 2637 | __ Cbz(temp, slow_path->GetEntryLabel()); |
| 2638 | __ Cmp(temp, cls); |
| 2639 | __ B(ne, &loop); |
| 2640 | break; |
| 2641 | } |
| 2642 | case TypeCheckKind::kClassHierarchyCheck: { |
| 2643 | // Walk over the class hierarchy to find a match. |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 2644 | vixl::Label loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 2645 | __ Bind(&loop); |
| 2646 | __ Cmp(temp, cls); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 2647 | __ B(eq, &done); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 2648 | __ Ldr(temp, HeapOperand(temp, super_offset)); |
| 2649 | GetAssembler()->MaybeUnpoisonHeapReference(temp); |
| 2650 | __ Cbnz(temp, &loop); |
| 2651 | // Jump to the slow path to throw the exception. |
| 2652 | __ B(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 2653 | break; |
| 2654 | } |
| 2655 | case TypeCheckKind::kArrayObjectCheck: { |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 2656 | // Do an exact check. |
| 2657 | __ Cmp(temp, cls); |
| 2658 | __ B(eq, &done); |
| 2659 | // Otherwise, we need to check that the object's class is a non primitive array. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 2660 | __ Ldr(temp, HeapOperand(temp, component_offset)); |
| 2661 | GetAssembler()->MaybeUnpoisonHeapReference(temp); |
| 2662 | __ Cbz(temp, slow_path->GetEntryLabel()); |
| 2663 | __ Ldrh(temp, HeapOperand(temp, primitive_offset)); |
| 2664 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
| 2665 | __ Cbnz(temp, slow_path->GetEntryLabel()); |
| 2666 | break; |
| 2667 | } |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 2668 | case TypeCheckKind::kUnresolvedCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 2669 | case TypeCheckKind::kInterfaceCheck: |
| 2670 | default: |
| 2671 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pCheckCast), |
| 2672 | instruction, |
| 2673 | instruction->GetDexPc(), |
| 2674 | nullptr); |
| 2675 | break; |
| 2676 | } |
Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame] | 2677 | __ Bind(&done); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 2678 | |
| 2679 | if (slow_path != nullptr) { |
| 2680 | __ Bind(slow_path->GetExitLabel()); |
| 2681 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2682 | } |
| 2683 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2684 | void LocationsBuilderARM64::VisitIntConstant(HIntConstant* constant) { |
| 2685 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant); |
| 2686 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2687 | } |
| 2688 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2689 | void InstructionCodeGeneratorARM64::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2690 | // Will be generated at use site. |
| 2691 | } |
| 2692 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2693 | void LocationsBuilderARM64::VisitNullConstant(HNullConstant* constant) { |
| 2694 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant); |
| 2695 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2696 | } |
| 2697 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2698 | void InstructionCodeGeneratorARM64::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2699 | // Will be generated at use site. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2700 | } |
| 2701 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 2702 | void LocationsBuilderARM64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2703 | // The trampoline uses the same calling convention as dex calling conventions, |
| 2704 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 2705 | // the method_idx. |
| 2706 | HandleInvoke(invoke); |
| 2707 | } |
| 2708 | |
| 2709 | void InstructionCodeGeneratorARM64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2710 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 2711 | } |
| 2712 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2713 | void LocationsBuilderARM64::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2714 | InvokeDexCallingConventionVisitorARM64 calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2715 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2716 | } |
| 2717 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2718 | void LocationsBuilderARM64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2719 | HandleInvoke(invoke); |
| 2720 | } |
| 2721 | |
| 2722 | void InstructionCodeGeneratorARM64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2723 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2724 | Register temp = XRegisterFrom(invoke->GetLocations()->GetTemp(0)); |
| 2725 | uint32_t method_offset = mirror::Class::EmbeddedImTableEntryOffset( |
| 2726 | invoke->GetImtIndex() % mirror::Class::kImtSize, kArm64PointerSize).Uint32Value(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2727 | Location receiver = invoke->GetLocations()->InAt(0); |
| 2728 | Offset class_offset = mirror::Object::ClassOffset(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2729 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64WordSize); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2730 | |
| 2731 | // The register ip1 is required to be used for the hidden argument in |
| 2732 | // art_quick_imt_conflict_trampoline, so prevent VIXL from using it. |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 2733 | MacroAssembler* masm = GetVIXLAssembler(); |
| 2734 | UseScratchRegisterScope scratch_scope(masm); |
| 2735 | BlockPoolsScope block_pools(masm); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2736 | scratch_scope.Exclude(ip1); |
| 2737 | __ Mov(ip1, invoke->GetDexMethodIndex()); |
| 2738 | |
| 2739 | // temp = object->GetClass(); |
| 2740 | if (receiver.IsStackSlot()) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2741 | __ Ldr(temp.W(), StackOperandFrom(receiver)); |
| 2742 | __ Ldr(temp.W(), HeapOperand(temp.W(), class_offset)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2743 | } else { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2744 | __ Ldr(temp.W(), HeapOperandFrom(receiver, class_offset)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2745 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 2746 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2747 | GetAssembler()->MaybeUnpoisonHeapReference(temp.W()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2748 | // temp = temp->GetImtEntryAt(method_offset); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2749 | __ Ldr(temp, MemOperand(temp, method_offset)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2750 | // lr = temp->GetEntryPoint(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2751 | __ Ldr(lr, MemOperand(temp, entry_point.Int32Value())); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2752 | // lr(); |
| 2753 | __ Blr(lr); |
| 2754 | DCHECK(!codegen_->IsLeafMethod()); |
| 2755 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 2756 | } |
| 2757 | |
| 2758 | void LocationsBuilderARM64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 2759 | IntrinsicLocationsBuilderARM64 intrinsic(GetGraph()->GetArena()); |
| 2760 | if (intrinsic.TryDispatch(invoke)) { |
| 2761 | return; |
| 2762 | } |
| 2763 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2764 | HandleInvoke(invoke); |
| 2765 | } |
| 2766 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2767 | void LocationsBuilderARM64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 2768 | // When we do not run baseline, explicit clinit checks triggered by static |
| 2769 | // invokes must have been pruned by art::PrepareForRegisterAllocation. |
| 2770 | DCHECK(codegen_->IsBaseline() || !invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2771 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 2772 | IntrinsicLocationsBuilderARM64 intrinsic(GetGraph()->GetArena()); |
| 2773 | if (intrinsic.TryDispatch(invoke)) { |
| 2774 | return; |
| 2775 | } |
| 2776 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2777 | HandleInvoke(invoke); |
| 2778 | } |
| 2779 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 2780 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARM64* codegen) { |
| 2781 | if (invoke->GetLocations()->Intrinsified()) { |
| 2782 | IntrinsicCodeGeneratorARM64 intrinsic(codegen); |
| 2783 | intrinsic.Dispatch(invoke); |
| 2784 | return true; |
| 2785 | } |
| 2786 | return false; |
| 2787 | } |
| 2788 | |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 2789 | void CodeGeneratorARM64::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 2790 | // For better instruction scheduling we load the direct code pointer before the method pointer. |
| 2791 | bool direct_code_loaded = false; |
| 2792 | switch (invoke->GetCodePtrLocation()) { |
| 2793 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 2794 | // LR = code address from literal pool with link-time patch. |
| 2795 | __ Ldr(lr, DeduplicateMethodCodeLiteral(invoke->GetTargetMethod())); |
| 2796 | direct_code_loaded = true; |
| 2797 | break; |
| 2798 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
| 2799 | // LR = invoke->GetDirectCodePtr(); |
| 2800 | __ Ldr(lr, DeduplicateUint64Literal(invoke->GetDirectCodePtr())); |
| 2801 | direct_code_loaded = true; |
| 2802 | break; |
| 2803 | default: |
| 2804 | break; |
| 2805 | } |
| 2806 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 2807 | // 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] | 2808 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 2809 | switch (invoke->GetMethodLoadKind()) { |
| 2810 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: |
| 2811 | // temp = thread->string_init_entrypoint |
| 2812 | __ Ldr(XRegisterFrom(temp).X(), MemOperand(tr, invoke->GetStringInitOffset())); |
| 2813 | break; |
| 2814 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
| 2815 | callee_method = invoke->GetLocations()->InAt(invoke->GetCurrentMethodInputIndex()); |
| 2816 | break; |
| 2817 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 2818 | // Load method address from literal pool. |
| 2819 | __ Ldr(XRegisterFrom(temp).X(), DeduplicateUint64Literal(invoke->GetMethodAddress())); |
| 2820 | break; |
| 2821 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup: |
| 2822 | // Load method address from literal pool with a link-time patch. |
| 2823 | __ Ldr(XRegisterFrom(temp).X(), |
| 2824 | DeduplicateMethodAddressLiteral(invoke->GetTargetMethod())); |
| 2825 | break; |
| 2826 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: { |
| 2827 | // Add ADRP with its PC-relative DexCache access patch. |
| 2828 | pc_rel_dex_cache_patches_.emplace_back(*invoke->GetTargetMethod().dex_file, |
| 2829 | invoke->GetDexCacheArrayOffset()); |
| 2830 | vixl::Label* pc_insn_label = &pc_rel_dex_cache_patches_.back().label; |
| 2831 | { |
| 2832 | vixl::SingleEmissionCheckScope guard(GetVIXLAssembler()); |
| 2833 | __ adrp(XRegisterFrom(temp).X(), 0); |
| 2834 | } |
| 2835 | __ Bind(pc_insn_label); // Bind after ADRP. |
| 2836 | pc_rel_dex_cache_patches_.back().pc_insn_label = pc_insn_label; |
| 2837 | // Add LDR with its PC-relative DexCache access patch. |
| 2838 | pc_rel_dex_cache_patches_.emplace_back(*invoke->GetTargetMethod().dex_file, |
| 2839 | invoke->GetDexCacheArrayOffset()); |
| 2840 | __ Ldr(XRegisterFrom(temp).X(), MemOperand(XRegisterFrom(temp).X(), 0)); |
| 2841 | __ Bind(&pc_rel_dex_cache_patches_.back().label); // Bind after LDR. |
| 2842 | pc_rel_dex_cache_patches_.back().pc_insn_label = pc_insn_label; |
| 2843 | break; |
Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 2844 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 2845 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: { |
| 2846 | Location current_method = invoke->GetLocations()->InAt(invoke->GetCurrentMethodInputIndex()); |
| 2847 | Register reg = XRegisterFrom(temp); |
| 2848 | Register method_reg; |
| 2849 | if (current_method.IsRegister()) { |
| 2850 | method_reg = XRegisterFrom(current_method); |
| 2851 | } else { |
| 2852 | DCHECK(invoke->GetLocations()->Intrinsified()); |
| 2853 | DCHECK(!current_method.IsValid()); |
| 2854 | method_reg = reg; |
| 2855 | __ Ldr(reg.X(), MemOperand(sp, kCurrentMethodStackOffset)); |
| 2856 | } |
Vladimir Marko | b2c431e | 2015-08-19 12:45:42 +0000 | [diff] [blame] | 2857 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 2858 | // temp = current_method->dex_cache_resolved_methods_; |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 2859 | __ Ldr(reg.X(), |
| 2860 | MemOperand(method_reg.X(), |
| 2861 | ArtMethod::DexCacheResolvedMethodsOffset(kArm64WordSize).Int32Value())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 2862 | // temp = temp[index_in_cache]; |
| 2863 | uint32_t index_in_cache = invoke->GetTargetMethod().dex_method_index; |
| 2864 | __ Ldr(reg.X(), MemOperand(reg.X(), GetCachePointerOffset(index_in_cache))); |
| 2865 | break; |
| 2866 | } |
| 2867 | } |
| 2868 | |
| 2869 | switch (invoke->GetCodePtrLocation()) { |
| 2870 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 2871 | __ Bl(&frame_entry_label_); |
| 2872 | break; |
| 2873 | case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative: { |
| 2874 | relative_call_patches_.emplace_back(invoke->GetTargetMethod()); |
| 2875 | vixl::Label* label = &relative_call_patches_.back().label; |
| 2876 | __ Bl(label); // Arbitrarily branch to the instruction after BL, override at link time. |
| 2877 | __ Bind(label); // Bind after BL. |
| 2878 | break; |
| 2879 | } |
| 2880 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 2881 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
| 2882 | // LR prepared above for better instruction scheduling. |
| 2883 | DCHECK(direct_code_loaded); |
| 2884 | // lr() |
| 2885 | __ Blr(lr); |
| 2886 | break; |
| 2887 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 2888 | // LR = callee_method->entry_point_from_quick_compiled_code_; |
| 2889 | __ Ldr(lr, MemOperand( |
| 2890 | XRegisterFrom(callee_method).X(), |
| 2891 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64WordSize).Int32Value())); |
| 2892 | // lr() |
| 2893 | __ Blr(lr); |
| 2894 | break; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 2895 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2896 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 2897 | DCHECK(!IsLeafMethod()); |
| 2898 | } |
| 2899 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2900 | void CodeGeneratorARM64::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_in) { |
| 2901 | LocationSummary* locations = invoke->GetLocations(); |
| 2902 | Location receiver = locations->InAt(0); |
| 2903 | Register temp = XRegisterFrom(temp_in); |
| 2904 | size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 2905 | invoke->GetVTableIndex(), kArm64PointerSize).SizeValue(); |
| 2906 | Offset class_offset = mirror::Object::ClassOffset(); |
| 2907 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64WordSize); |
| 2908 | |
| 2909 | BlockPoolsScope block_pools(GetVIXLAssembler()); |
| 2910 | |
| 2911 | DCHECK(receiver.IsRegister()); |
| 2912 | __ Ldr(temp.W(), HeapOperandFrom(receiver, class_offset)); |
| 2913 | MaybeRecordImplicitNullCheck(invoke); |
| 2914 | GetAssembler()->MaybeUnpoisonHeapReference(temp.W()); |
| 2915 | // temp = temp->GetMethodAt(method_offset); |
| 2916 | __ Ldr(temp, MemOperand(temp, method_offset)); |
| 2917 | // lr = temp->GetEntryPoint(); |
| 2918 | __ Ldr(lr, MemOperand(temp, entry_point.SizeValue())); |
| 2919 | // lr(); |
| 2920 | __ Blr(lr); |
| 2921 | } |
| 2922 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 2923 | void CodeGeneratorARM64::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) { |
| 2924 | DCHECK(linker_patches->empty()); |
| 2925 | size_t size = |
| 2926 | method_patches_.size() + |
| 2927 | call_patches_.size() + |
| 2928 | relative_call_patches_.size() + |
| 2929 | pc_rel_dex_cache_patches_.size(); |
| 2930 | linker_patches->reserve(size); |
| 2931 | for (const auto& entry : method_patches_) { |
| 2932 | const MethodReference& target_method = entry.first; |
| 2933 | vixl::Literal<uint64_t>* literal = entry.second; |
| 2934 | linker_patches->push_back(LinkerPatch::MethodPatch(literal->offset(), |
| 2935 | target_method.dex_file, |
| 2936 | target_method.dex_method_index)); |
| 2937 | } |
| 2938 | for (const auto& entry : call_patches_) { |
| 2939 | const MethodReference& target_method = entry.first; |
| 2940 | vixl::Literal<uint64_t>* literal = entry.second; |
| 2941 | linker_patches->push_back(LinkerPatch::CodePatch(literal->offset(), |
| 2942 | target_method.dex_file, |
| 2943 | target_method.dex_method_index)); |
| 2944 | } |
| 2945 | for (const MethodPatchInfo<vixl::Label>& info : relative_call_patches_) { |
| 2946 | linker_patches->push_back(LinkerPatch::RelativeCodePatch(info.label.location() - 4u, |
| 2947 | info.target_method.dex_file, |
| 2948 | info.target_method.dex_method_index)); |
| 2949 | } |
| 2950 | for (const PcRelativeDexCacheAccessInfo& info : pc_rel_dex_cache_patches_) { |
| 2951 | linker_patches->push_back(LinkerPatch::DexCacheArrayPatch(info.label.location() - 4u, |
| 2952 | &info.target_dex_file, |
| 2953 | info.pc_insn_label->location() - 4u, |
| 2954 | info.element_offset)); |
| 2955 | } |
| 2956 | } |
| 2957 | |
| 2958 | vixl::Literal<uint64_t>* CodeGeneratorARM64::DeduplicateUint64Literal(uint64_t value) { |
| 2959 | // Look up the literal for value. |
| 2960 | auto lb = uint64_literals_.lower_bound(value); |
| 2961 | if (lb != uint64_literals_.end() && !uint64_literals_.key_comp()(value, lb->first)) { |
| 2962 | return lb->second; |
| 2963 | } |
| 2964 | // We don't have a literal for this value, insert a new one. |
| 2965 | vixl::Literal<uint64_t>* literal = __ CreateLiteralDestroyedWithPool<uint64_t>(value); |
| 2966 | uint64_literals_.PutBefore(lb, value, literal); |
| 2967 | return literal; |
| 2968 | } |
| 2969 | |
| 2970 | vixl::Literal<uint64_t>* CodeGeneratorARM64::DeduplicateMethodLiteral( |
| 2971 | MethodReference target_method, |
| 2972 | MethodToLiteralMap* map) { |
| 2973 | // Look up the literal for target_method. |
| 2974 | auto lb = map->lower_bound(target_method); |
| 2975 | if (lb != map->end() && !map->key_comp()(target_method, lb->first)) { |
| 2976 | return lb->second; |
| 2977 | } |
| 2978 | // We don't have a literal for this method yet, insert a new one. |
| 2979 | vixl::Literal<uint64_t>* literal = __ CreateLiteralDestroyedWithPool<uint64_t>(0u); |
| 2980 | map->PutBefore(lb, target_method, literal); |
| 2981 | return literal; |
| 2982 | } |
| 2983 | |
| 2984 | vixl::Literal<uint64_t>* CodeGeneratorARM64::DeduplicateMethodAddressLiteral( |
| 2985 | MethodReference target_method) { |
| 2986 | return DeduplicateMethodLiteral(target_method, &method_patches_); |
| 2987 | } |
| 2988 | |
| 2989 | vixl::Literal<uint64_t>* CodeGeneratorARM64::DeduplicateMethodCodeLiteral( |
| 2990 | MethodReference target_method) { |
| 2991 | return DeduplicateMethodLiteral(target_method, &call_patches_); |
| 2992 | } |
| 2993 | |
| 2994 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 2995 | void InstructionCodeGeneratorARM64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 2996 | // When we do not run baseline, explicit clinit checks triggered by static |
| 2997 | // invokes must have been pruned by art::PrepareForRegisterAllocation. |
| 2998 | DCHECK(codegen_->IsBaseline() || !invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2999 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 3000 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 3001 | return; |
| 3002 | } |
| 3003 | |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 3004 | BlockPoolsScope block_pools(GetVIXLAssembler()); |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 3005 | LocationSummary* locations = invoke->GetLocations(); |
| 3006 | codegen_->GenerateStaticOrDirectCall( |
| 3007 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 3008 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3009 | } |
| 3010 | |
| 3011 | void InstructionCodeGeneratorARM64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 3012 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 3013 | return; |
| 3014 | } |
| 3015 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 3016 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3017 | DCHECK(!codegen_->IsLeafMethod()); |
| 3018 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 3019 | } |
| 3020 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3021 | void LocationsBuilderARM64::VisitLoadClass(HLoadClass* cls) { |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 3022 | InvokeRuntimeCallingConvention calling_convention; |
| 3023 | CodeGenerator::CreateLoadClassLocationSummary( |
| 3024 | cls, |
| 3025 | LocationFrom(calling_convention.GetRegisterAt(0)), |
| 3026 | LocationFrom(vixl::x0)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3027 | } |
| 3028 | |
| 3029 | void InstructionCodeGeneratorARM64::VisitLoadClass(HLoadClass* cls) { |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 3030 | if (cls->NeedsAccessCheck()) { |
| 3031 | codegen_->MoveConstant(cls->GetLocations()->GetTemp(0), cls->GetTypeIndex()); |
| 3032 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pInitializeTypeAndVerifyAccess), |
| 3033 | cls, |
| 3034 | cls->GetDexPc(), |
| 3035 | nullptr); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 3036 | return; |
| 3037 | } |
| 3038 | |
| 3039 | Register out = OutputRegister(cls); |
| 3040 | Register current_method = InputRegisterAt(cls, 0); |
| 3041 | if (cls->IsReferrersClass()) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3042 | DCHECK(!cls->CanCallRuntime()); |
| 3043 | DCHECK(!cls->MustGenerateClinitCheck()); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 3044 | __ Ldr(out, MemOperand(current_method, ArtMethod::DeclaringClassOffset().Int32Value())); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3045 | } else { |
| 3046 | DCHECK(cls->CanCallRuntime()); |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 3047 | MemberOffset resolved_types_offset = ArtMethod::DexCacheResolvedTypesOffset(kArm64PointerSize); |
| 3048 | __ Ldr(out.X(), MemOperand(current_method, resolved_types_offset.Int32Value())); |
| 3049 | __ Ldr(out, MemOperand(out.X(), CodeGenerator::GetCacheOffset(cls->GetTypeIndex()))); |
| 3050 | // TODO: We will need a read barrier here. |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3051 | |
| 3052 | SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM64( |
| 3053 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 3054 | codegen_->AddSlowPath(slow_path); |
| 3055 | __ Cbz(out, slow_path->GetEntryLabel()); |
| 3056 | if (cls->MustGenerateClinitCheck()) { |
| 3057 | GenerateClassInitializationCheck(slow_path, out); |
| 3058 | } else { |
| 3059 | __ Bind(slow_path->GetExitLabel()); |
| 3060 | } |
| 3061 | } |
| 3062 | } |
| 3063 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 3064 | static MemOperand GetExceptionTlsAddress() { |
| 3065 | return MemOperand(tr, Thread::ExceptionOffset<kArm64WordSize>().Int32Value()); |
| 3066 | } |
| 3067 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3068 | void LocationsBuilderARM64::VisitLoadException(HLoadException* load) { |
| 3069 | LocationSummary* locations = |
| 3070 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 3071 | locations->SetOut(Location::RequiresRegister()); |
| 3072 | } |
| 3073 | |
| 3074 | void InstructionCodeGeneratorARM64::VisitLoadException(HLoadException* instruction) { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 3075 | __ Ldr(OutputRegister(instruction), GetExceptionTlsAddress()); |
| 3076 | } |
| 3077 | |
| 3078 | void LocationsBuilderARM64::VisitClearException(HClearException* clear) { |
| 3079 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 3080 | } |
| 3081 | |
| 3082 | void InstructionCodeGeneratorARM64::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 3083 | __ Str(wzr, GetExceptionTlsAddress()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3084 | } |
| 3085 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3086 | void LocationsBuilderARM64::VisitLoadLocal(HLoadLocal* load) { |
| 3087 | load->SetLocations(nullptr); |
| 3088 | } |
| 3089 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3090 | void InstructionCodeGeneratorARM64::VisitLoadLocal(HLoadLocal* load ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3091 | // Nothing to do, this is driven by the code generator. |
| 3092 | } |
| 3093 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3094 | void LocationsBuilderARM64::VisitLoadString(HLoadString* load) { |
| 3095 | LocationSummary* locations = |
| 3096 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kCallOnSlowPath); |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 3097 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3098 | locations->SetOut(Location::RequiresRegister()); |
| 3099 | } |
| 3100 | |
| 3101 | void InstructionCodeGeneratorARM64::VisitLoadString(HLoadString* load) { |
| 3102 | SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathARM64(load); |
| 3103 | codegen_->AddSlowPath(slow_path); |
| 3104 | |
| 3105 | Register out = OutputRegister(load); |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 3106 | Register current_method = InputRegisterAt(load, 0); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 3107 | __ Ldr(out, MemOperand(current_method, ArtMethod::DeclaringClassOffset().Int32Value())); |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 3108 | __ Ldr(out.X(), HeapOperand(out, mirror::Class::DexCacheStringsOffset())); |
| 3109 | __ Ldr(out, MemOperand(out.X(), CodeGenerator::GetCacheOffset(load->GetStringIndex()))); |
| 3110 | // TODO: We will need a read barrier here. |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3111 | __ Cbz(out, slow_path->GetEntryLabel()); |
| 3112 | __ Bind(slow_path->GetExitLabel()); |
| 3113 | } |
| 3114 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3115 | void LocationsBuilderARM64::VisitLocal(HLocal* local) { |
| 3116 | local->SetLocations(nullptr); |
| 3117 | } |
| 3118 | |
| 3119 | void InstructionCodeGeneratorARM64::VisitLocal(HLocal* local) { |
| 3120 | DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock()); |
| 3121 | } |
| 3122 | |
| 3123 | void LocationsBuilderARM64::VisitLongConstant(HLongConstant* constant) { |
| 3124 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant); |
| 3125 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3126 | } |
| 3127 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3128 | void InstructionCodeGeneratorARM64::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3129 | // Will be generated at use site. |
| 3130 | } |
| 3131 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3132 | void LocationsBuilderARM64::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 3133 | LocationSummary* locations = |
| 3134 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 3135 | InvokeRuntimeCallingConvention calling_convention; |
| 3136 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 3137 | } |
| 3138 | |
| 3139 | void InstructionCodeGeneratorARM64::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 3140 | codegen_->InvokeRuntime(instruction->IsEnter() |
| 3141 | ? QUICK_ENTRY_POINT(pLockObject) : QUICK_ENTRY_POINT(pUnlockObject), |
| 3142 | instruction, |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 3143 | instruction->GetDexPc(), |
| 3144 | nullptr); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 3145 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3146 | } |
| 3147 | |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 3148 | void LocationsBuilderARM64::VisitMul(HMul* mul) { |
| 3149 | LocationSummary* locations = |
| 3150 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 3151 | switch (mul->GetResultType()) { |
| 3152 | case Primitive::kPrimInt: |
| 3153 | case Primitive::kPrimLong: |
| 3154 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3155 | locations->SetInAt(1, Location::RequiresRegister()); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 3156 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 3157 | break; |
| 3158 | |
| 3159 | case Primitive::kPrimFloat: |
| 3160 | case Primitive::kPrimDouble: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3161 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3162 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3163 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 3164 | break; |
| 3165 | |
| 3166 | default: |
| 3167 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 3168 | } |
| 3169 | } |
| 3170 | |
| 3171 | void InstructionCodeGeneratorARM64::VisitMul(HMul* mul) { |
| 3172 | switch (mul->GetResultType()) { |
| 3173 | case Primitive::kPrimInt: |
| 3174 | case Primitive::kPrimLong: |
| 3175 | __ Mul(OutputRegister(mul), InputRegisterAt(mul, 0), InputRegisterAt(mul, 1)); |
| 3176 | break; |
| 3177 | |
| 3178 | case Primitive::kPrimFloat: |
| 3179 | case Primitive::kPrimDouble: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3180 | __ Fmul(OutputFPRegister(mul), InputFPRegisterAt(mul, 0), InputFPRegisterAt(mul, 1)); |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 3181 | break; |
| 3182 | |
| 3183 | default: |
| 3184 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 3185 | } |
| 3186 | } |
| 3187 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3188 | void LocationsBuilderARM64::VisitNeg(HNeg* neg) { |
| 3189 | LocationSummary* locations = |
| 3190 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 3191 | switch (neg->GetResultType()) { |
| 3192 | case Primitive::kPrimInt: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3193 | case Primitive::kPrimLong: |
Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 3194 | locations->SetInAt(0, ARM64EncodableConstantOrRegister(neg->InputAt(0), neg)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3195 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3196 | break; |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3197 | |
| 3198 | case Primitive::kPrimFloat: |
| 3199 | case Primitive::kPrimDouble: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3200 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3201 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3202 | break; |
| 3203 | |
| 3204 | default: |
| 3205 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 3206 | } |
| 3207 | } |
| 3208 | |
| 3209 | void InstructionCodeGeneratorARM64::VisitNeg(HNeg* neg) { |
| 3210 | switch (neg->GetResultType()) { |
| 3211 | case Primitive::kPrimInt: |
| 3212 | case Primitive::kPrimLong: |
| 3213 | __ Neg(OutputRegister(neg), InputOperandAt(neg, 0)); |
| 3214 | break; |
| 3215 | |
| 3216 | case Primitive::kPrimFloat: |
| 3217 | case Primitive::kPrimDouble: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3218 | __ Fneg(OutputFPRegister(neg), InputFPRegisterAt(neg, 0)); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3219 | break; |
| 3220 | |
| 3221 | default: |
| 3222 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 3223 | } |
| 3224 | } |
| 3225 | |
| 3226 | void LocationsBuilderARM64::VisitNewArray(HNewArray* instruction) { |
| 3227 | LocationSummary* locations = |
| 3228 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 3229 | InvokeRuntimeCallingConvention calling_convention; |
| 3230 | locations->AddTemp(LocationFrom(calling_convention.GetRegisterAt(0))); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3231 | locations->SetOut(LocationFrom(x0)); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 3232 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3233 | locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(2))); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 3234 | CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck, |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 3235 | void*, uint32_t, int32_t, ArtMethod*>(); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3236 | } |
| 3237 | |
| 3238 | void InstructionCodeGeneratorARM64::VisitNewArray(HNewArray* instruction) { |
| 3239 | LocationSummary* locations = instruction->GetLocations(); |
| 3240 | InvokeRuntimeCallingConvention calling_convention; |
| 3241 | Register type_index = RegisterFrom(locations->GetTemp(0), Primitive::kPrimInt); |
| 3242 | DCHECK(type_index.Is(w0)); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3243 | __ Mov(type_index, instruction->GetTypeIndex()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3244 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 3245 | // of poisoning the reference. |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 3246 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), |
| 3247 | instruction, |
| 3248 | instruction->GetDexPc(), |
| 3249 | nullptr); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 3250 | CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck, void*, uint32_t, int32_t, ArtMethod*>(); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3251 | } |
| 3252 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3253 | void LocationsBuilderARM64::VisitNewInstance(HNewInstance* instruction) { |
| 3254 | LocationSummary* locations = |
| 3255 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 3256 | InvokeRuntimeCallingConvention calling_convention; |
| 3257 | locations->AddTemp(LocationFrom(calling_convention.GetRegisterAt(0))); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3258 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(1))); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3259 | locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimNot)); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 3260 | CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, ArtMethod*>(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3261 | } |
| 3262 | |
| 3263 | void InstructionCodeGeneratorARM64::VisitNewInstance(HNewInstance* instruction) { |
| 3264 | LocationSummary* locations = instruction->GetLocations(); |
| 3265 | Register type_index = RegisterFrom(locations->GetTemp(0), Primitive::kPrimInt); |
| 3266 | DCHECK(type_index.Is(w0)); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3267 | __ Mov(type_index, instruction->GetTypeIndex()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3268 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 3269 | // of poisoning the reference. |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 3270 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), |
| 3271 | instruction, |
| 3272 | instruction->GetDexPc(), |
| 3273 | nullptr); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 3274 | CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, ArtMethod*>(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3275 | } |
| 3276 | |
| 3277 | void LocationsBuilderARM64::VisitNot(HNot* instruction) { |
| 3278 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Alexandre Rames | 4e59651 | 2014-11-07 15:56:50 +0000 | [diff] [blame] | 3279 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 3280 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3281 | } |
| 3282 | |
| 3283 | void InstructionCodeGeneratorARM64::VisitNot(HNot* instruction) { |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 3284 | switch (instruction->GetResultType()) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3285 | case Primitive::kPrimInt: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3286 | case Primitive::kPrimLong: |
Roland Levillain | 55dcfb5 | 2014-10-24 18:09:09 +0100 | [diff] [blame] | 3287 | __ Mvn(OutputRegister(instruction), InputOperandAt(instruction, 0)); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3288 | break; |
| 3289 | |
| 3290 | default: |
| 3291 | LOG(FATAL) << "Unexpected type for not operation " << instruction->GetResultType(); |
| 3292 | } |
| 3293 | } |
| 3294 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 3295 | void LocationsBuilderARM64::VisitBooleanNot(HBooleanNot* instruction) { |
| 3296 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 3297 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3298 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3299 | } |
| 3300 | |
| 3301 | void InstructionCodeGeneratorARM64::VisitBooleanNot(HBooleanNot* instruction) { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 3302 | __ Eor(OutputRegister(instruction), InputRegisterAt(instruction, 0), vixl::Operand(1)); |
| 3303 | } |
| 3304 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3305 | void LocationsBuilderARM64::VisitNullCheck(HNullCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 3306 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 3307 | ? LocationSummary::kCallOnSlowPath |
| 3308 | : LocationSummary::kNoCall; |
| 3309 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3310 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3311 | if (instruction->HasUses()) { |
| 3312 | locations->SetOut(Location::SameAsFirstInput()); |
| 3313 | } |
| 3314 | } |
| 3315 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3316 | void InstructionCodeGeneratorARM64::GenerateImplicitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3317 | if (codegen_->CanMoveNullCheckToUser(instruction)) { |
| 3318 | return; |
| 3319 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3320 | |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 3321 | BlockPoolsScope block_pools(GetVIXLAssembler()); |
| 3322 | Location obj = instruction->GetLocations()->InAt(0); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3323 | __ Ldr(wzr, HeapOperandFrom(obj, Offset(0))); |
| 3324 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 3325 | } |
| 3326 | |
| 3327 | void InstructionCodeGeneratorARM64::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3328 | SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM64(instruction); |
| 3329 | codegen_->AddSlowPath(slow_path); |
| 3330 | |
| 3331 | LocationSummary* locations = instruction->GetLocations(); |
| 3332 | Location obj = locations->InAt(0); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3333 | |
| 3334 | __ Cbz(RegisterFrom(obj, instruction->InputAt(0)->GetType()), slow_path->GetEntryLabel()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3335 | } |
| 3336 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3337 | void InstructionCodeGeneratorARM64::VisitNullCheck(HNullCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 3338 | if (codegen_->IsImplicitNullCheckAllowed(instruction)) { |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3339 | GenerateImplicitNullCheck(instruction); |
| 3340 | } else { |
| 3341 | GenerateExplicitNullCheck(instruction); |
| 3342 | } |
| 3343 | } |
| 3344 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3345 | void LocationsBuilderARM64::VisitOr(HOr* instruction) { |
| 3346 | HandleBinaryOp(instruction); |
| 3347 | } |
| 3348 | |
| 3349 | void InstructionCodeGeneratorARM64::VisitOr(HOr* instruction) { |
| 3350 | HandleBinaryOp(instruction); |
| 3351 | } |
| 3352 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 3353 | void LocationsBuilderARM64::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
| 3354 | LOG(FATAL) << "Unreachable"; |
| 3355 | } |
| 3356 | |
| 3357 | void InstructionCodeGeneratorARM64::VisitParallelMove(HParallelMove* instruction) { |
| 3358 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 3359 | } |
| 3360 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3361 | void LocationsBuilderARM64::VisitParameterValue(HParameterValue* instruction) { |
| 3362 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 3363 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 3364 | if (location.IsStackSlot()) { |
| 3365 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 3366 | } else if (location.IsDoubleStackSlot()) { |
| 3367 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 3368 | } |
| 3369 | locations->SetOut(location); |
| 3370 | } |
| 3371 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3372 | void InstructionCodeGeneratorARM64::VisitParameterValue( |
| 3373 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3374 | // Nothing to do, the parameter is already at its location. |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3375 | } |
| 3376 | |
| 3377 | void LocationsBuilderARM64::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 3378 | LocationSummary* locations = |
| 3379 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 3380 | locations->SetOut(LocationFrom(kArtMethodRegister)); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3381 | } |
| 3382 | |
| 3383 | void InstructionCodeGeneratorARM64::VisitCurrentMethod( |
| 3384 | HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
| 3385 | // Nothing to do, the method is already at its location. |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3386 | } |
| 3387 | |
| 3388 | void LocationsBuilderARM64::VisitPhi(HPhi* instruction) { |
| 3389 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 3390 | for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) { |
| 3391 | locations->SetInAt(i, Location::Any()); |
| 3392 | } |
| 3393 | locations->SetOut(Location::Any()); |
| 3394 | } |
| 3395 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3396 | void InstructionCodeGeneratorARM64::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3397 | LOG(FATAL) << "Unreachable"; |
| 3398 | } |
| 3399 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3400 | void LocationsBuilderARM64::VisitRem(HRem* rem) { |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 3401 | Primitive::Type type = rem->GetResultType(); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 3402 | LocationSummary::CallKind call_kind = |
| 3403 | Primitive::IsFloatingPointType(type) ? LocationSummary::kCall : LocationSummary::kNoCall; |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 3404 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind); |
| 3405 | |
| 3406 | switch (type) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3407 | case Primitive::kPrimInt: |
| 3408 | case Primitive::kPrimLong: |
| 3409 | locations->SetInAt(0, Location::RequiresRegister()); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3410 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3411 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3412 | break; |
| 3413 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 3414 | case Primitive::kPrimFloat: |
| 3415 | case Primitive::kPrimDouble: { |
| 3416 | InvokeRuntimeCallingConvention calling_convention; |
| 3417 | locations->SetInAt(0, LocationFrom(calling_convention.GetFpuRegisterAt(0))); |
| 3418 | locations->SetInAt(1, LocationFrom(calling_convention.GetFpuRegisterAt(1))); |
| 3419 | locations->SetOut(calling_convention.GetReturnLocation(type)); |
| 3420 | |
| 3421 | break; |
| 3422 | } |
| 3423 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3424 | default: |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 3425 | LOG(FATAL) << "Unexpected rem type " << type; |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3426 | } |
| 3427 | } |
| 3428 | |
| 3429 | void InstructionCodeGeneratorARM64::VisitRem(HRem* rem) { |
| 3430 | Primitive::Type type = rem->GetResultType(); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 3431 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3432 | switch (type) { |
| 3433 | case Primitive::kPrimInt: |
| 3434 | case Primitive::kPrimLong: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3435 | GenerateDivRemIntegral(rem); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3436 | break; |
| 3437 | } |
| 3438 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 3439 | case Primitive::kPrimFloat: |
| 3440 | case Primitive::kPrimDouble: { |
| 3441 | int32_t entry_offset = (type == Primitive::kPrimFloat) ? QUICK_ENTRY_POINT(pFmodf) |
| 3442 | : QUICK_ENTRY_POINT(pFmod); |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 3443 | codegen_->InvokeRuntime(entry_offset, rem, rem->GetDexPc(), nullptr); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 3444 | break; |
| 3445 | } |
| 3446 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3447 | default: |
| 3448 | LOG(FATAL) << "Unexpected rem type " << type; |
| 3449 | } |
| 3450 | } |
| 3451 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 3452 | void LocationsBuilderARM64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 3453 | memory_barrier->SetLocations(nullptr); |
| 3454 | } |
| 3455 | |
| 3456 | void InstructionCodeGeneratorARM64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 3457 | GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
| 3458 | } |
| 3459 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3460 | void LocationsBuilderARM64::VisitReturn(HReturn* instruction) { |
| 3461 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 3462 | Primitive::Type return_type = instruction->InputAt(0)->GetType(); |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3463 | locations->SetInAt(0, ARM64ReturnLocation(return_type)); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3464 | } |
| 3465 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3466 | void InstructionCodeGeneratorARM64::VisitReturn(HReturn* instruction ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3467 | codegen_->GenerateFrameExit(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3468 | } |
| 3469 | |
| 3470 | void LocationsBuilderARM64::VisitReturnVoid(HReturnVoid* instruction) { |
| 3471 | instruction->SetLocations(nullptr); |
| 3472 | } |
| 3473 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3474 | void InstructionCodeGeneratorARM64::VisitReturnVoid(HReturnVoid* instruction ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3475 | codegen_->GenerateFrameExit(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3476 | } |
| 3477 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3478 | void LocationsBuilderARM64::VisitShl(HShl* shl) { |
| 3479 | HandleShift(shl); |
| 3480 | } |
| 3481 | |
| 3482 | void InstructionCodeGeneratorARM64::VisitShl(HShl* shl) { |
| 3483 | HandleShift(shl); |
| 3484 | } |
| 3485 | |
| 3486 | void LocationsBuilderARM64::VisitShr(HShr* shr) { |
| 3487 | HandleShift(shr); |
| 3488 | } |
| 3489 | |
| 3490 | void InstructionCodeGeneratorARM64::VisitShr(HShr* shr) { |
| 3491 | HandleShift(shr); |
| 3492 | } |
| 3493 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3494 | void LocationsBuilderARM64::VisitStoreLocal(HStoreLocal* store) { |
| 3495 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(store); |
| 3496 | Primitive::Type field_type = store->InputAt(1)->GetType(); |
| 3497 | switch (field_type) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3498 | case Primitive::kPrimNot: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3499 | case Primitive::kPrimBoolean: |
| 3500 | case Primitive::kPrimByte: |
| 3501 | case Primitive::kPrimChar: |
| 3502 | case Primitive::kPrimShort: |
| 3503 | case Primitive::kPrimInt: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3504 | case Primitive::kPrimFloat: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3505 | locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 3506 | break; |
| 3507 | |
| 3508 | case Primitive::kPrimLong: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3509 | case Primitive::kPrimDouble: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3510 | locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 3511 | break; |
| 3512 | |
| 3513 | default: |
| 3514 | LOG(FATAL) << "Unimplemented local type " << field_type; |
| 3515 | } |
| 3516 | } |
| 3517 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3518 | void InstructionCodeGeneratorARM64::VisitStoreLocal(HStoreLocal* store ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3519 | } |
| 3520 | |
| 3521 | void LocationsBuilderARM64::VisitSub(HSub* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3522 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3523 | } |
| 3524 | |
| 3525 | void InstructionCodeGeneratorARM64::VisitSub(HSub* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3526 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3527 | } |
| 3528 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3529 | void LocationsBuilderARM64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 3530 | HandleFieldGet(instruction); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3531 | } |
| 3532 | |
| 3533 | void InstructionCodeGeneratorARM64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 3534 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3535 | } |
| 3536 | |
| 3537 | void LocationsBuilderARM64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 3538 | HandleFieldSet(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3539 | } |
| 3540 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3541 | void InstructionCodeGeneratorARM64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3542 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3543 | } |
| 3544 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 3545 | void LocationsBuilderARM64::VisitUnresolvedInstanceFieldGet( |
| 3546 | HUnresolvedInstanceFieldGet* instruction) { |
| 3547 | FieldAccessCallingConventionARM64 calling_convention; |
| 3548 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 3549 | instruction, instruction->GetFieldType(), calling_convention); |
| 3550 | } |
| 3551 | |
| 3552 | void InstructionCodeGeneratorARM64::VisitUnresolvedInstanceFieldGet( |
| 3553 | HUnresolvedInstanceFieldGet* instruction) { |
| 3554 | FieldAccessCallingConventionARM64 calling_convention; |
| 3555 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 3556 | instruction->GetFieldType(), |
| 3557 | instruction->GetFieldIndex(), |
| 3558 | instruction->GetDexPc(), |
| 3559 | calling_convention); |
| 3560 | } |
| 3561 | |
| 3562 | void LocationsBuilderARM64::VisitUnresolvedInstanceFieldSet( |
| 3563 | HUnresolvedInstanceFieldSet* instruction) { |
| 3564 | FieldAccessCallingConventionARM64 calling_convention; |
| 3565 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 3566 | instruction, instruction->GetFieldType(), calling_convention); |
| 3567 | } |
| 3568 | |
| 3569 | void InstructionCodeGeneratorARM64::VisitUnresolvedInstanceFieldSet( |
| 3570 | HUnresolvedInstanceFieldSet* instruction) { |
| 3571 | FieldAccessCallingConventionARM64 calling_convention; |
| 3572 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 3573 | instruction->GetFieldType(), |
| 3574 | instruction->GetFieldIndex(), |
| 3575 | instruction->GetDexPc(), |
| 3576 | calling_convention); |
| 3577 | } |
| 3578 | |
| 3579 | void LocationsBuilderARM64::VisitUnresolvedStaticFieldGet( |
| 3580 | HUnresolvedStaticFieldGet* instruction) { |
| 3581 | FieldAccessCallingConventionARM64 calling_convention; |
| 3582 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 3583 | instruction, instruction->GetFieldType(), calling_convention); |
| 3584 | } |
| 3585 | |
| 3586 | void InstructionCodeGeneratorARM64::VisitUnresolvedStaticFieldGet( |
| 3587 | HUnresolvedStaticFieldGet* instruction) { |
| 3588 | FieldAccessCallingConventionARM64 calling_convention; |
| 3589 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 3590 | instruction->GetFieldType(), |
| 3591 | instruction->GetFieldIndex(), |
| 3592 | instruction->GetDexPc(), |
| 3593 | calling_convention); |
| 3594 | } |
| 3595 | |
| 3596 | void LocationsBuilderARM64::VisitUnresolvedStaticFieldSet( |
| 3597 | HUnresolvedStaticFieldSet* instruction) { |
| 3598 | FieldAccessCallingConventionARM64 calling_convention; |
| 3599 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 3600 | instruction, instruction->GetFieldType(), calling_convention); |
| 3601 | } |
| 3602 | |
| 3603 | void InstructionCodeGeneratorARM64::VisitUnresolvedStaticFieldSet( |
| 3604 | HUnresolvedStaticFieldSet* instruction) { |
| 3605 | FieldAccessCallingConventionARM64 calling_convention; |
| 3606 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 3607 | instruction->GetFieldType(), |
| 3608 | instruction->GetFieldIndex(), |
| 3609 | instruction->GetDexPc(), |
| 3610 | calling_convention); |
| 3611 | } |
| 3612 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3613 | void LocationsBuilderARM64::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 3614 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
| 3615 | } |
| 3616 | |
| 3617 | void InstructionCodeGeneratorARM64::VisitSuspendCheck(HSuspendCheck* instruction) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3618 | HBasicBlock* block = instruction->GetBlock(); |
| 3619 | if (block->GetLoopInformation() != nullptr) { |
| 3620 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 3621 | // The back edge will generate the suspend check. |
| 3622 | return; |
| 3623 | } |
| 3624 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 3625 | // The goto will generate the suspend check. |
| 3626 | return; |
| 3627 | } |
| 3628 | GenerateSuspendCheck(instruction, nullptr); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3629 | } |
| 3630 | |
| 3631 | void LocationsBuilderARM64::VisitTemporary(HTemporary* temp) { |
| 3632 | temp->SetLocations(nullptr); |
| 3633 | } |
| 3634 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3635 | void InstructionCodeGeneratorARM64::VisitTemporary(HTemporary* temp ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3636 | // Nothing to do, this is driven by the code generator. |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3637 | } |
| 3638 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3639 | void LocationsBuilderARM64::VisitThrow(HThrow* instruction) { |
| 3640 | LocationSummary* locations = |
| 3641 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 3642 | InvokeRuntimeCallingConvention calling_convention; |
| 3643 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 3644 | } |
| 3645 | |
| 3646 | void InstructionCodeGeneratorARM64::VisitThrow(HThrow* instruction) { |
| 3647 | codegen_->InvokeRuntime( |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 3648 | QUICK_ENTRY_POINT(pDeliverException), instruction, instruction->GetDexPc(), nullptr); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 3649 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3650 | } |
| 3651 | |
| 3652 | void LocationsBuilderARM64::VisitTypeConversion(HTypeConversion* conversion) { |
| 3653 | LocationSummary* locations = |
| 3654 | new (GetGraph()->GetArena()) LocationSummary(conversion, LocationSummary::kNoCall); |
| 3655 | Primitive::Type input_type = conversion->GetInputType(); |
| 3656 | Primitive::Type result_type = conversion->GetResultType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 3657 | DCHECK_NE(input_type, result_type); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3658 | if ((input_type == Primitive::kPrimNot) || (input_type == Primitive::kPrimVoid) || |
| 3659 | (result_type == Primitive::kPrimNot) || (result_type == Primitive::kPrimVoid)) { |
| 3660 | LOG(FATAL) << "Unexpected type conversion from " << input_type << " to " << result_type; |
| 3661 | } |
| 3662 | |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 3663 | if (Primitive::IsFloatingPointType(input_type)) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3664 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3665 | } else { |
| 3666 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3667 | } |
| 3668 | |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 3669 | if (Primitive::IsFloatingPointType(result_type)) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3670 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3671 | } else { |
| 3672 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3673 | } |
| 3674 | } |
| 3675 | |
| 3676 | void InstructionCodeGeneratorARM64::VisitTypeConversion(HTypeConversion* conversion) { |
| 3677 | Primitive::Type result_type = conversion->GetResultType(); |
| 3678 | Primitive::Type input_type = conversion->GetInputType(); |
| 3679 | |
| 3680 | DCHECK_NE(input_type, result_type); |
| 3681 | |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 3682 | if (Primitive::IsIntegralType(result_type) && Primitive::IsIntegralType(input_type)) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3683 | int result_size = Primitive::ComponentSize(result_type); |
| 3684 | int input_size = Primitive::ComponentSize(input_type); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 3685 | int min_size = std::min(result_size, input_size); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3686 | Register output = OutputRegister(conversion); |
| 3687 | Register source = InputRegisterAt(conversion, 0); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 3688 | if ((result_type == Primitive::kPrimChar) && (input_size < result_size)) { |
| 3689 | __ Ubfx(output, source, 0, result_size * kBitsPerByte); |
Alexandre Rames | 4dff2fd | 2015-08-20 13:36:35 +0100 | [diff] [blame] | 3690 | } else if (result_type == Primitive::kPrimInt && input_type == Primitive::kPrimLong) { |
| 3691 | // 'int' values are used directly as W registers, discarding the top |
| 3692 | // bits, so we don't need to sign-extend and can just perform a move. |
| 3693 | // We do not pass the `kDiscardForSameWReg` argument to force clearing the |
| 3694 | // top 32 bits of the target register. We theoretically could leave those |
| 3695 | // bits unchanged, but we would have to make sure that no code uses a |
| 3696 | // 32bit input value as a 64bit value assuming that the top 32 bits are |
| 3697 | // zero. |
| 3698 | __ Mov(output.W(), source.W()); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 3699 | } else if ((result_type == Primitive::kPrimChar) || |
| 3700 | ((input_type == Primitive::kPrimChar) && (result_size > input_size))) { |
| 3701 | __ Ubfx(output, output.IsX() ? source.X() : source.W(), 0, min_size * kBitsPerByte); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3702 | } else { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 3703 | __ Sbfx(output, output.IsX() ? source.X() : source.W(), 0, min_size * kBitsPerByte); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3704 | } |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 3705 | } else if (Primitive::IsFloatingPointType(result_type) && Primitive::IsIntegralType(input_type)) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3706 | __ Scvtf(OutputFPRegister(conversion), InputRegisterAt(conversion, 0)); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 3707 | } else if (Primitive::IsIntegralType(result_type) && Primitive::IsFloatingPointType(input_type)) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3708 | CHECK(result_type == Primitive::kPrimInt || result_type == Primitive::kPrimLong); |
| 3709 | __ Fcvtzs(OutputRegister(conversion), InputFPRegisterAt(conversion, 0)); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 3710 | } else if (Primitive::IsFloatingPointType(result_type) && |
| 3711 | Primitive::IsFloatingPointType(input_type)) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3712 | __ Fcvt(OutputFPRegister(conversion), InputFPRegisterAt(conversion, 0)); |
| 3713 | } else { |
| 3714 | LOG(FATAL) << "Unexpected or unimplemented type conversion from " << input_type |
| 3715 | << " to " << result_type; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3716 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3717 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3718 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3719 | void LocationsBuilderARM64::VisitUShr(HUShr* ushr) { |
| 3720 | HandleShift(ushr); |
| 3721 | } |
| 3722 | |
| 3723 | void InstructionCodeGeneratorARM64::VisitUShr(HUShr* ushr) { |
| 3724 | HandleShift(ushr); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3725 | } |
| 3726 | |
| 3727 | void LocationsBuilderARM64::VisitXor(HXor* instruction) { |
| 3728 | HandleBinaryOp(instruction); |
| 3729 | } |
| 3730 | |
| 3731 | void InstructionCodeGeneratorARM64::VisitXor(HXor* instruction) { |
| 3732 | HandleBinaryOp(instruction); |
| 3733 | } |
| 3734 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3735 | void LocationsBuilderARM64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 3736 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 3737 | LOG(FATAL) << "Unreachable"; |
| 3738 | } |
| 3739 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3740 | void InstructionCodeGeneratorARM64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 3741 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 3742 | LOG(FATAL) << "Unreachable"; |
| 3743 | } |
| 3744 | |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 3745 | void LocationsBuilderARM64::VisitFakeString(HFakeString* instruction) { |
| 3746 | DCHECK(codegen_->IsBaseline()); |
| 3747 | LocationSummary* locations = |
| 3748 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 3749 | locations->SetOut(Location::ConstantLocation(GetGraph()->GetNullConstant())); |
| 3750 | } |
| 3751 | |
| 3752 | void InstructionCodeGeneratorARM64::VisitFakeString(HFakeString* instruction ATTRIBUTE_UNUSED) { |
| 3753 | DCHECK(codegen_->IsBaseline()); |
| 3754 | // Will be generated at use site. |
| 3755 | } |
| 3756 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3757 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 3758 | void LocationsBuilderARM64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 3759 | LocationSummary* locations = |
| 3760 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 3761 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3762 | } |
| 3763 | |
| 3764 | void InstructionCodeGeneratorARM64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 3765 | int32_t lower_bound = switch_instr->GetStartValue(); |
| 3766 | int32_t num_entries = switch_instr->GetNumEntries(); |
| 3767 | Register value_reg = InputRegisterAt(switch_instr, 0); |
| 3768 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 3769 | |
| 3770 | // Create a series of compare/jumps. |
| 3771 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
| 3772 | for (int32_t i = 0; i < num_entries; i++) { |
| 3773 | int32_t case_value = lower_bound + i; |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 3774 | vixl::Label* succ = codegen_->GetLabelOf(successors[i]); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3775 | if (case_value == 0) { |
| 3776 | __ Cbz(value_reg, succ); |
| 3777 | } else { |
| 3778 | __ Cmp(value_reg, vixl::Operand(case_value)); |
| 3779 | __ B(eq, succ); |
| 3780 | } |
| 3781 | } |
| 3782 | |
| 3783 | // And the default for any other value. |
| 3784 | if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) { |
| 3785 | __ B(codegen_->GetLabelOf(default_block)); |
| 3786 | } |
| 3787 | } |
| 3788 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3789 | #undef __ |
| 3790 | #undef QUICK_ENTRY_POINT |
| 3791 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3792 | } // namespace arm64 |
| 3793 | } // namespace art |