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