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