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