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