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