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