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