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