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