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