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" |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 22 | #include "compiled_method.h" |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 23 | #include "entrypoints/quick/quick_entrypoints.h" |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 24 | #include "entrypoints/quick/quick_entrypoints_enum.h" |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 25 | #include "gc/accounting/card_table.h" |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 26 | #include "intrinsics.h" |
| 27 | #include "intrinsics_arm64.h" |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 28 | #include "mirror/array-inl.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 29 | #include "mirror/class-inl.h" |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 30 | #include "offsets.h" |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 31 | #include "thread.h" |
| 32 | #include "utils/arm64/assembler_arm64.h" |
| 33 | #include "utils/assembler.h" |
| 34 | #include "utils/stack_checks.h" |
| 35 | |
| 36 | |
| 37 | using namespace vixl; // NOLINT(build/namespaces) |
| 38 | |
| 39 | #ifdef __ |
| 40 | #error "ARM64 Codegen VIXL macro-assembler macro already defined." |
| 41 | #endif |
| 42 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 43 | namespace art { |
| 44 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 45 | template<class MirrorType> |
| 46 | class GcRoot; |
| 47 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 48 | namespace arm64 { |
| 49 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 50 | using helpers::CPURegisterFrom; |
| 51 | using helpers::DRegisterFrom; |
| 52 | using helpers::FPRegisterFrom; |
| 53 | using helpers::HeapOperand; |
| 54 | using helpers::HeapOperandFrom; |
| 55 | using helpers::InputCPURegisterAt; |
| 56 | using helpers::InputFPRegisterAt; |
| 57 | using helpers::InputRegisterAt; |
| 58 | using helpers::InputOperandAt; |
| 59 | using helpers::Int64ConstantFrom; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 60 | using helpers::LocationFrom; |
| 61 | using helpers::OperandFromMemOperand; |
| 62 | using helpers::OutputCPURegister; |
| 63 | using helpers::OutputFPRegister; |
| 64 | using helpers::OutputRegister; |
| 65 | using helpers::RegisterFrom; |
| 66 | using helpers::StackOperandFrom; |
| 67 | using helpers::VIXLRegCodeFromART; |
| 68 | using helpers::WRegisterFrom; |
| 69 | using helpers::XRegisterFrom; |
Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 70 | using helpers::ARM64EncodableConstantOrRegister; |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 71 | using helpers::ArtVixlRegCodeCoherentForRegSet; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 72 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 73 | static constexpr int kCurrentMethodStackOffset = 0; |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 74 | // The compare/jump sequence will generate about (1.5 * num_entries + 3) instructions. While jump |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 75 | // table version generates 7 instructions and num_entries literals. Compare/jump sequence will |
| 76 | // generates less code/data with a small num_entries. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 77 | static constexpr uint32_t kPackedSwitchCompareJumpThreshold = 7; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 78 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 79 | inline Condition ARM64Condition(IfCondition cond) { |
| 80 | switch (cond) { |
| 81 | case kCondEQ: return eq; |
| 82 | case kCondNE: return ne; |
| 83 | case kCondLT: return lt; |
| 84 | case kCondLE: return le; |
| 85 | case kCondGT: return gt; |
| 86 | case kCondGE: return ge; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 87 | case kCondB: return lo; |
| 88 | case kCondBE: return ls; |
| 89 | case kCondA: return hi; |
| 90 | case kCondAE: return hs; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 91 | } |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 92 | LOG(FATAL) << "Unreachable"; |
| 93 | UNREACHABLE(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 94 | } |
| 95 | |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 96 | inline Condition ARM64FPCondition(IfCondition cond, bool gt_bias) { |
| 97 | // The ARM64 condition codes can express all the necessary branches, see the |
| 98 | // "Meaning (floating-point)" column in the table C1-1 in the ARMv8 reference manual. |
| 99 | // There is no dex instruction or HIR that would need the missing conditions |
| 100 | // "equal or unordered" or "not equal". |
| 101 | switch (cond) { |
| 102 | case kCondEQ: return eq; |
| 103 | case kCondNE: return ne /* unordered */; |
| 104 | case kCondLT: return gt_bias ? cc : lt /* unordered */; |
| 105 | case kCondLE: return gt_bias ? ls : le /* unordered */; |
| 106 | case kCondGT: return gt_bias ? hi /* unordered */ : gt; |
| 107 | case kCondGE: return gt_bias ? cs /* unordered */ : ge; |
| 108 | default: |
| 109 | LOG(FATAL) << "UNREACHABLE"; |
| 110 | UNREACHABLE(); |
| 111 | } |
| 112 | } |
| 113 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 114 | Location ARM64ReturnLocation(Primitive::Type return_type) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 115 | // Note that in practice, `LocationFrom(x0)` and `LocationFrom(w0)` create the |
| 116 | // same Location object, and so do `LocationFrom(d0)` and `LocationFrom(s0)`, |
| 117 | // but we use the exact registers for clarity. |
| 118 | if (return_type == Primitive::kPrimFloat) { |
| 119 | return LocationFrom(s0); |
| 120 | } else if (return_type == Primitive::kPrimDouble) { |
| 121 | return LocationFrom(d0); |
| 122 | } else if (return_type == Primitive::kPrimLong) { |
| 123 | return LocationFrom(x0); |
Nicolas Geoffray | 925e562 | 2015-06-03 12:23:32 +0100 | [diff] [blame] | 124 | } else if (return_type == Primitive::kPrimVoid) { |
| 125 | return Location::NoLocation(); |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 126 | } else { |
| 127 | return LocationFrom(w0); |
| 128 | } |
| 129 | } |
| 130 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 131 | Location InvokeRuntimeCallingConvention::GetReturnLocation(Primitive::Type return_type) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 132 | return ARM64ReturnLocation(return_type); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 133 | } |
| 134 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 135 | #define __ down_cast<CodeGeneratorARM64*>(codegen)->GetVIXLAssembler()-> |
| 136 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kArm64WordSize, x).Int32Value() |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 137 | |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 138 | // Calculate memory accessing operand for save/restore live registers. |
| 139 | static void SaveRestoreLiveRegistersHelper(CodeGenerator* codegen, |
| 140 | RegisterSet* register_set, |
| 141 | int64_t spill_offset, |
| 142 | bool is_save) { |
| 143 | DCHECK(ArtVixlRegCodeCoherentForRegSet(register_set->GetCoreRegisters(), |
| 144 | codegen->GetNumberOfCoreRegisters(), |
| 145 | register_set->GetFloatingPointRegisters(), |
| 146 | codegen->GetNumberOfFloatingPointRegisters())); |
| 147 | |
| 148 | CPURegList core_list = CPURegList(CPURegister::kRegister, kXRegSize, |
| 149 | register_set->GetCoreRegisters() & (~callee_saved_core_registers.list())); |
Nicolas Geoffray | 75d5b9b | 2015-10-05 07:40:35 +0000 | [diff] [blame] | 150 | CPURegList fp_list = CPURegList(CPURegister::kFPRegister, kDRegSize, |
| 151 | register_set->GetFloatingPointRegisters() & (~callee_saved_fp_registers.list())); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 152 | |
| 153 | MacroAssembler* masm = down_cast<CodeGeneratorARM64*>(codegen)->GetVIXLAssembler(); |
| 154 | UseScratchRegisterScope temps(masm); |
| 155 | |
| 156 | Register base = masm->StackPointer(); |
| 157 | int64_t core_spill_size = core_list.TotalSizeInBytes(); |
| 158 | int64_t fp_spill_size = fp_list.TotalSizeInBytes(); |
| 159 | int64_t reg_size = kXRegSizeInBytes; |
| 160 | int64_t max_ls_pair_offset = spill_offset + core_spill_size + fp_spill_size - 2 * reg_size; |
| 161 | uint32_t ls_access_size = WhichPowerOf2(reg_size); |
| 162 | if (((core_list.Count() > 1) || (fp_list.Count() > 1)) && |
| 163 | !masm->IsImmLSPair(max_ls_pair_offset, ls_access_size)) { |
| 164 | // If the offset does not fit in the instruction's immediate field, use an alternate register |
| 165 | // to compute the base address(float point registers spill base address). |
| 166 | Register new_base = temps.AcquireSameSizeAs(base); |
| 167 | __ Add(new_base, base, Operand(spill_offset + core_spill_size)); |
| 168 | base = new_base; |
| 169 | spill_offset = -core_spill_size; |
| 170 | int64_t new_max_ls_pair_offset = fp_spill_size - 2 * reg_size; |
| 171 | DCHECK(masm->IsImmLSPair(spill_offset, ls_access_size)); |
| 172 | DCHECK(masm->IsImmLSPair(new_max_ls_pair_offset, ls_access_size)); |
| 173 | } |
| 174 | |
| 175 | if (is_save) { |
| 176 | __ StoreCPURegList(core_list, MemOperand(base, spill_offset)); |
| 177 | __ StoreCPURegList(fp_list, MemOperand(base, spill_offset + core_spill_size)); |
| 178 | } else { |
| 179 | __ LoadCPURegList(core_list, MemOperand(base, spill_offset)); |
| 180 | __ LoadCPURegList(fp_list, MemOperand(base, spill_offset + core_spill_size)); |
| 181 | } |
| 182 | } |
| 183 | |
| 184 | void SlowPathCodeARM64::SaveLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) { |
| 185 | RegisterSet* register_set = locations->GetLiveRegisters(); |
| 186 | size_t stack_offset = codegen->GetFirstRegisterSlotInSlowPath(); |
| 187 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 188 | if (!codegen->IsCoreCalleeSaveRegister(i) && register_set->ContainsCoreRegister(i)) { |
| 189 | // If the register holds an object, update the stack mask. |
| 190 | if (locations->RegisterContainsObject(i)) { |
| 191 | locations->SetStackBit(stack_offset / kVRegSize); |
| 192 | } |
| 193 | DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 194 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 195 | saved_core_stack_offsets_[i] = stack_offset; |
| 196 | stack_offset += kXRegSizeInBytes; |
| 197 | } |
| 198 | } |
| 199 | |
| 200 | for (size_t i = 0, e = codegen->GetNumberOfFloatingPointRegisters(); i < e; ++i) { |
| 201 | if (!codegen->IsFloatingPointCalleeSaveRegister(i) && |
| 202 | register_set->ContainsFloatingPointRegister(i)) { |
| 203 | DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 204 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 205 | saved_fpu_stack_offsets_[i] = stack_offset; |
| 206 | stack_offset += kDRegSizeInBytes; |
| 207 | } |
| 208 | } |
| 209 | |
| 210 | SaveRestoreLiveRegistersHelper(codegen, register_set, |
| 211 | codegen->GetFirstRegisterSlotInSlowPath(), true /* is_save */); |
| 212 | } |
| 213 | |
| 214 | void SlowPathCodeARM64::RestoreLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) { |
| 215 | RegisterSet* register_set = locations->GetLiveRegisters(); |
| 216 | SaveRestoreLiveRegistersHelper(codegen, register_set, |
| 217 | codegen->GetFirstRegisterSlotInSlowPath(), false /* is_save */); |
| 218 | } |
| 219 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 220 | class BoundsCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 221 | public: |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 222 | explicit BoundsCheckSlowPathARM64(HBoundsCheck* instruction) : instruction_(instruction) {} |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 223 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 224 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 225 | LocationSummary* locations = instruction_->GetLocations(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 226 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 227 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 228 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 229 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 230 | // Live registers will be restored in the catch block if caught. |
| 231 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 232 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 233 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 234 | // move resolver. |
| 235 | InvokeRuntimeCallingConvention calling_convention; |
| 236 | codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 237 | locations->InAt(0), LocationFrom(calling_convention.GetRegisterAt(0)), Primitive::kPrimInt, |
| 238 | locations->InAt(1), LocationFrom(calling_convention.GetRegisterAt(1)), Primitive::kPrimInt); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 239 | arm64_codegen->InvokeRuntime( |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 240 | QUICK_ENTRY_POINT(pThrowArrayBounds), instruction_, instruction_->GetDexPc(), this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 241 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 242 | } |
| 243 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 244 | bool IsFatal() const OVERRIDE { return true; } |
| 245 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 246 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathARM64"; } |
| 247 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 248 | private: |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 249 | HBoundsCheck* const instruction_; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 250 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 251 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathARM64); |
| 252 | }; |
| 253 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 254 | class DivZeroCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 255 | public: |
| 256 | explicit DivZeroCheckSlowPathARM64(HDivZeroCheck* instruction) : instruction_(instruction) {} |
| 257 | |
| 258 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 259 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 260 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 261 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 262 | // Live registers will be restored in the catch block if caught. |
| 263 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 264 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 265 | arm64_codegen->InvokeRuntime( |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 266 | QUICK_ENTRY_POINT(pThrowDivZero), instruction_, instruction_->GetDexPc(), this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 267 | CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 268 | } |
| 269 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 270 | bool IsFatal() const OVERRIDE { return true; } |
| 271 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 272 | const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathARM64"; } |
| 273 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 274 | private: |
| 275 | HDivZeroCheck* const instruction_; |
| 276 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathARM64); |
| 277 | }; |
| 278 | |
| 279 | class LoadClassSlowPathARM64 : public SlowPathCodeARM64 { |
| 280 | public: |
| 281 | LoadClassSlowPathARM64(HLoadClass* cls, |
| 282 | HInstruction* at, |
| 283 | uint32_t dex_pc, |
| 284 | bool do_clinit) |
| 285 | : cls_(cls), at_(at), dex_pc_(dex_pc), do_clinit_(do_clinit) { |
| 286 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 287 | } |
| 288 | |
| 289 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 290 | LocationSummary* locations = at_->GetLocations(); |
| 291 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 292 | |
| 293 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 294 | SaveLiveRegisters(codegen, locations); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 295 | |
| 296 | InvokeRuntimeCallingConvention calling_convention; |
| 297 | __ Mov(calling_convention.GetRegisterAt(0).W(), cls_->GetTypeIndex()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 298 | int32_t entry_point_offset = do_clinit_ ? QUICK_ENTRY_POINT(pInitializeStaticStorage) |
| 299 | : QUICK_ENTRY_POINT(pInitializeType); |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 300 | arm64_codegen->InvokeRuntime(entry_point_offset, at_, dex_pc_, this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 301 | if (do_clinit_) { |
Vladimir Marko | 5ea536a | 2015-04-20 20:11:30 +0100 | [diff] [blame] | 302 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>(); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 303 | } else { |
Vladimir Marko | 5ea536a | 2015-04-20 20:11:30 +0100 | [diff] [blame] | 304 | CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>(); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 305 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 306 | |
| 307 | // Move the class to the desired location. |
| 308 | Location out = locations->Out(); |
| 309 | if (out.IsValid()) { |
| 310 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
| 311 | Primitive::Type type = at_->GetType(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 312 | arm64_codegen->MoveLocation(out, calling_convention.GetReturnLocation(type), type); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 313 | } |
| 314 | |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 315 | RestoreLiveRegisters(codegen, locations); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 316 | __ B(GetExitLabel()); |
| 317 | } |
| 318 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 319 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathARM64"; } |
| 320 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 321 | private: |
| 322 | // The class this slow path will load. |
| 323 | HLoadClass* const cls_; |
| 324 | |
| 325 | // The instruction where this slow path is happening. |
| 326 | // (Might be the load class or an initialization check). |
| 327 | HInstruction* const at_; |
| 328 | |
| 329 | // The dex PC of `at_`. |
| 330 | const uint32_t dex_pc_; |
| 331 | |
| 332 | // Whether to initialize the class. |
| 333 | const bool do_clinit_; |
| 334 | |
| 335 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathARM64); |
| 336 | }; |
| 337 | |
| 338 | class LoadStringSlowPathARM64 : public SlowPathCodeARM64 { |
| 339 | public: |
| 340 | explicit LoadStringSlowPathARM64(HLoadString* instruction) : instruction_(instruction) {} |
| 341 | |
| 342 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 343 | LocationSummary* locations = instruction_->GetLocations(); |
| 344 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 345 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 346 | |
| 347 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 348 | SaveLiveRegisters(codegen, locations); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 349 | |
| 350 | InvokeRuntimeCallingConvention calling_convention; |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 351 | __ Mov(calling_convention.GetRegisterAt(0).W(), instruction_->GetStringIndex()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 352 | arm64_codegen->InvokeRuntime( |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 353 | QUICK_ENTRY_POINT(pResolveString), instruction_, instruction_->GetDexPc(), this); |
Vladimir Marko | 5ea536a | 2015-04-20 20:11:30 +0100 | [diff] [blame] | 354 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 355 | Primitive::Type type = instruction_->GetType(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 356 | arm64_codegen->MoveLocation(locations->Out(), calling_convention.GetReturnLocation(type), type); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 357 | |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 358 | RestoreLiveRegisters(codegen, locations); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 359 | __ B(GetExitLabel()); |
| 360 | } |
| 361 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 362 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathARM64"; } |
| 363 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 364 | private: |
| 365 | HLoadString* const instruction_; |
| 366 | |
| 367 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathARM64); |
| 368 | }; |
| 369 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 370 | class NullCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 371 | public: |
| 372 | explicit NullCheckSlowPathARM64(HNullCheck* instr) : instruction_(instr) {} |
| 373 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 374 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 375 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 376 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 377 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 378 | // Live registers will be restored in the catch block if caught. |
| 379 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 380 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 381 | arm64_codegen->InvokeRuntime( |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 382 | QUICK_ENTRY_POINT(pThrowNullPointer), instruction_, instruction_->GetDexPc(), this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 383 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 384 | } |
| 385 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 386 | bool IsFatal() const OVERRIDE { return true; } |
| 387 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 388 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathARM64"; } |
| 389 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 390 | private: |
| 391 | HNullCheck* const instruction_; |
| 392 | |
| 393 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathARM64); |
| 394 | }; |
| 395 | |
| 396 | class SuspendCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 397 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 398 | SuspendCheckSlowPathARM64(HSuspendCheck* instruction, HBasicBlock* successor) |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 399 | : instruction_(instruction), successor_(successor) {} |
| 400 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 401 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 402 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 403 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 404 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 405 | arm64_codegen->InvokeRuntime( |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 406 | QUICK_ENTRY_POINT(pTestSuspend), instruction_, instruction_->GetDexPc(), this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 407 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 408 | RestoreLiveRegisters(codegen, instruction_->GetLocations()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 409 | if (successor_ == nullptr) { |
| 410 | __ B(GetReturnLabel()); |
| 411 | } else { |
| 412 | __ B(arm64_codegen->GetLabelOf(successor_)); |
| 413 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 414 | } |
| 415 | |
| 416 | vixl::Label* GetReturnLabel() { |
| 417 | DCHECK(successor_ == nullptr); |
| 418 | return &return_label_; |
| 419 | } |
| 420 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 421 | HBasicBlock* GetSuccessor() const { |
| 422 | return successor_; |
| 423 | } |
| 424 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 425 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathARM64"; } |
| 426 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 427 | private: |
| 428 | HSuspendCheck* const instruction_; |
| 429 | // If not null, the block to branch to after the suspend check. |
| 430 | HBasicBlock* const successor_; |
| 431 | |
| 432 | // If `successor_` is null, the label to branch to after the suspend check. |
| 433 | vixl::Label return_label_; |
| 434 | |
| 435 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathARM64); |
| 436 | }; |
| 437 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 438 | class TypeCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 439 | public: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 440 | TypeCheckSlowPathARM64(HInstruction* instruction, bool is_fatal) |
| 441 | : instruction_(instruction), is_fatal_(is_fatal) {} |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 442 | |
| 443 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 444 | LocationSummary* locations = instruction_->GetLocations(); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 445 | Location class_to_check = locations->InAt(1); |
| 446 | Location object_class = instruction_->IsCheckCast() ? locations->GetTemp(0) |
| 447 | : locations->Out(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 448 | DCHECK(instruction_->IsCheckCast() |
| 449 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 450 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 451 | uint32_t dex_pc = instruction_->GetDexPc(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 452 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 453 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 454 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 455 | if (!is_fatal_) { |
| 456 | SaveLiveRegisters(codegen, locations); |
| 457 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 458 | |
| 459 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 460 | // move resolver. |
| 461 | InvokeRuntimeCallingConvention calling_convention; |
| 462 | codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 463 | class_to_check, LocationFrom(calling_convention.GetRegisterAt(0)), Primitive::kPrimNot, |
| 464 | object_class, LocationFrom(calling_convention.GetRegisterAt(1)), Primitive::kPrimNot); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 465 | |
| 466 | if (instruction_->IsInstanceOf()) { |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 467 | arm64_codegen->InvokeRuntime( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 468 | QUICK_ENTRY_POINT(pInstanceofNonTrivial), instruction_, dex_pc, this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 469 | CheckEntrypointTypes<kQuickInstanceofNonTrivial, uint32_t, |
| 470 | const mirror::Class*, const mirror::Class*>(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 471 | Primitive::Type ret_type = instruction_->GetType(); |
| 472 | Location ret_loc = calling_convention.GetReturnLocation(ret_type); |
| 473 | arm64_codegen->MoveLocation(locations->Out(), ret_loc, ret_type); |
| 474 | } else { |
| 475 | DCHECK(instruction_->IsCheckCast()); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 476 | arm64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pCheckCast), instruction_, dex_pc, this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 477 | CheckEntrypointTypes<kQuickCheckCast, void, const mirror::Class*, const mirror::Class*>(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 478 | } |
| 479 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 480 | if (!is_fatal_) { |
| 481 | RestoreLiveRegisters(codegen, locations); |
| 482 | __ B(GetExitLabel()); |
| 483 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 484 | } |
| 485 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 486 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathARM64"; } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 487 | bool IsFatal() const { return is_fatal_; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 488 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 489 | private: |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 490 | HInstruction* const instruction_; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 491 | const bool is_fatal_; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 492 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 493 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathARM64); |
| 494 | }; |
| 495 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 496 | class DeoptimizationSlowPathARM64 : public SlowPathCodeARM64 { |
| 497 | public: |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 498 | explicit DeoptimizationSlowPathARM64(HDeoptimize* instruction) |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 499 | : instruction_(instruction) {} |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 500 | |
| 501 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 502 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 503 | __ Bind(GetEntryLabel()); |
| 504 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 505 | arm64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pDeoptimize), |
| 506 | instruction_, |
| 507 | instruction_->GetDexPc(), |
| 508 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 509 | CheckEntrypointTypes<kQuickDeoptimize, void, void>(); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 510 | } |
| 511 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 512 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathARM64"; } |
| 513 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 514 | private: |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 515 | HDeoptimize* const instruction_; |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 516 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathARM64); |
| 517 | }; |
| 518 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 519 | class ArraySetSlowPathARM64 : public SlowPathCodeARM64 { |
| 520 | public: |
| 521 | explicit ArraySetSlowPathARM64(HInstruction* instruction) : instruction_(instruction) {} |
| 522 | |
| 523 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 524 | LocationSummary* locations = instruction_->GetLocations(); |
| 525 | __ Bind(GetEntryLabel()); |
| 526 | SaveLiveRegisters(codegen, locations); |
| 527 | |
| 528 | InvokeRuntimeCallingConvention calling_convention; |
| 529 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 530 | parallel_move.AddMove( |
| 531 | locations->InAt(0), |
| 532 | LocationFrom(calling_convention.GetRegisterAt(0)), |
| 533 | Primitive::kPrimNot, |
| 534 | nullptr); |
| 535 | parallel_move.AddMove( |
| 536 | locations->InAt(1), |
| 537 | LocationFrom(calling_convention.GetRegisterAt(1)), |
| 538 | Primitive::kPrimInt, |
| 539 | nullptr); |
| 540 | parallel_move.AddMove( |
| 541 | locations->InAt(2), |
| 542 | LocationFrom(calling_convention.GetRegisterAt(2)), |
| 543 | Primitive::kPrimNot, |
| 544 | nullptr); |
| 545 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 546 | |
| 547 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 548 | arm64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject), |
| 549 | instruction_, |
| 550 | instruction_->GetDexPc(), |
| 551 | this); |
| 552 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
| 553 | RestoreLiveRegisters(codegen, locations); |
| 554 | __ B(GetExitLabel()); |
| 555 | } |
| 556 | |
| 557 | const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathARM64"; } |
| 558 | |
| 559 | private: |
| 560 | HInstruction* const instruction_; |
| 561 | |
| 562 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathARM64); |
| 563 | }; |
| 564 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 565 | void JumpTableARM64::EmitTable(CodeGeneratorARM64* codegen) { |
| 566 | uint32_t num_entries = switch_instr_->GetNumEntries(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 567 | DCHECK_GE(num_entries, kPackedSwitchCompareJumpThreshold); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 568 | |
| 569 | // We are about to use the assembler to place literals directly. Make sure we have enough |
| 570 | // underlying code buffer and we have generated the jump table with right size. |
| 571 | CodeBufferCheckScope scope(codegen->GetVIXLAssembler(), num_entries * sizeof(int32_t), |
| 572 | CodeBufferCheckScope::kCheck, CodeBufferCheckScope::kExactSize); |
| 573 | |
| 574 | __ Bind(&table_start_); |
| 575 | const ArenaVector<HBasicBlock*>& successors = switch_instr_->GetBlock()->GetSuccessors(); |
| 576 | for (uint32_t i = 0; i < num_entries; i++) { |
| 577 | vixl::Label* target_label = codegen->GetLabelOf(successors[i]); |
| 578 | DCHECK(target_label->IsBound()); |
| 579 | ptrdiff_t jump_offset = target_label->location() - table_start_.location(); |
| 580 | DCHECK_GT(jump_offset, std::numeric_limits<int32_t>::min()); |
| 581 | DCHECK_LE(jump_offset, std::numeric_limits<int32_t>::max()); |
| 582 | Literal<int32_t> literal(jump_offset); |
| 583 | __ place(&literal); |
| 584 | } |
| 585 | } |
| 586 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 587 | // Slow path generating a read barrier for a heap reference. |
| 588 | class ReadBarrierForHeapReferenceSlowPathARM64 : public SlowPathCodeARM64 { |
| 589 | public: |
| 590 | ReadBarrierForHeapReferenceSlowPathARM64(HInstruction* instruction, |
| 591 | Location out, |
| 592 | Location ref, |
| 593 | Location obj, |
| 594 | uint32_t offset, |
| 595 | Location index) |
| 596 | : instruction_(instruction), |
| 597 | out_(out), |
| 598 | ref_(ref), |
| 599 | obj_(obj), |
| 600 | offset_(offset), |
| 601 | index_(index) { |
| 602 | DCHECK(kEmitCompilerReadBarrier); |
| 603 | // If `obj` is equal to `out` or `ref`, it means the initial object |
| 604 | // has been overwritten by (or after) the heap object reference load |
| 605 | // to be instrumented, e.g.: |
| 606 | // |
| 607 | // __ Ldr(out, HeapOperand(out, class_offset); |
| 608 | // codegen_->GenerateReadBarrier(instruction, out_loc, out_loc, out_loc, offset); |
| 609 | // |
| 610 | // In that case, we have lost the information about the original |
| 611 | // object, and the emitted read barrier cannot work properly. |
| 612 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 613 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 614 | } |
| 615 | |
| 616 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 617 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 618 | LocationSummary* locations = instruction_->GetLocations(); |
| 619 | Primitive::Type type = Primitive::kPrimNot; |
| 620 | DCHECK(locations->CanCall()); |
| 621 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(out_.reg())); |
| 622 | DCHECK(!instruction_->IsInvoke() || |
| 623 | (instruction_->IsInvokeStaticOrDirect() && |
| 624 | instruction_->GetLocations()->Intrinsified())); |
Roland Levillain | cd3d0fb | 2016-01-15 19:26:48 +0000 | [diff] [blame] | 625 | // The read barrier instrumentation does not support the |
| 626 | // HArm64IntermediateAddress instruction yet. |
| 627 | DCHECK(!(instruction_->IsArrayGet() && |
| 628 | instruction_->AsArrayGet()->GetArray()->IsArm64IntermediateAddress())); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 629 | |
| 630 | __ Bind(GetEntryLabel()); |
| 631 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 632 | SaveLiveRegisters(codegen, locations); |
| 633 | |
| 634 | // We may have to change the index's value, but as `index_` is a |
| 635 | // constant member (like other "inputs" of this slow path), |
| 636 | // introduce a copy of it, `index`. |
| 637 | Location index = index_; |
| 638 | if (index_.IsValid()) { |
| 639 | // Handle `index_` for HArrayGet and intrinsic UnsafeGetObject. |
| 640 | if (instruction_->IsArrayGet()) { |
| 641 | // Compute the actual memory offset and store it in `index`. |
| 642 | Register index_reg = RegisterFrom(index_, Primitive::kPrimInt); |
| 643 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_.reg())); |
| 644 | if (codegen->IsCoreCalleeSaveRegister(index_.reg())) { |
| 645 | // We are about to change the value of `index_reg` (see the |
| 646 | // calls to vixl::MacroAssembler::Lsl and |
| 647 | // vixl::MacroAssembler::Mov below), but it has |
| 648 | // not been saved by the previous call to |
| 649 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 650 | // callee-save register -- |
| 651 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 652 | // callee-save registers, as it has been designed with the |
| 653 | // assumption that callee-save registers are supposed to be |
| 654 | // handled by the called function. So, as a callee-save |
| 655 | // register, `index_reg` _would_ eventually be saved onto |
| 656 | // the stack, but it would be too late: we would have |
| 657 | // changed its value earlier. Therefore, we manually save |
| 658 | // it here into another freely available register, |
| 659 | // `free_reg`, chosen of course among the caller-save |
| 660 | // registers (as a callee-save `free_reg` register would |
| 661 | // exhibit the same problem). |
| 662 | // |
| 663 | // Note we could have requested a temporary register from |
| 664 | // the register allocator instead; but we prefer not to, as |
| 665 | // this is a slow path, and we know we can find a |
| 666 | // caller-save register that is available. |
| 667 | Register free_reg = FindAvailableCallerSaveRegister(codegen); |
| 668 | __ Mov(free_reg.W(), index_reg); |
| 669 | index_reg = free_reg; |
| 670 | index = LocationFrom(index_reg); |
| 671 | } else { |
| 672 | // The initial register stored in `index_` has already been |
| 673 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 674 | // (as it is not a callee-save register), so we can freely |
| 675 | // use it. |
| 676 | } |
| 677 | // Shifting the index value contained in `index_reg` by the scale |
| 678 | // factor (2) cannot overflow in practice, as the runtime is |
| 679 | // unable to allocate object arrays with a size larger than |
| 680 | // 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 681 | __ Lsl(index_reg, index_reg, Primitive::ComponentSizeShift(type)); |
| 682 | static_assert( |
| 683 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 684 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 685 | __ Add(index_reg, index_reg, Operand(offset_)); |
| 686 | } else { |
| 687 | DCHECK(instruction_->IsInvoke()); |
| 688 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 689 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 690 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 691 | << instruction_->AsInvoke()->GetIntrinsic(); |
| 692 | DCHECK_EQ(offset_, 0U); |
| 693 | DCHECK(index_.IsRegisterPair()); |
| 694 | // UnsafeGet's offset location is a register pair, the low |
| 695 | // part contains the correct offset. |
| 696 | index = index_.ToLow(); |
| 697 | } |
| 698 | } |
| 699 | |
| 700 | // We're moving two or three locations to locations that could |
| 701 | // overlap, so we need a parallel move resolver. |
| 702 | InvokeRuntimeCallingConvention calling_convention; |
| 703 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 704 | parallel_move.AddMove(ref_, |
| 705 | LocationFrom(calling_convention.GetRegisterAt(0)), |
| 706 | type, |
| 707 | nullptr); |
| 708 | parallel_move.AddMove(obj_, |
| 709 | LocationFrom(calling_convention.GetRegisterAt(1)), |
| 710 | type, |
| 711 | nullptr); |
| 712 | if (index.IsValid()) { |
| 713 | parallel_move.AddMove(index, |
| 714 | LocationFrom(calling_convention.GetRegisterAt(2)), |
| 715 | Primitive::kPrimInt, |
| 716 | nullptr); |
| 717 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 718 | } else { |
| 719 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 720 | arm64_codegen->MoveConstant(LocationFrom(calling_convention.GetRegisterAt(2)), offset_); |
| 721 | } |
| 722 | arm64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pReadBarrierSlow), |
| 723 | instruction_, |
| 724 | instruction_->GetDexPc(), |
| 725 | this); |
| 726 | CheckEntrypointTypes< |
| 727 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 728 | arm64_codegen->MoveLocation(out_, calling_convention.GetReturnLocation(type), type); |
| 729 | |
| 730 | RestoreLiveRegisters(codegen, locations); |
| 731 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 732 | __ B(GetExitLabel()); |
| 733 | } |
| 734 | |
| 735 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForHeapReferenceSlowPathARM64"; } |
| 736 | |
| 737 | private: |
| 738 | Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
| 739 | size_t ref = static_cast<int>(XRegisterFrom(ref_).code()); |
| 740 | size_t obj = static_cast<int>(XRegisterFrom(obj_).code()); |
| 741 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 742 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 743 | return Register(VIXLRegCodeFromART(i), kXRegSize); |
| 744 | } |
| 745 | } |
| 746 | // We shall never fail to find a free caller-save register, as |
| 747 | // there are more than two core caller-save registers on ARM64 |
| 748 | // (meaning it is possible to find one which is different from |
| 749 | // `ref` and `obj`). |
| 750 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 751 | LOG(FATAL) << "Could not find a free register"; |
| 752 | UNREACHABLE(); |
| 753 | } |
| 754 | |
| 755 | HInstruction* const instruction_; |
| 756 | const Location out_; |
| 757 | const Location ref_; |
| 758 | const Location obj_; |
| 759 | const uint32_t offset_; |
| 760 | // An additional location containing an index to an array. |
| 761 | // Only used for HArrayGet and the UnsafeGetObject & |
| 762 | // UnsafeGetObjectVolatile intrinsics. |
| 763 | const Location index_; |
| 764 | |
| 765 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathARM64); |
| 766 | }; |
| 767 | |
| 768 | // Slow path generating a read barrier for a GC root. |
| 769 | class ReadBarrierForRootSlowPathARM64 : public SlowPathCodeARM64 { |
| 770 | public: |
| 771 | ReadBarrierForRootSlowPathARM64(HInstruction* instruction, Location out, Location root) |
| 772 | : instruction_(instruction), out_(out), root_(root) {} |
| 773 | |
| 774 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 775 | LocationSummary* locations = instruction_->GetLocations(); |
| 776 | Primitive::Type type = Primitive::kPrimNot; |
| 777 | DCHECK(locations->CanCall()); |
| 778 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(out_.reg())); |
| 779 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()); |
| 780 | |
| 781 | __ Bind(GetEntryLabel()); |
| 782 | SaveLiveRegisters(codegen, locations); |
| 783 | |
| 784 | InvokeRuntimeCallingConvention calling_convention; |
| 785 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 786 | // The argument of the ReadBarrierForRootSlow is not a managed |
| 787 | // reference (`mirror::Object*`), but a `GcRoot<mirror::Object>*`; |
| 788 | // thus we need a 64-bit move here, and we cannot use |
| 789 | // |
| 790 | // arm64_codegen->MoveLocation( |
| 791 | // LocationFrom(calling_convention.GetRegisterAt(0)), |
| 792 | // root_, |
| 793 | // type); |
| 794 | // |
| 795 | // which would emit a 32-bit move, as `type` is a (32-bit wide) |
| 796 | // reference type (`Primitive::kPrimNot`). |
| 797 | __ Mov(calling_convention.GetRegisterAt(0), XRegisterFrom(out_)); |
| 798 | arm64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pReadBarrierForRootSlow), |
| 799 | instruction_, |
| 800 | instruction_->GetDexPc(), |
| 801 | this); |
| 802 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 803 | arm64_codegen->MoveLocation(out_, calling_convention.GetReturnLocation(type), type); |
| 804 | |
| 805 | RestoreLiveRegisters(codegen, locations); |
| 806 | __ B(GetExitLabel()); |
| 807 | } |
| 808 | |
| 809 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathARM64"; } |
| 810 | |
| 811 | private: |
| 812 | HInstruction* const instruction_; |
| 813 | const Location out_; |
| 814 | const Location root_; |
| 815 | |
| 816 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathARM64); |
| 817 | }; |
| 818 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 819 | #undef __ |
| 820 | |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 821 | Location InvokeDexCallingConventionVisitorARM64::GetNextLocation(Primitive::Type type) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 822 | Location next_location; |
| 823 | if (type == Primitive::kPrimVoid) { |
| 824 | LOG(FATAL) << "Unreachable type " << type; |
| 825 | } |
| 826 | |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 827 | if (Primitive::IsFloatingPointType(type) && |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 828 | (float_index_ < calling_convention.GetNumberOfFpuRegisters())) { |
| 829 | next_location = LocationFrom(calling_convention.GetFpuRegisterAt(float_index_++)); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 830 | } else if (!Primitive::IsFloatingPointType(type) && |
| 831 | (gp_index_ < calling_convention.GetNumberOfRegisters())) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 832 | next_location = LocationFrom(calling_convention.GetRegisterAt(gp_index_++)); |
| 833 | } else { |
| 834 | size_t stack_offset = calling_convention.GetStackOffsetOf(stack_index_); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 835 | next_location = Primitive::Is64BitType(type) ? Location::DoubleStackSlot(stack_offset) |
| 836 | : Location::StackSlot(stack_offset); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 837 | } |
| 838 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 839 | // Space on the stack is reserved for all arguments. |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 840 | stack_index_ += Primitive::Is64BitType(type) ? 2 : 1; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 841 | return next_location; |
| 842 | } |
| 843 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 844 | Location InvokeDexCallingConventionVisitorARM64::GetMethodLocation() const { |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 845 | return LocationFrom(kArtMethodRegister); |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 846 | } |
| 847 | |
Serban Constantinescu | 579885a | 2015-02-22 20:51:33 +0000 | [diff] [blame] | 848 | CodeGeneratorARM64::CodeGeneratorARM64(HGraph* graph, |
| 849 | const Arm64InstructionSetFeatures& isa_features, |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 850 | const CompilerOptions& compiler_options, |
| 851 | OptimizingCompilerStats* stats) |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 852 | : CodeGenerator(graph, |
| 853 | kNumberOfAllocatableRegisters, |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 854 | kNumberOfAllocatableFPRegisters, |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 855 | kNumberOfAllocatableRegisterPairs, |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 856 | callee_saved_core_registers.list(), |
Nicolas Geoffray | 75d5b9b | 2015-10-05 07:40:35 +0000 | [diff] [blame] | 857 | callee_saved_fp_registers.list(), |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 858 | compiler_options, |
| 859 | stats), |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 860 | block_labels_(nullptr), |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 861 | jump_tables_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 862 | location_builder_(graph, this), |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 863 | instruction_visitor_(graph, this), |
Serban Constantinescu | 579885a | 2015-02-22 20:51:33 +0000 | [diff] [blame] | 864 | move_resolver_(graph->GetArena(), this), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 865 | isa_features_(isa_features), |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 866 | uint64_literals_(std::less<uint64_t>(), |
| 867 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 868 | method_patches_(MethodReferenceComparator(), |
| 869 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 870 | call_patches_(MethodReferenceComparator(), |
| 871 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 872 | relative_call_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 873 | pc_relative_dex_cache_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 874 | // Save the link register (containing the return address) to mimic Quick. |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 875 | AddAllocatedRegister(LocationFrom(lr)); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 876 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 877 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 878 | #define __ GetVIXLAssembler()-> |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 879 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 880 | void CodeGeneratorARM64::EmitJumpTables() { |
| 881 | for (auto jump_table : jump_tables_) { |
| 882 | jump_table->EmitTable(this); |
| 883 | } |
| 884 | } |
| 885 | |
Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 886 | void CodeGeneratorARM64::Finalize(CodeAllocator* allocator) { |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 887 | EmitJumpTables(); |
Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 888 | // Ensure we emit the literal pool. |
| 889 | __ FinalizeCode(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 890 | |
Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 891 | CodeGenerator::Finalize(allocator); |
| 892 | } |
| 893 | |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 894 | void ParallelMoveResolverARM64::PrepareForEmitNativeCode() { |
| 895 | // Note: There are 6 kinds of moves: |
| 896 | // 1. constant -> GPR/FPR (non-cycle) |
| 897 | // 2. constant -> stack (non-cycle) |
| 898 | // 3. GPR/FPR -> GPR/FPR |
| 899 | // 4. GPR/FPR -> stack |
| 900 | // 5. stack -> GPR/FPR |
| 901 | // 6. stack -> stack (non-cycle) |
| 902 | // Case 1, 2 and 6 should never be included in a dependency cycle on ARM64. For case 3, 4, and 5 |
| 903 | // VIXL uses at most 1 GPR. VIXL has 2 GPR and 1 FPR temps, and there should be no intersecting |
| 904 | // cycles on ARM64, so we always have 1 GPR and 1 FPR available VIXL temps to resolve the |
| 905 | // dependency. |
| 906 | vixl_temps_.Open(GetVIXLAssembler()); |
| 907 | } |
| 908 | |
| 909 | void ParallelMoveResolverARM64::FinishEmitNativeCode() { |
| 910 | vixl_temps_.Close(); |
| 911 | } |
| 912 | |
| 913 | Location ParallelMoveResolverARM64::AllocateScratchLocationFor(Location::Kind kind) { |
| 914 | DCHECK(kind == Location::kRegister || kind == Location::kFpuRegister || |
| 915 | kind == Location::kStackSlot || kind == Location::kDoubleStackSlot); |
| 916 | kind = (kind == Location::kFpuRegister) ? Location::kFpuRegister : Location::kRegister; |
| 917 | Location scratch = GetScratchLocation(kind); |
| 918 | if (!scratch.Equals(Location::NoLocation())) { |
| 919 | return scratch; |
| 920 | } |
| 921 | // Allocate from VIXL temp registers. |
| 922 | if (kind == Location::kRegister) { |
| 923 | scratch = LocationFrom(vixl_temps_.AcquireX()); |
| 924 | } else { |
| 925 | DCHECK(kind == Location::kFpuRegister); |
| 926 | scratch = LocationFrom(vixl_temps_.AcquireD()); |
| 927 | } |
| 928 | AddScratchLocation(scratch); |
| 929 | return scratch; |
| 930 | } |
| 931 | |
| 932 | void ParallelMoveResolverARM64::FreeScratchLocation(Location loc) { |
| 933 | if (loc.IsRegister()) { |
| 934 | vixl_temps_.Release(XRegisterFrom(loc)); |
| 935 | } else { |
| 936 | DCHECK(loc.IsFpuRegister()); |
| 937 | vixl_temps_.Release(DRegisterFrom(loc)); |
| 938 | } |
| 939 | RemoveScratchLocation(loc); |
| 940 | } |
| 941 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 942 | void ParallelMoveResolverARM64::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 943 | MoveOperands* move = moves_[index]; |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 944 | codegen_->MoveLocation(move->GetDestination(), move->GetSource(), Primitive::kPrimVoid); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 945 | } |
| 946 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 947 | void CodeGeneratorARM64::GenerateFrameEntry() { |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 948 | MacroAssembler* masm = GetVIXLAssembler(); |
| 949 | BlockPoolsScope block_pools(masm); |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 950 | __ Bind(&frame_entry_label_); |
| 951 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 952 | bool do_overflow_check = FrameNeedsStackCheck(GetFrameSize(), kArm64) || !IsLeafMethod(); |
| 953 | if (do_overflow_check) { |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 954 | UseScratchRegisterScope temps(masm); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 955 | Register temp = temps.AcquireX(); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 956 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 957 | __ Sub(temp, sp, static_cast<int32_t>(GetStackOverflowReservedBytes(kArm64))); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 958 | __ Ldr(wzr, MemOperand(temp, 0)); |
| 959 | RecordPcInfo(nullptr, 0); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 960 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 961 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 962 | if (!HasEmptyFrame()) { |
| 963 | int frame_size = GetFrameSize(); |
| 964 | // Stack layout: |
| 965 | // sp[frame_size - 8] : lr. |
| 966 | // ... : other preserved core registers. |
| 967 | // ... : other preserved fp registers. |
| 968 | // ... : reserved frame space. |
| 969 | // sp[0] : current method. |
| 970 | __ Str(kArtMethodRegister, MemOperand(sp, -frame_size, PreIndex)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 971 | GetAssembler()->cfi().AdjustCFAOffset(frame_size); |
Zheng Xu | 69a5030 | 2015-04-14 20:04:41 +0800 | [diff] [blame] | 972 | GetAssembler()->SpillRegisters(GetFramePreservedCoreRegisters(), |
| 973 | frame_size - GetCoreSpillSize()); |
| 974 | GetAssembler()->SpillRegisters(GetFramePreservedFPRegisters(), |
| 975 | frame_size - FrameEntrySpillSize()); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 976 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 977 | } |
| 978 | |
| 979 | void CodeGeneratorARM64::GenerateFrameExit() { |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 980 | BlockPoolsScope block_pools(GetVIXLAssembler()); |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 981 | GetAssembler()->cfi().RememberState(); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 982 | if (!HasEmptyFrame()) { |
| 983 | int frame_size = GetFrameSize(); |
Zheng Xu | 69a5030 | 2015-04-14 20:04:41 +0800 | [diff] [blame] | 984 | GetAssembler()->UnspillRegisters(GetFramePreservedFPRegisters(), |
| 985 | frame_size - FrameEntrySpillSize()); |
| 986 | GetAssembler()->UnspillRegisters(GetFramePreservedCoreRegisters(), |
| 987 | frame_size - GetCoreSpillSize()); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 988 | __ Drop(frame_size); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 989 | GetAssembler()->cfi().AdjustCFAOffset(-frame_size); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 990 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 991 | __ Ret(); |
| 992 | GetAssembler()->cfi().RestoreState(); |
| 993 | GetAssembler()->cfi().DefCFAOffset(GetFrameSize()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 994 | } |
| 995 | |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 996 | vixl::CPURegList CodeGeneratorARM64::GetFramePreservedCoreRegisters() const { |
| 997 | DCHECK(ArtVixlRegCodeCoherentForRegSet(core_spill_mask_, GetNumberOfCoreRegisters(), 0, 0)); |
| 998 | return vixl::CPURegList(vixl::CPURegister::kRegister, vixl::kXRegSize, |
| 999 | core_spill_mask_); |
| 1000 | } |
| 1001 | |
| 1002 | vixl::CPURegList CodeGeneratorARM64::GetFramePreservedFPRegisters() const { |
| 1003 | DCHECK(ArtVixlRegCodeCoherentForRegSet(0, 0, fpu_spill_mask_, |
| 1004 | GetNumberOfFloatingPointRegisters())); |
| 1005 | return vixl::CPURegList(vixl::CPURegister::kFPRegister, vixl::kDRegSize, |
| 1006 | fpu_spill_mask_); |
| 1007 | } |
| 1008 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1009 | void CodeGeneratorARM64::Bind(HBasicBlock* block) { |
| 1010 | __ Bind(GetLabelOf(block)); |
| 1011 | } |
| 1012 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1013 | void CodeGeneratorARM64::Move(HInstruction* instruction, |
| 1014 | Location location, |
| 1015 | HInstruction* move_for) { |
| 1016 | LocationSummary* locations = instruction->GetLocations(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1017 | Primitive::Type type = instruction->GetType(); |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1018 | DCHECK_NE(type, Primitive::kPrimVoid); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1019 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 1020 | if (instruction->IsCurrentMethod()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1021 | MoveLocation(location, |
| 1022 | Location::DoubleStackSlot(kCurrentMethodStackOffset), |
| 1023 | Primitive::kPrimVoid); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 1024 | } else if (locations != nullptr && locations->Out().Equals(location)) { |
| 1025 | return; |
| 1026 | } else if (instruction->IsIntConstant() |
| 1027 | || instruction->IsLongConstant() |
| 1028 | || instruction->IsNullConstant()) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1029 | int64_t value = GetInt64ValueOf(instruction->AsConstant()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1030 | if (location.IsRegister()) { |
| 1031 | Register dst = RegisterFrom(location, type); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1032 | DCHECK(((instruction->IsIntConstant() || instruction->IsNullConstant()) && dst.Is32Bits()) || |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1033 | (instruction->IsLongConstant() && dst.Is64Bits())); |
| 1034 | __ Mov(dst, value); |
| 1035 | } else { |
| 1036 | DCHECK(location.IsStackSlot() || location.IsDoubleStackSlot()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1037 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1038 | Register temp = (instruction->IsIntConstant() || instruction->IsNullConstant()) |
| 1039 | ? temps.AcquireW() |
| 1040 | : temps.AcquireX(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1041 | __ Mov(temp, value); |
| 1042 | __ Str(temp, StackOperandFrom(location)); |
| 1043 | } |
Nicolas Geoffray | f43083d | 2014-11-07 10:48:10 +0000 | [diff] [blame] | 1044 | } else if (instruction->IsTemporary()) { |
| 1045 | Location temp_location = GetTemporaryLocation(instruction->AsTemporary()); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1046 | MoveLocation(location, temp_location, type); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1047 | } else if (instruction->IsLoadLocal()) { |
| 1048 | uint32_t stack_slot = GetStackSlot(instruction->AsLoadLocal()->GetLocal()); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 1049 | if (Primitive::Is64BitType(type)) { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1050 | MoveLocation(location, Location::DoubleStackSlot(stack_slot), type); |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1051 | } else { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1052 | MoveLocation(location, Location::StackSlot(stack_slot), type); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1053 | } |
| 1054 | |
| 1055 | } else { |
| 1056 | DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary()); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1057 | MoveLocation(location, locations->Out(), type); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1058 | } |
| 1059 | } |
| 1060 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1061 | void CodeGeneratorARM64::MoveConstant(Location location, int32_t value) { |
| 1062 | DCHECK(location.IsRegister()); |
| 1063 | __ Mov(RegisterFrom(location, Primitive::kPrimInt), value); |
| 1064 | } |
| 1065 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1066 | void CodeGeneratorARM64::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1067 | if (location.IsRegister()) { |
| 1068 | locations->AddTemp(location); |
| 1069 | } else { |
| 1070 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1071 | } |
| 1072 | } |
| 1073 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1074 | Location CodeGeneratorARM64::GetStackLocation(HLoadLocal* load) const { |
| 1075 | Primitive::Type type = load->GetType(); |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1076 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1077 | switch (type) { |
| 1078 | case Primitive::kPrimNot: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1079 | case Primitive::kPrimInt: |
| 1080 | case Primitive::kPrimFloat: |
| 1081 | return Location::StackSlot(GetStackSlot(load->GetLocal())); |
| 1082 | |
| 1083 | case Primitive::kPrimLong: |
| 1084 | case Primitive::kPrimDouble: |
| 1085 | return Location::DoubleStackSlot(GetStackSlot(load->GetLocal())); |
| 1086 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1087 | case Primitive::kPrimBoolean: |
| 1088 | case Primitive::kPrimByte: |
| 1089 | case Primitive::kPrimChar: |
| 1090 | case Primitive::kPrimShort: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1091 | case Primitive::kPrimVoid: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1092 | LOG(FATAL) << "Unexpected type " << type; |
| 1093 | } |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1094 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1095 | LOG(FATAL) << "Unreachable"; |
| 1096 | return Location::NoLocation(); |
| 1097 | } |
| 1098 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1099 | void CodeGeneratorARM64::MarkGCCard(Register object, Register value, bool value_can_be_null) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1100 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1101 | Register card = temps.AcquireX(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1102 | Register temp = temps.AcquireW(); // Index within the CardTable - 32bit. |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1103 | vixl::Label done; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1104 | if (value_can_be_null) { |
| 1105 | __ Cbz(value, &done); |
| 1106 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1107 | __ Ldr(card, MemOperand(tr, Thread::CardTableOffset<kArm64WordSize>().Int32Value())); |
| 1108 | __ Lsr(temp, object, gc::accounting::CardTable::kCardShift); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1109 | __ Strb(card, MemOperand(card, temp.X())); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1110 | if (value_can_be_null) { |
| 1111 | __ Bind(&done); |
| 1112 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1113 | } |
| 1114 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1115 | void CodeGeneratorARM64::SetupBlockedRegisters() const { |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1116 | // Blocked core registers: |
| 1117 | // lr : Runtime reserved. |
| 1118 | // tr : Runtime reserved. |
| 1119 | // xSuspend : Runtime reserved. TODO: Unblock this when the runtime stops using it. |
| 1120 | // ip1 : VIXL core temp. |
| 1121 | // ip0 : VIXL core temp. |
| 1122 | // |
| 1123 | // Blocked fp registers: |
| 1124 | // d31 : VIXL fp temp. |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1125 | CPURegList reserved_core_registers = vixl_reserved_core_registers; |
| 1126 | reserved_core_registers.Combine(runtime_reserved_core_registers); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1127 | while (!reserved_core_registers.IsEmpty()) { |
| 1128 | blocked_core_registers_[reserved_core_registers.PopLowestIndex().code()] = true; |
| 1129 | } |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1130 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1131 | CPURegList reserved_fp_registers = vixl_reserved_fp_registers; |
Zheng Xu | a3ec394 | 2015-02-15 18:39:46 +0800 | [diff] [blame] | 1132 | while (!reserved_fp_registers.IsEmpty()) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1133 | blocked_fpu_registers_[reserved_fp_registers.PopLowestIndex().code()] = true; |
| 1134 | } |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1135 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1136 | if (GetGraph()->IsDebuggable()) { |
Nicolas Geoffray | ecf680d | 2015-10-05 11:15:37 +0100 | [diff] [blame] | 1137 | // Stubs do not save callee-save floating point registers. If the graph |
| 1138 | // is debuggable, we need to deal with these registers differently. For |
| 1139 | // now, just block them. |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1140 | CPURegList reserved_fp_registers_debuggable = callee_saved_fp_registers; |
| 1141 | while (!reserved_fp_registers_debuggable.IsEmpty()) { |
| 1142 | blocked_fpu_registers_[reserved_fp_registers_debuggable.PopLowestIndex().code()] = true; |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1143 | } |
| 1144 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1145 | } |
| 1146 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1147 | size_t CodeGeneratorARM64::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1148 | Register reg = Register(VIXLRegCodeFromART(reg_id), kXRegSize); |
| 1149 | __ Str(reg, MemOperand(sp, stack_index)); |
| 1150 | return kArm64WordSize; |
| 1151 | } |
| 1152 | |
| 1153 | size_t CodeGeneratorARM64::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1154 | Register reg = Register(VIXLRegCodeFromART(reg_id), kXRegSize); |
| 1155 | __ Ldr(reg, MemOperand(sp, stack_index)); |
| 1156 | return kArm64WordSize; |
| 1157 | } |
| 1158 | |
| 1159 | size_t CodeGeneratorARM64::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 1160 | FPRegister reg = FPRegister(reg_id, kDRegSize); |
| 1161 | __ Str(reg, MemOperand(sp, stack_index)); |
| 1162 | return kArm64WordSize; |
| 1163 | } |
| 1164 | |
| 1165 | size_t CodeGeneratorARM64::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 1166 | FPRegister reg = FPRegister(reg_id, kDRegSize); |
| 1167 | __ Ldr(reg, MemOperand(sp, stack_index)); |
| 1168 | return kArm64WordSize; |
| 1169 | } |
| 1170 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1171 | void CodeGeneratorARM64::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1172 | stream << XRegister(reg); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1173 | } |
| 1174 | |
| 1175 | void CodeGeneratorARM64::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1176 | stream << DRegister(reg); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1177 | } |
| 1178 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1179 | void CodeGeneratorARM64::MoveConstant(CPURegister destination, HConstant* constant) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1180 | if (constant->IsIntConstant()) { |
| 1181 | __ Mov(Register(destination), constant->AsIntConstant()->GetValue()); |
| 1182 | } else if (constant->IsLongConstant()) { |
| 1183 | __ Mov(Register(destination), constant->AsLongConstant()->GetValue()); |
| 1184 | } else if (constant->IsNullConstant()) { |
| 1185 | __ Mov(Register(destination), 0); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1186 | } else if (constant->IsFloatConstant()) { |
| 1187 | __ Fmov(FPRegister(destination), constant->AsFloatConstant()->GetValue()); |
| 1188 | } else { |
| 1189 | DCHECK(constant->IsDoubleConstant()); |
| 1190 | __ Fmov(FPRegister(destination), constant->AsDoubleConstant()->GetValue()); |
| 1191 | } |
| 1192 | } |
| 1193 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1194 | |
| 1195 | static bool CoherentConstantAndType(Location constant, Primitive::Type type) { |
| 1196 | DCHECK(constant.IsConstant()); |
| 1197 | HConstant* cst = constant.GetConstant(); |
| 1198 | return (cst->IsIntConstant() && type == Primitive::kPrimInt) || |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1199 | // Null is mapped to a core W register, which we associate with kPrimInt. |
| 1200 | (cst->IsNullConstant() && type == Primitive::kPrimInt) || |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1201 | (cst->IsLongConstant() && type == Primitive::kPrimLong) || |
| 1202 | (cst->IsFloatConstant() && type == Primitive::kPrimFloat) || |
| 1203 | (cst->IsDoubleConstant() && type == Primitive::kPrimDouble); |
| 1204 | } |
| 1205 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1206 | void CodeGeneratorARM64::MoveLocation(Location destination, |
| 1207 | Location source, |
| 1208 | Primitive::Type dst_type) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1209 | if (source.Equals(destination)) { |
| 1210 | return; |
| 1211 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1212 | |
| 1213 | // A valid move can always be inferred from the destination and source |
| 1214 | // locations. When moving from and to a register, the argument type can be |
| 1215 | // used to generate 32bit instead of 64bit moves. In debug mode we also |
| 1216 | // checks the coherency of the locations and the type. |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1217 | bool unspecified_type = (dst_type == Primitive::kPrimVoid); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1218 | |
| 1219 | if (destination.IsRegister() || destination.IsFpuRegister()) { |
| 1220 | if (unspecified_type) { |
| 1221 | HConstant* src_cst = source.IsConstant() ? source.GetConstant() : nullptr; |
| 1222 | if (source.IsStackSlot() || |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1223 | (src_cst != nullptr && (src_cst->IsIntConstant() |
| 1224 | || src_cst->IsFloatConstant() |
| 1225 | || src_cst->IsNullConstant()))) { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1226 | // For stack slots and 32bit constants, a 64bit type is appropriate. |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1227 | dst_type = destination.IsRegister() ? Primitive::kPrimInt : Primitive::kPrimFloat; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1228 | } else { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1229 | // If the source is a double stack slot or a 64bit constant, a 64bit |
| 1230 | // type is appropriate. Else the source is a register, and since the |
| 1231 | // type has not been specified, we chose a 64bit type to force a 64bit |
| 1232 | // move. |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1233 | dst_type = destination.IsRegister() ? Primitive::kPrimLong : Primitive::kPrimDouble; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1234 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1235 | } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1236 | DCHECK((destination.IsFpuRegister() && Primitive::IsFloatingPointType(dst_type)) || |
| 1237 | (destination.IsRegister() && !Primitive::IsFloatingPointType(dst_type))); |
| 1238 | CPURegister dst = CPURegisterFrom(destination, dst_type); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1239 | if (source.IsStackSlot() || source.IsDoubleStackSlot()) { |
| 1240 | DCHECK(dst.Is64Bits() == source.IsDoubleStackSlot()); |
| 1241 | __ Ldr(dst, StackOperandFrom(source)); |
| 1242 | } else if (source.IsConstant()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1243 | DCHECK(CoherentConstantAndType(source, dst_type)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1244 | MoveConstant(dst, source.GetConstant()); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1245 | } else if (source.IsRegister()) { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1246 | if (destination.IsRegister()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1247 | __ Mov(Register(dst), RegisterFrom(source, dst_type)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1248 | } else { |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1249 | DCHECK(destination.IsFpuRegister()); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1250 | Primitive::Type source_type = Primitive::Is64BitType(dst_type) |
| 1251 | ? Primitive::kPrimLong |
| 1252 | : Primitive::kPrimInt; |
| 1253 | __ Fmov(FPRegisterFrom(destination, dst_type), RegisterFrom(source, source_type)); |
| 1254 | } |
| 1255 | } else { |
| 1256 | DCHECK(source.IsFpuRegister()); |
| 1257 | if (destination.IsRegister()) { |
| 1258 | Primitive::Type source_type = Primitive::Is64BitType(dst_type) |
| 1259 | ? Primitive::kPrimDouble |
| 1260 | : Primitive::kPrimFloat; |
| 1261 | __ Fmov(RegisterFrom(destination, dst_type), FPRegisterFrom(source, source_type)); |
| 1262 | } else { |
| 1263 | DCHECK(destination.IsFpuRegister()); |
| 1264 | __ Fmov(FPRegister(dst), FPRegisterFrom(source, dst_type)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1265 | } |
| 1266 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1267 | } else { // The destination is not a register. It must be a stack slot. |
| 1268 | DCHECK(destination.IsStackSlot() || destination.IsDoubleStackSlot()); |
| 1269 | if (source.IsRegister() || source.IsFpuRegister()) { |
| 1270 | if (unspecified_type) { |
| 1271 | if (source.IsRegister()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1272 | dst_type = destination.IsStackSlot() ? Primitive::kPrimInt : Primitive::kPrimLong; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1273 | } else { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1274 | dst_type = destination.IsStackSlot() ? Primitive::kPrimFloat : Primitive::kPrimDouble; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1275 | } |
| 1276 | } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1277 | DCHECK((destination.IsDoubleStackSlot() == Primitive::Is64BitType(dst_type)) && |
| 1278 | (source.IsFpuRegister() == Primitive::IsFloatingPointType(dst_type))); |
| 1279 | __ Str(CPURegisterFrom(source, dst_type), StackOperandFrom(destination)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1280 | } else if (source.IsConstant()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1281 | DCHECK(unspecified_type || CoherentConstantAndType(source, dst_type)) |
| 1282 | << source << " " << dst_type; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1283 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 1284 | HConstant* src_cst = source.GetConstant(); |
| 1285 | CPURegister temp; |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1286 | if (src_cst->IsIntConstant() || src_cst->IsNullConstant()) { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1287 | temp = temps.AcquireW(); |
| 1288 | } else if (src_cst->IsLongConstant()) { |
| 1289 | temp = temps.AcquireX(); |
| 1290 | } else if (src_cst->IsFloatConstant()) { |
| 1291 | temp = temps.AcquireS(); |
| 1292 | } else { |
| 1293 | DCHECK(src_cst->IsDoubleConstant()); |
| 1294 | temp = temps.AcquireD(); |
| 1295 | } |
| 1296 | MoveConstant(temp, src_cst); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1297 | __ Str(temp, StackOperandFrom(destination)); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1298 | } else { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1299 | DCHECK(source.IsStackSlot() || source.IsDoubleStackSlot()); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1300 | DCHECK(source.IsDoubleStackSlot() == destination.IsDoubleStackSlot()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1301 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1302 | // There is generally less pressure on FP registers. |
| 1303 | FPRegister temp = destination.IsDoubleStackSlot() ? temps.AcquireD() : temps.AcquireS(); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1304 | __ Ldr(temp, StackOperandFrom(source)); |
| 1305 | __ Str(temp, StackOperandFrom(destination)); |
| 1306 | } |
| 1307 | } |
| 1308 | } |
| 1309 | |
| 1310 | void CodeGeneratorARM64::Load(Primitive::Type type, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1311 | CPURegister dst, |
| 1312 | const MemOperand& src) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1313 | switch (type) { |
| 1314 | case Primitive::kPrimBoolean: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1315 | __ Ldrb(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1316 | break; |
| 1317 | case Primitive::kPrimByte: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1318 | __ Ldrsb(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1319 | break; |
| 1320 | case Primitive::kPrimShort: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1321 | __ Ldrsh(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1322 | break; |
| 1323 | case Primitive::kPrimChar: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1324 | __ Ldrh(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1325 | break; |
| 1326 | case Primitive::kPrimInt: |
| 1327 | case Primitive::kPrimNot: |
| 1328 | case Primitive::kPrimLong: |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1329 | case Primitive::kPrimFloat: |
| 1330 | case Primitive::kPrimDouble: |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 1331 | DCHECK_EQ(dst.Is64Bits(), Primitive::Is64BitType(type)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1332 | __ Ldr(dst, src); |
| 1333 | break; |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1334 | case Primitive::kPrimVoid: |
| 1335 | LOG(FATAL) << "Unreachable type " << type; |
| 1336 | } |
| 1337 | } |
| 1338 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1339 | void CodeGeneratorARM64::LoadAcquire(HInstruction* instruction, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1340 | CPURegister dst, |
| 1341 | const MemOperand& src) { |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1342 | MacroAssembler* masm = GetVIXLAssembler(); |
| 1343 | BlockPoolsScope block_pools(masm); |
| 1344 | UseScratchRegisterScope temps(masm); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1345 | Register temp_base = temps.AcquireX(); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1346 | Primitive::Type type = instruction->GetType(); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1347 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1348 | DCHECK(!src.IsPreIndex()); |
| 1349 | DCHECK(!src.IsPostIndex()); |
| 1350 | |
| 1351 | // TODO(vixl): Let the MacroAssembler handle MemOperand. |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 1352 | __ Add(temp_base, src.base(), OperandFromMemOperand(src)); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1353 | MemOperand base = MemOperand(temp_base); |
| 1354 | switch (type) { |
| 1355 | case Primitive::kPrimBoolean: |
| 1356 | __ Ldarb(Register(dst), base); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1357 | MaybeRecordImplicitNullCheck(instruction); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1358 | break; |
| 1359 | case Primitive::kPrimByte: |
| 1360 | __ Ldarb(Register(dst), base); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1361 | MaybeRecordImplicitNullCheck(instruction); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1362 | __ Sbfx(Register(dst), Register(dst), 0, Primitive::ComponentSize(type) * kBitsPerByte); |
| 1363 | break; |
| 1364 | case Primitive::kPrimChar: |
| 1365 | __ Ldarh(Register(dst), base); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1366 | MaybeRecordImplicitNullCheck(instruction); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1367 | break; |
| 1368 | case Primitive::kPrimShort: |
| 1369 | __ Ldarh(Register(dst), base); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1370 | MaybeRecordImplicitNullCheck(instruction); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1371 | __ Sbfx(Register(dst), Register(dst), 0, Primitive::ComponentSize(type) * kBitsPerByte); |
| 1372 | break; |
| 1373 | case Primitive::kPrimInt: |
| 1374 | case Primitive::kPrimNot: |
| 1375 | case Primitive::kPrimLong: |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 1376 | DCHECK_EQ(dst.Is64Bits(), Primitive::Is64BitType(type)); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1377 | __ Ldar(Register(dst), base); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1378 | MaybeRecordImplicitNullCheck(instruction); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1379 | break; |
| 1380 | case Primitive::kPrimFloat: |
| 1381 | case Primitive::kPrimDouble: { |
| 1382 | DCHECK(dst.IsFPRegister()); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 1383 | DCHECK_EQ(dst.Is64Bits(), Primitive::Is64BitType(type)); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1384 | |
| 1385 | Register temp = dst.Is64Bits() ? temps.AcquireX() : temps.AcquireW(); |
| 1386 | __ Ldar(temp, base); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1387 | MaybeRecordImplicitNullCheck(instruction); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1388 | __ Fmov(FPRegister(dst), temp); |
| 1389 | break; |
| 1390 | } |
| 1391 | case Primitive::kPrimVoid: |
| 1392 | LOG(FATAL) << "Unreachable type " << type; |
| 1393 | } |
| 1394 | } |
| 1395 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1396 | void CodeGeneratorARM64::Store(Primitive::Type type, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1397 | CPURegister src, |
| 1398 | const MemOperand& dst) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1399 | switch (type) { |
| 1400 | case Primitive::kPrimBoolean: |
| 1401 | case Primitive::kPrimByte: |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1402 | __ Strb(Register(src), dst); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1403 | break; |
| 1404 | case Primitive::kPrimChar: |
| 1405 | case Primitive::kPrimShort: |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1406 | __ Strh(Register(src), dst); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1407 | break; |
| 1408 | case Primitive::kPrimInt: |
| 1409 | case Primitive::kPrimNot: |
| 1410 | case Primitive::kPrimLong: |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1411 | case Primitive::kPrimFloat: |
| 1412 | case Primitive::kPrimDouble: |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 1413 | DCHECK_EQ(src.Is64Bits(), Primitive::Is64BitType(type)); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1414 | __ Str(src, dst); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1415 | break; |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1416 | case Primitive::kPrimVoid: |
| 1417 | LOG(FATAL) << "Unreachable type " << type; |
| 1418 | } |
| 1419 | } |
| 1420 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1421 | void CodeGeneratorARM64::StoreRelease(Primitive::Type type, |
| 1422 | CPURegister src, |
| 1423 | const MemOperand& dst) { |
| 1424 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 1425 | Register temp_base = temps.AcquireX(); |
| 1426 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1427 | DCHECK(!dst.IsPreIndex()); |
| 1428 | DCHECK(!dst.IsPostIndex()); |
| 1429 | |
| 1430 | // TODO(vixl): Let the MacroAssembler handle this. |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 1431 | Operand op = OperandFromMemOperand(dst); |
| 1432 | __ Add(temp_base, dst.base(), op); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1433 | MemOperand base = MemOperand(temp_base); |
| 1434 | switch (type) { |
| 1435 | case Primitive::kPrimBoolean: |
| 1436 | case Primitive::kPrimByte: |
| 1437 | __ Stlrb(Register(src), base); |
| 1438 | break; |
| 1439 | case Primitive::kPrimChar: |
| 1440 | case Primitive::kPrimShort: |
| 1441 | __ Stlrh(Register(src), base); |
| 1442 | break; |
| 1443 | case Primitive::kPrimInt: |
| 1444 | case Primitive::kPrimNot: |
| 1445 | case Primitive::kPrimLong: |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 1446 | DCHECK_EQ(src.Is64Bits(), Primitive::Is64BitType(type)); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1447 | __ Stlr(Register(src), base); |
| 1448 | break; |
| 1449 | case Primitive::kPrimFloat: |
| 1450 | case Primitive::kPrimDouble: { |
| 1451 | DCHECK(src.IsFPRegister()); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 1452 | DCHECK_EQ(src.Is64Bits(), Primitive::Is64BitType(type)); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1453 | |
| 1454 | Register temp = src.Is64Bits() ? temps.AcquireX() : temps.AcquireW(); |
| 1455 | __ Fmov(temp, FPRegister(src)); |
| 1456 | __ Stlr(temp, base); |
| 1457 | break; |
| 1458 | } |
| 1459 | case Primitive::kPrimVoid: |
| 1460 | LOG(FATAL) << "Unreachable type " << type; |
| 1461 | } |
| 1462 | } |
| 1463 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1464 | void CodeGeneratorARM64::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 1465 | HInstruction* instruction, |
| 1466 | uint32_t dex_pc, |
| 1467 | SlowPathCode* slow_path) { |
| 1468 | InvokeRuntime(GetThreadOffset<kArm64WordSize>(entrypoint).Int32Value(), |
| 1469 | instruction, |
| 1470 | dex_pc, |
| 1471 | slow_path); |
| 1472 | } |
| 1473 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1474 | void CodeGeneratorARM64::InvokeRuntime(int32_t entry_point_offset, |
| 1475 | HInstruction* instruction, |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 1476 | uint32_t dex_pc, |
| 1477 | SlowPathCode* slow_path) { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1478 | ValidateInvokeRuntime(instruction, slow_path); |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1479 | BlockPoolsScope block_pools(GetVIXLAssembler()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1480 | __ Ldr(lr, MemOperand(tr, entry_point_offset)); |
| 1481 | __ Blr(lr); |
Roland Levillain | 896e32d | 2015-05-05 18:07:10 +0100 | [diff] [blame] | 1482 | RecordPcInfo(instruction, dex_pc, slow_path); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1483 | } |
| 1484 | |
| 1485 | void InstructionCodeGeneratorARM64::GenerateClassInitializationCheck(SlowPathCodeARM64* slow_path, |
| 1486 | vixl::Register class_reg) { |
| 1487 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 1488 | Register temp = temps.AcquireW(); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1489 | size_t status_offset = mirror::Class::StatusOffset().SizeValue(); |
Serban Constantinescu | 579885a | 2015-02-22 20:51:33 +0000 | [diff] [blame] | 1490 | bool use_acquire_release = codegen_->GetInstructionSetFeatures().PreferAcquireRelease(); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1491 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1492 | // 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] | 1493 | if (use_acquire_release) { |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1494 | // TODO(vixl): Let the MacroAssembler handle MemOperand. |
| 1495 | __ Add(temp, class_reg, status_offset); |
| 1496 | __ Ldar(temp, HeapOperand(temp)); |
| 1497 | __ Cmp(temp, mirror::Class::kStatusInitialized); |
| 1498 | __ B(lt, slow_path->GetEntryLabel()); |
| 1499 | } else { |
| 1500 | __ Ldr(temp, HeapOperand(class_reg, status_offset)); |
| 1501 | __ Cmp(temp, mirror::Class::kStatusInitialized); |
| 1502 | __ B(lt, slow_path->GetEntryLabel()); |
| 1503 | __ Dmb(InnerShareable, BarrierReads); |
| 1504 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1505 | __ Bind(slow_path->GetExitLabel()); |
| 1506 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1507 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1508 | void InstructionCodeGeneratorARM64::GenerateMemoryBarrier(MemBarrierKind kind) { |
| 1509 | BarrierType type = BarrierAll; |
| 1510 | |
| 1511 | switch (kind) { |
| 1512 | case MemBarrierKind::kAnyAny: |
| 1513 | case MemBarrierKind::kAnyStore: { |
| 1514 | type = BarrierAll; |
| 1515 | break; |
| 1516 | } |
| 1517 | case MemBarrierKind::kLoadAny: { |
| 1518 | type = BarrierReads; |
| 1519 | break; |
| 1520 | } |
| 1521 | case MemBarrierKind::kStoreStore: { |
| 1522 | type = BarrierWrites; |
| 1523 | break; |
| 1524 | } |
| 1525 | default: |
| 1526 | LOG(FATAL) << "Unexpected memory barrier " << kind; |
| 1527 | } |
| 1528 | __ Dmb(InnerShareable, type); |
| 1529 | } |
| 1530 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1531 | void InstructionCodeGeneratorARM64::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 1532 | HBasicBlock* successor) { |
| 1533 | SuspendCheckSlowPathARM64* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 1534 | down_cast<SuspendCheckSlowPathARM64*>(instruction->GetSlowPath()); |
| 1535 | if (slow_path == nullptr) { |
| 1536 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathARM64(instruction, successor); |
| 1537 | instruction->SetSlowPath(slow_path); |
| 1538 | codegen_->AddSlowPath(slow_path); |
| 1539 | if (successor != nullptr) { |
| 1540 | DCHECK(successor->IsLoopHeader()); |
| 1541 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 1542 | } |
| 1543 | } else { |
| 1544 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 1545 | } |
| 1546 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1547 | UseScratchRegisterScope temps(codegen_->GetVIXLAssembler()); |
| 1548 | Register temp = temps.AcquireW(); |
| 1549 | |
| 1550 | __ Ldrh(temp, MemOperand(tr, Thread::ThreadFlagsOffset<kArm64WordSize>().SizeValue())); |
| 1551 | if (successor == nullptr) { |
| 1552 | __ Cbnz(temp, slow_path->GetEntryLabel()); |
| 1553 | __ Bind(slow_path->GetReturnLabel()); |
| 1554 | } else { |
| 1555 | __ Cbz(temp, codegen_->GetLabelOf(successor)); |
| 1556 | __ B(slow_path->GetEntryLabel()); |
| 1557 | // slow_path will return to GetLabelOf(successor). |
| 1558 | } |
| 1559 | } |
| 1560 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1561 | InstructionCodeGeneratorARM64::InstructionCodeGeneratorARM64(HGraph* graph, |
| 1562 | CodeGeneratorARM64* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1563 | : InstructionCodeGenerator(graph, codegen), |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1564 | assembler_(codegen->GetAssembler()), |
| 1565 | codegen_(codegen) {} |
| 1566 | |
| 1567 | #define FOR_EACH_UNIMPLEMENTED_INSTRUCTION(M) \ |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1568 | /* No unimplemented IR. */ |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1569 | |
| 1570 | #define UNIMPLEMENTED_INSTRUCTION_BREAK_CODE(name) name##UnimplementedInstructionBreakCode |
| 1571 | |
| 1572 | enum UnimplementedInstructionBreakCode { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1573 | // Using a base helps identify when we hit such breakpoints. |
| 1574 | UnimplementedInstructionBreakCodeBaseCode = 0x900, |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1575 | #define ENUM_UNIMPLEMENTED_INSTRUCTION(name) UNIMPLEMENTED_INSTRUCTION_BREAK_CODE(name), |
| 1576 | FOR_EACH_UNIMPLEMENTED_INSTRUCTION(ENUM_UNIMPLEMENTED_INSTRUCTION) |
| 1577 | #undef ENUM_UNIMPLEMENTED_INSTRUCTION |
| 1578 | }; |
| 1579 | |
| 1580 | #define DEFINE_UNIMPLEMENTED_INSTRUCTION_VISITORS(name) \ |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1581 | void InstructionCodeGeneratorARM64::Visit##name(H##name* instr ATTRIBUTE_UNUSED) { \ |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1582 | __ Brk(UNIMPLEMENTED_INSTRUCTION_BREAK_CODE(name)); \ |
| 1583 | } \ |
| 1584 | void LocationsBuilderARM64::Visit##name(H##name* instr) { \ |
| 1585 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr); \ |
| 1586 | locations->SetOut(Location::Any()); \ |
| 1587 | } |
| 1588 | FOR_EACH_UNIMPLEMENTED_INSTRUCTION(DEFINE_UNIMPLEMENTED_INSTRUCTION_VISITORS) |
| 1589 | #undef DEFINE_UNIMPLEMENTED_INSTRUCTION_VISITORS |
| 1590 | |
| 1591 | #undef UNIMPLEMENTED_INSTRUCTION_BREAK_CODE |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1592 | #undef FOR_EACH_UNIMPLEMENTED_INSTRUCTION |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1593 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1594 | void LocationsBuilderARM64::HandleBinaryOp(HBinaryOperation* instr) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1595 | DCHECK_EQ(instr->InputCount(), 2U); |
| 1596 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr); |
| 1597 | Primitive::Type type = instr->GetResultType(); |
| 1598 | switch (type) { |
| 1599 | case Primitive::kPrimInt: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1600 | case Primitive::kPrimLong: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1601 | locations->SetInAt(0, Location::RequiresRegister()); |
Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 1602 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instr->InputAt(1), instr)); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 1603 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1604 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1605 | |
| 1606 | case Primitive::kPrimFloat: |
| 1607 | case Primitive::kPrimDouble: |
| 1608 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1609 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1610 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1611 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1612 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1613 | default: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1614 | LOG(FATAL) << "Unexpected " << instr->DebugName() << " type " << type; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1615 | } |
| 1616 | } |
| 1617 | |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1618 | void LocationsBuilderARM64::HandleFieldGet(HInstruction* instruction) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1619 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 1620 | |
| 1621 | bool object_field_get_with_read_barrier = |
| 1622 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1623 | LocationSummary* locations = |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1624 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 1625 | object_field_get_with_read_barrier ? |
| 1626 | LocationSummary::kCallOnSlowPath : |
| 1627 | LocationSummary::kNoCall); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1628 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1629 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 1630 | locations->SetOut(Location::RequiresFpuRegister()); |
| 1631 | } else { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1632 | // The output overlaps for an object field get when read barriers |
| 1633 | // are enabled: we do not want the load to overwrite the object's |
| 1634 | // location, as we need it to emit the read barrier. |
| 1635 | locations->SetOut( |
| 1636 | Location::RequiresRegister(), |
| 1637 | object_field_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1638 | } |
| 1639 | } |
| 1640 | |
| 1641 | void InstructionCodeGeneratorARM64::HandleFieldGet(HInstruction* instruction, |
| 1642 | const FieldInfo& field_info) { |
| 1643 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1644 | Primitive::Type field_type = field_info.GetFieldType(); |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1645 | BlockPoolsScope block_pools(GetVIXLAssembler()); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1646 | |
| 1647 | MemOperand field = HeapOperand(InputRegisterAt(instruction, 0), field_info.GetFieldOffset()); |
| 1648 | bool use_acquire_release = codegen_->GetInstructionSetFeatures().PreferAcquireRelease(); |
| 1649 | |
| 1650 | if (field_info.IsVolatile()) { |
| 1651 | if (use_acquire_release) { |
| 1652 | // NB: LoadAcquire will record the pc info if needed. |
| 1653 | codegen_->LoadAcquire(instruction, OutputCPURegister(instruction), field); |
| 1654 | } else { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1655 | codegen_->Load(field_type, OutputCPURegister(instruction), field); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1656 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 1657 | // For IRIW sequential consistency kLoadAny is not sufficient. |
| 1658 | GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
| 1659 | } |
| 1660 | } else { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1661 | codegen_->Load(field_type, OutputCPURegister(instruction), field); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1662 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 1663 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1664 | |
| 1665 | if (field_type == Primitive::kPrimNot) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1666 | LocationSummary* locations = instruction->GetLocations(); |
| 1667 | Location base = locations->InAt(0); |
| 1668 | Location out = locations->Out(); |
| 1669 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 1670 | codegen_->MaybeGenerateReadBarrier(instruction, out, out, base, offset); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1671 | } |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1672 | } |
| 1673 | |
| 1674 | void LocationsBuilderARM64::HandleFieldSet(HInstruction* instruction) { |
| 1675 | LocationSummary* locations = |
| 1676 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 1677 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1678 | if (Primitive::IsFloatingPointType(instruction->InputAt(1)->GetType())) { |
| 1679 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1680 | } else { |
| 1681 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1682 | } |
| 1683 | } |
| 1684 | |
| 1685 | void InstructionCodeGeneratorARM64::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1686 | const FieldInfo& field_info, |
| 1687 | bool value_can_be_null) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1688 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1689 | BlockPoolsScope block_pools(GetVIXLAssembler()); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1690 | |
| 1691 | Register obj = InputRegisterAt(instruction, 0); |
| 1692 | CPURegister value = InputCPURegisterAt(instruction, 1); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1693 | CPURegister source = value; |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1694 | Offset offset = field_info.GetFieldOffset(); |
| 1695 | Primitive::Type field_type = field_info.GetFieldType(); |
| 1696 | bool use_acquire_release = codegen_->GetInstructionSetFeatures().PreferAcquireRelease(); |
| 1697 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1698 | { |
| 1699 | // We use a block to end the scratch scope before the write barrier, thus |
| 1700 | // freeing the temporary registers so they can be used in `MarkGCCard`. |
| 1701 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 1702 | |
| 1703 | if (kPoisonHeapReferences && field_type == Primitive::kPrimNot) { |
| 1704 | DCHECK(value.IsW()); |
| 1705 | Register temp = temps.AcquireW(); |
| 1706 | __ Mov(temp, value.W()); |
| 1707 | GetAssembler()->PoisonHeapReference(temp.W()); |
| 1708 | source = temp; |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1709 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1710 | |
| 1711 | if (field_info.IsVolatile()) { |
| 1712 | if (use_acquire_release) { |
| 1713 | codegen_->StoreRelease(field_type, source, HeapOperand(obj, offset)); |
| 1714 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 1715 | } else { |
| 1716 | GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
| 1717 | codegen_->Store(field_type, source, HeapOperand(obj, offset)); |
| 1718 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 1719 | GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
| 1720 | } |
| 1721 | } else { |
| 1722 | codegen_->Store(field_type, source, HeapOperand(obj, offset)); |
| 1723 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 1724 | } |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1725 | } |
| 1726 | |
| 1727 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1728 | codegen_->MarkGCCard(obj, Register(value), value_can_be_null); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1729 | } |
| 1730 | } |
| 1731 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1732 | void InstructionCodeGeneratorARM64::HandleBinaryOp(HBinaryOperation* instr) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1733 | Primitive::Type type = instr->GetType(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1734 | |
| 1735 | switch (type) { |
| 1736 | case Primitive::kPrimInt: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1737 | case Primitive::kPrimLong: { |
| 1738 | Register dst = OutputRegister(instr); |
| 1739 | Register lhs = InputRegisterAt(instr, 0); |
| 1740 | Operand rhs = InputOperandAt(instr, 1); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1741 | if (instr->IsAdd()) { |
| 1742 | __ Add(dst, lhs, rhs); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1743 | } else if (instr->IsAnd()) { |
| 1744 | __ And(dst, lhs, rhs); |
| 1745 | } else if (instr->IsOr()) { |
| 1746 | __ Orr(dst, lhs, rhs); |
| 1747 | } else if (instr->IsSub()) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1748 | __ Sub(dst, lhs, rhs); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 1749 | } else if (instr->IsRor()) { |
| 1750 | if (rhs.IsImmediate()) { |
| 1751 | uint32_t shift = rhs.immediate() & (lhs.SizeInBits() - 1); |
| 1752 | __ Ror(dst, lhs, shift); |
| 1753 | } else { |
| 1754 | // Ensure shift distance is in the same size register as the result. If |
| 1755 | // we are rotating a long and the shift comes in a w register originally, |
| 1756 | // we don't need to sxtw for use as an x since the shift distances are |
| 1757 | // all & reg_bits - 1. |
| 1758 | __ Ror(dst, lhs, RegisterFrom(instr->GetLocations()->InAt(1), type)); |
| 1759 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1760 | } else { |
| 1761 | DCHECK(instr->IsXor()); |
| 1762 | __ Eor(dst, lhs, rhs); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1763 | } |
| 1764 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1765 | } |
| 1766 | case Primitive::kPrimFloat: |
| 1767 | case Primitive::kPrimDouble: { |
| 1768 | FPRegister dst = OutputFPRegister(instr); |
| 1769 | FPRegister lhs = InputFPRegisterAt(instr, 0); |
| 1770 | FPRegister rhs = InputFPRegisterAt(instr, 1); |
| 1771 | if (instr->IsAdd()) { |
| 1772 | __ Fadd(dst, lhs, rhs); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1773 | } else if (instr->IsSub()) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1774 | __ Fsub(dst, lhs, rhs); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1775 | } else { |
| 1776 | LOG(FATAL) << "Unexpected floating-point binary operation"; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1777 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1778 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1779 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1780 | default: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1781 | LOG(FATAL) << "Unexpected binary operation type " << type; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1782 | } |
| 1783 | } |
| 1784 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1785 | void LocationsBuilderARM64::HandleShift(HBinaryOperation* instr) { |
| 1786 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr()); |
| 1787 | |
| 1788 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr); |
| 1789 | Primitive::Type type = instr->GetResultType(); |
| 1790 | switch (type) { |
| 1791 | case Primitive::kPrimInt: |
| 1792 | case Primitive::kPrimLong: { |
| 1793 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1794 | locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1))); |
| 1795 | locations->SetOut(Location::RequiresRegister()); |
| 1796 | break; |
| 1797 | } |
| 1798 | default: |
| 1799 | LOG(FATAL) << "Unexpected shift type " << type; |
| 1800 | } |
| 1801 | } |
| 1802 | |
| 1803 | void InstructionCodeGeneratorARM64::HandleShift(HBinaryOperation* instr) { |
| 1804 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr()); |
| 1805 | |
| 1806 | Primitive::Type type = instr->GetType(); |
| 1807 | switch (type) { |
| 1808 | case Primitive::kPrimInt: |
| 1809 | case Primitive::kPrimLong: { |
| 1810 | Register dst = OutputRegister(instr); |
| 1811 | Register lhs = InputRegisterAt(instr, 0); |
| 1812 | Operand rhs = InputOperandAt(instr, 1); |
| 1813 | if (rhs.IsImmediate()) { |
| 1814 | uint32_t shift_value = (type == Primitive::kPrimInt) |
| 1815 | ? static_cast<uint32_t>(rhs.immediate() & kMaxIntShiftValue) |
| 1816 | : static_cast<uint32_t>(rhs.immediate() & kMaxLongShiftValue); |
| 1817 | if (instr->IsShl()) { |
| 1818 | __ Lsl(dst, lhs, shift_value); |
| 1819 | } else if (instr->IsShr()) { |
| 1820 | __ Asr(dst, lhs, shift_value); |
| 1821 | } else { |
| 1822 | __ Lsr(dst, lhs, shift_value); |
| 1823 | } |
| 1824 | } else { |
| 1825 | Register rhs_reg = dst.IsX() ? rhs.reg().X() : rhs.reg().W(); |
| 1826 | |
| 1827 | if (instr->IsShl()) { |
| 1828 | __ Lsl(dst, lhs, rhs_reg); |
| 1829 | } else if (instr->IsShr()) { |
| 1830 | __ Asr(dst, lhs, rhs_reg); |
| 1831 | } else { |
| 1832 | __ Lsr(dst, lhs, rhs_reg); |
| 1833 | } |
| 1834 | } |
| 1835 | break; |
| 1836 | } |
| 1837 | default: |
| 1838 | LOG(FATAL) << "Unexpected shift operation type " << type; |
| 1839 | } |
| 1840 | } |
| 1841 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1842 | void LocationsBuilderARM64::VisitAdd(HAdd* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1843 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1844 | } |
| 1845 | |
| 1846 | void InstructionCodeGeneratorARM64::VisitAdd(HAdd* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1847 | HandleBinaryOp(instruction); |
| 1848 | } |
| 1849 | |
| 1850 | void LocationsBuilderARM64::VisitAnd(HAnd* instruction) { |
| 1851 | HandleBinaryOp(instruction); |
| 1852 | } |
| 1853 | |
| 1854 | void InstructionCodeGeneratorARM64::VisitAnd(HAnd* instruction) { |
| 1855 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1856 | } |
| 1857 | |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 1858 | void LocationsBuilderARM64::VisitArm64DataProcWithShifterOp( |
| 1859 | HArm64DataProcWithShifterOp* instruction) { |
| 1860 | DCHECK(instruction->GetType() == Primitive::kPrimInt || |
| 1861 | instruction->GetType() == Primitive::kPrimLong); |
| 1862 | LocationSummary* locations = |
| 1863 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 1864 | if (instruction->GetInstrKind() == HInstruction::kNeg) { |
| 1865 | locations->SetInAt(0, Location::ConstantLocation(instruction->InputAt(0)->AsConstant())); |
| 1866 | } else { |
| 1867 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1868 | } |
| 1869 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1870 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1871 | } |
| 1872 | |
| 1873 | void InstructionCodeGeneratorARM64::VisitArm64DataProcWithShifterOp( |
| 1874 | HArm64DataProcWithShifterOp* instruction) { |
| 1875 | Primitive::Type type = instruction->GetType(); |
| 1876 | HInstruction::InstructionKind kind = instruction->GetInstrKind(); |
| 1877 | DCHECK(type == Primitive::kPrimInt || type == Primitive::kPrimLong); |
| 1878 | Register out = OutputRegister(instruction); |
| 1879 | Register left; |
| 1880 | if (kind != HInstruction::kNeg) { |
| 1881 | left = InputRegisterAt(instruction, 0); |
| 1882 | } |
| 1883 | // If this `HArm64DataProcWithShifterOp` was created by merging a type conversion as the |
| 1884 | // shifter operand operation, the IR generating `right_reg` (input to the type |
| 1885 | // conversion) can have a different type from the current instruction's type, |
| 1886 | // so we manually indicate the type. |
| 1887 | Register right_reg = RegisterFrom(instruction->GetLocations()->InAt(1), type); |
| 1888 | int64_t shift_amount = (type == Primitive::kPrimInt) |
| 1889 | ? static_cast<uint32_t>(instruction->GetShiftAmount() & kMaxIntShiftValue) |
| 1890 | : static_cast<uint32_t>(instruction->GetShiftAmount() & kMaxLongShiftValue); |
| 1891 | |
| 1892 | Operand right_operand(0); |
| 1893 | |
| 1894 | HArm64DataProcWithShifterOp::OpKind op_kind = instruction->GetOpKind(); |
| 1895 | if (HArm64DataProcWithShifterOp::IsExtensionOp(op_kind)) { |
| 1896 | right_operand = Operand(right_reg, helpers::ExtendFromOpKind(op_kind)); |
| 1897 | } else { |
| 1898 | right_operand = Operand(right_reg, helpers::ShiftFromOpKind(op_kind), shift_amount); |
| 1899 | } |
| 1900 | |
| 1901 | // Logical binary operations do not support extension operations in the |
| 1902 | // operand. Note that VIXL would still manage if it was passed by generating |
| 1903 | // the extension as a separate instruction. |
| 1904 | // `HNeg` also does not support extension. See comments in `ShifterOperandSupportsExtension()`. |
| 1905 | DCHECK(!right_operand.IsExtendedRegister() || |
| 1906 | (kind != HInstruction::kAnd && kind != HInstruction::kOr && kind != HInstruction::kXor && |
| 1907 | kind != HInstruction::kNeg)); |
| 1908 | switch (kind) { |
| 1909 | case HInstruction::kAdd: |
| 1910 | __ Add(out, left, right_operand); |
| 1911 | break; |
| 1912 | case HInstruction::kAnd: |
| 1913 | __ And(out, left, right_operand); |
| 1914 | break; |
| 1915 | case HInstruction::kNeg: |
| 1916 | DCHECK(instruction->InputAt(0)->AsConstant()->IsZero()); |
| 1917 | __ Neg(out, right_operand); |
| 1918 | break; |
| 1919 | case HInstruction::kOr: |
| 1920 | __ Orr(out, left, right_operand); |
| 1921 | break; |
| 1922 | case HInstruction::kSub: |
| 1923 | __ Sub(out, left, right_operand); |
| 1924 | break; |
| 1925 | case HInstruction::kXor: |
| 1926 | __ Eor(out, left, right_operand); |
| 1927 | break; |
| 1928 | default: |
| 1929 | LOG(FATAL) << "Unexpected operation kind: " << kind; |
| 1930 | UNREACHABLE(); |
| 1931 | } |
| 1932 | } |
| 1933 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1934 | void LocationsBuilderARM64::VisitArm64IntermediateAddress(HArm64IntermediateAddress* instruction) { |
Roland Levillain | cd3d0fb | 2016-01-15 19:26:48 +0000 | [diff] [blame] | 1935 | // The read barrier instrumentation does not support the |
| 1936 | // HArm64IntermediateAddress instruction yet. |
| 1937 | DCHECK(!kEmitCompilerReadBarrier); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1938 | LocationSummary* locations = |
| 1939 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 1940 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1941 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->GetOffset(), instruction)); |
| 1942 | locations->SetOut(Location::RequiresRegister()); |
| 1943 | } |
| 1944 | |
| 1945 | void InstructionCodeGeneratorARM64::VisitArm64IntermediateAddress( |
| 1946 | HArm64IntermediateAddress* instruction) { |
Roland Levillain | cd3d0fb | 2016-01-15 19:26:48 +0000 | [diff] [blame] | 1947 | // The read barrier instrumentation does not support the |
| 1948 | // HArm64IntermediateAddress instruction yet. |
| 1949 | DCHECK(!kEmitCompilerReadBarrier); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1950 | __ Add(OutputRegister(instruction), |
| 1951 | InputRegisterAt(instruction, 0), |
| 1952 | Operand(InputOperandAt(instruction, 1))); |
| 1953 | } |
| 1954 | |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 1955 | void LocationsBuilderARM64::VisitArm64MultiplyAccumulate(HArm64MultiplyAccumulate* instr) { |
| 1956 | LocationSummary* locations = |
| 1957 | new (GetGraph()->GetArena()) LocationSummary(instr, LocationSummary::kNoCall); |
| 1958 | locations->SetInAt(HArm64MultiplyAccumulate::kInputAccumulatorIndex, |
| 1959 | Location::RequiresRegister()); |
| 1960 | locations->SetInAt(HArm64MultiplyAccumulate::kInputMulLeftIndex, Location::RequiresRegister()); |
| 1961 | locations->SetInAt(HArm64MultiplyAccumulate::kInputMulRightIndex, Location::RequiresRegister()); |
| 1962 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1963 | } |
| 1964 | |
| 1965 | void InstructionCodeGeneratorARM64::VisitArm64MultiplyAccumulate(HArm64MultiplyAccumulate* instr) { |
| 1966 | Register res = OutputRegister(instr); |
| 1967 | Register accumulator = InputRegisterAt(instr, HArm64MultiplyAccumulate::kInputAccumulatorIndex); |
| 1968 | Register mul_left = InputRegisterAt(instr, HArm64MultiplyAccumulate::kInputMulLeftIndex); |
| 1969 | Register mul_right = InputRegisterAt(instr, HArm64MultiplyAccumulate::kInputMulRightIndex); |
| 1970 | |
| 1971 | // Avoid emitting code that could trigger Cortex A53's erratum 835769. |
| 1972 | // This fixup should be carried out for all multiply-accumulate instructions: |
| 1973 | // madd, msub, smaddl, smsubl, umaddl and umsubl. |
| 1974 | if (instr->GetType() == Primitive::kPrimLong && |
| 1975 | codegen_->GetInstructionSetFeatures().NeedFixCortexA53_835769()) { |
| 1976 | MacroAssembler* masm = down_cast<CodeGeneratorARM64*>(codegen_)->GetVIXLAssembler(); |
| 1977 | vixl::Instruction* prev = masm->GetCursorAddress<vixl::Instruction*>() - vixl::kInstructionSize; |
| 1978 | if (prev->IsLoadOrStore()) { |
| 1979 | // Make sure we emit only exactly one nop. |
| 1980 | vixl::CodeBufferCheckScope scope(masm, |
| 1981 | vixl::kInstructionSize, |
| 1982 | vixl::CodeBufferCheckScope::kCheck, |
| 1983 | vixl::CodeBufferCheckScope::kExactSize); |
| 1984 | __ nop(); |
| 1985 | } |
| 1986 | } |
| 1987 | |
| 1988 | if (instr->GetOpKind() == HInstruction::kAdd) { |
| 1989 | __ Madd(res, mul_left, mul_right, accumulator); |
| 1990 | } else { |
| 1991 | DCHECK(instr->GetOpKind() == HInstruction::kSub); |
| 1992 | __ Msub(res, mul_left, mul_right, accumulator); |
| 1993 | } |
| 1994 | } |
| 1995 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1996 | void LocationsBuilderARM64::VisitArrayGet(HArrayGet* instruction) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1997 | bool object_array_get_with_read_barrier = |
| 1998 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1999 | LocationSummary* locations = |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2000 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 2001 | object_array_get_with_read_barrier ? |
| 2002 | LocationSummary::kCallOnSlowPath : |
| 2003 | LocationSummary::kNoCall); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2004 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2005 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 2006 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 2007 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 2008 | } else { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2009 | // The output overlaps in the case of an object array get with |
| 2010 | // read barriers enabled: we do not want the move to overwrite the |
| 2011 | // array's location, as we need it to emit the read barrier. |
| 2012 | locations->SetOut( |
| 2013 | Location::RequiresRegister(), |
| 2014 | object_array_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 2015 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2016 | } |
| 2017 | |
| 2018 | void InstructionCodeGeneratorARM64::VisitArrayGet(HArrayGet* instruction) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2019 | Primitive::Type type = instruction->GetType(); |
| 2020 | Register obj = InputRegisterAt(instruction, 0); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2021 | LocationSummary* locations = instruction->GetLocations(); |
| 2022 | Location index = locations->InAt(1); |
| 2023 | uint32_t offset = mirror::Array::DataOffset(Primitive::ComponentSize(type)).Uint32Value(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2024 | MemOperand source = HeapOperand(obj); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2025 | CPURegister dest = OutputCPURegister(instruction); |
| 2026 | |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 2027 | MacroAssembler* masm = GetVIXLAssembler(); |
| 2028 | UseScratchRegisterScope temps(masm); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2029 | // Block pools between `Load` and `MaybeRecordImplicitNullCheck`. |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 2030 | BlockPoolsScope block_pools(masm); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2031 | |
| 2032 | if (index.IsConstant()) { |
| 2033 | offset += Int64ConstantFrom(index) << Primitive::ComponentSizeShift(type); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2034 | source = HeapOperand(obj, offset); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2035 | } else { |
| 2036 | Register temp = temps.AcquireSameSizeAs(obj); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2037 | if (instruction->GetArray()->IsArm64IntermediateAddress()) { |
Roland Levillain | cd3d0fb | 2016-01-15 19:26:48 +0000 | [diff] [blame] | 2038 | // The read barrier instrumentation does not support the |
| 2039 | // HArm64IntermediateAddress instruction yet. |
| 2040 | DCHECK(!kEmitCompilerReadBarrier); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2041 | // We do not need to compute the intermediate address from the array: the |
| 2042 | // input instruction has done it already. See the comment in |
| 2043 | // `InstructionSimplifierArm64::TryExtractArrayAccessAddress()`. |
| 2044 | if (kIsDebugBuild) { |
| 2045 | HArm64IntermediateAddress* tmp = instruction->GetArray()->AsArm64IntermediateAddress(); |
| 2046 | DCHECK(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64() == offset); |
| 2047 | } |
| 2048 | temp = obj; |
| 2049 | } else { |
| 2050 | __ Add(temp, obj, offset); |
| 2051 | } |
Alexandre Rames | 82000b0 | 2015-07-07 11:34:16 +0100 | [diff] [blame] | 2052 | source = HeapOperand(temp, XRegisterFrom(index), LSL, Primitive::ComponentSizeShift(type)); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2053 | } |
| 2054 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2055 | codegen_->Load(type, dest, source); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 2056 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2057 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2058 | if (type == Primitive::kPrimNot) { |
| 2059 | static_assert( |
| 2060 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 2061 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 2062 | Location obj_loc = locations->InAt(0); |
| 2063 | Location out = locations->Out(); |
| 2064 | if (index.IsConstant()) { |
| 2065 | codegen_->MaybeGenerateReadBarrier(instruction, out, out, obj_loc, offset); |
| 2066 | } else { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2067 | codegen_->MaybeGenerateReadBarrier(instruction, out, out, obj_loc, offset, index); |
| 2068 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2069 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2070 | } |
| 2071 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2072 | void LocationsBuilderARM64::VisitArrayLength(HArrayLength* instruction) { |
| 2073 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 2074 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 2075 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2076 | } |
| 2077 | |
| 2078 | void InstructionCodeGeneratorARM64::VisitArrayLength(HArrayLength* instruction) { |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 2079 | BlockPoolsScope block_pools(GetVIXLAssembler()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2080 | __ Ldr(OutputRegister(instruction), |
| 2081 | HeapOperand(InputRegisterAt(instruction, 0), mirror::Array::LengthOffset())); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 2082 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2083 | } |
| 2084 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2085 | void LocationsBuilderARM64::VisitArraySet(HArraySet* instruction) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2086 | Primitive::Type value_type = instruction->GetComponentType(); |
| 2087 | |
| 2088 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
| 2089 | bool object_array_set_with_read_barrier = |
| 2090 | kEmitCompilerReadBarrier && (value_type == Primitive::kPrimNot); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2091 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 2092 | instruction, |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2093 | (may_need_runtime_call_for_type_check || object_array_set_with_read_barrier) ? |
| 2094 | LocationSummary::kCallOnSlowPath : |
| 2095 | LocationSummary::kNoCall); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2096 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2097 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2098 | if (Primitive::IsFloatingPointType(value_type)) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2099 | locations->SetInAt(2, Location::RequiresFpuRegister()); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2100 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2101 | locations->SetInAt(2, Location::RequiresRegister()); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2102 | } |
| 2103 | } |
| 2104 | |
| 2105 | void InstructionCodeGeneratorARM64::VisitArraySet(HArraySet* instruction) { |
| 2106 | Primitive::Type value_type = instruction->GetComponentType(); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2107 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2108 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2109 | bool needs_write_barrier = |
| 2110 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2111 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2112 | Register array = InputRegisterAt(instruction, 0); |
| 2113 | CPURegister value = InputCPURegisterAt(instruction, 2); |
| 2114 | CPURegister source = value; |
| 2115 | Location index = locations->InAt(1); |
| 2116 | size_t offset = mirror::Array::DataOffset(Primitive::ComponentSize(value_type)).Uint32Value(); |
| 2117 | MemOperand destination = HeapOperand(array); |
| 2118 | MacroAssembler* masm = GetVIXLAssembler(); |
| 2119 | BlockPoolsScope block_pools(masm); |
| 2120 | |
| 2121 | if (!needs_write_barrier) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2122 | DCHECK(!may_need_runtime_call_for_type_check); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2123 | if (index.IsConstant()) { |
| 2124 | offset += Int64ConstantFrom(index) << Primitive::ComponentSizeShift(value_type); |
| 2125 | destination = HeapOperand(array, offset); |
| 2126 | } else { |
| 2127 | UseScratchRegisterScope temps(masm); |
| 2128 | Register temp = temps.AcquireSameSizeAs(array); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2129 | if (instruction->GetArray()->IsArm64IntermediateAddress()) { |
Roland Levillain | cd3d0fb | 2016-01-15 19:26:48 +0000 | [diff] [blame] | 2130 | // The read barrier instrumentation does not support the |
| 2131 | // HArm64IntermediateAddress instruction yet. |
| 2132 | DCHECK(!kEmitCompilerReadBarrier); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2133 | // We do not need to compute the intermediate address from the array: the |
| 2134 | // input instruction has done it already. See the comment in |
| 2135 | // `InstructionSimplifierArm64::TryExtractArrayAccessAddress()`. |
| 2136 | if (kIsDebugBuild) { |
| 2137 | HArm64IntermediateAddress* tmp = instruction->GetArray()->AsArm64IntermediateAddress(); |
| 2138 | DCHECK(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64() == offset); |
| 2139 | } |
| 2140 | temp = array; |
| 2141 | } else { |
| 2142 | __ Add(temp, array, offset); |
| 2143 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2144 | destination = HeapOperand(temp, |
| 2145 | XRegisterFrom(index), |
| 2146 | LSL, |
| 2147 | Primitive::ComponentSizeShift(value_type)); |
| 2148 | } |
| 2149 | codegen_->Store(value_type, value, destination); |
| 2150 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2151 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2152 | DCHECK(needs_write_barrier); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2153 | DCHECK(!instruction->GetArray()->IsArm64IntermediateAddress()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2154 | vixl::Label done; |
| 2155 | SlowPathCodeARM64* slow_path = nullptr; |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2156 | { |
| 2157 | // We use a block to end the scratch scope before the write barrier, thus |
| 2158 | // freeing the temporary registers so they can be used in `MarkGCCard`. |
| 2159 | UseScratchRegisterScope temps(masm); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2160 | Register temp = temps.AcquireSameSizeAs(array); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2161 | if (index.IsConstant()) { |
| 2162 | offset += Int64ConstantFrom(index) << Primitive::ComponentSizeShift(value_type); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2163 | destination = HeapOperand(array, offset); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2164 | } else { |
Alexandre Rames | 82000b0 | 2015-07-07 11:34:16 +0100 | [diff] [blame] | 2165 | destination = HeapOperand(temp, |
| 2166 | XRegisterFrom(index), |
| 2167 | LSL, |
| 2168 | Primitive::ComponentSizeShift(value_type)); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2169 | } |
| 2170 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2171 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2172 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 2173 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 2174 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2175 | if (may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2176 | slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathARM64(instruction); |
| 2177 | codegen_->AddSlowPath(slow_path); |
| 2178 | if (instruction->GetValueCanBeNull()) { |
| 2179 | vixl::Label non_zero; |
| 2180 | __ Cbnz(Register(value), &non_zero); |
| 2181 | if (!index.IsConstant()) { |
| 2182 | __ Add(temp, array, offset); |
| 2183 | } |
| 2184 | __ Str(wzr, destination); |
| 2185 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2186 | __ B(&done); |
| 2187 | __ Bind(&non_zero); |
| 2188 | } |
| 2189 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2190 | if (kEmitCompilerReadBarrier) { |
| 2191 | // When read barriers are enabled, the type checking |
| 2192 | // instrumentation requires two read barriers: |
| 2193 | // |
| 2194 | // __ Mov(temp2, temp); |
| 2195 | // // /* HeapReference<Class> */ temp = temp->component_type_ |
| 2196 | // __ Ldr(temp, HeapOperand(temp, component_offset)); |
| 2197 | // codegen_->GenerateReadBarrier( |
| 2198 | // instruction, temp_loc, temp_loc, temp2_loc, component_offset); |
| 2199 | // |
| 2200 | // // /* HeapReference<Class> */ temp2 = value->klass_ |
| 2201 | // __ Ldr(temp2, HeapOperand(Register(value), class_offset)); |
| 2202 | // codegen_->GenerateReadBarrier( |
| 2203 | // instruction, temp2_loc, temp2_loc, value_loc, class_offset, temp_loc); |
| 2204 | // |
| 2205 | // __ Cmp(temp, temp2); |
| 2206 | // |
| 2207 | // However, the second read barrier may trash `temp`, as it |
| 2208 | // is a temporary register, and as such would not be saved |
| 2209 | // along with live registers before calling the runtime (nor |
| 2210 | // restored afterwards). So in this case, we bail out and |
| 2211 | // delegate the work to the array set slow path. |
| 2212 | // |
| 2213 | // TODO: Extend the register allocator to support a new |
| 2214 | // "(locally) live temp" location so as to avoid always |
| 2215 | // going into the slow path when read barriers are enabled. |
| 2216 | __ B(slow_path->GetEntryLabel()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2217 | } else { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2218 | Register temp2 = temps.AcquireSameSizeAs(array); |
| 2219 | // /* HeapReference<Class> */ temp = array->klass_ |
| 2220 | __ Ldr(temp, HeapOperand(array, class_offset)); |
| 2221 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2222 | GetAssembler()->MaybeUnpoisonHeapReference(temp); |
| 2223 | |
| 2224 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| 2225 | __ Ldr(temp, HeapOperand(temp, component_offset)); |
| 2226 | // /* HeapReference<Class> */ temp2 = value->klass_ |
| 2227 | __ Ldr(temp2, HeapOperand(Register(value), class_offset)); |
| 2228 | // If heap poisoning is enabled, no need to unpoison `temp` |
| 2229 | // nor `temp2`, as we are comparing two poisoned references. |
| 2230 | __ Cmp(temp, temp2); |
| 2231 | |
| 2232 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 2233 | vixl::Label do_put; |
| 2234 | __ B(eq, &do_put); |
| 2235 | // If heap poisoning is enabled, the `temp` reference has |
| 2236 | // not been unpoisoned yet; unpoison it now. |
| 2237 | GetAssembler()->MaybeUnpoisonHeapReference(temp); |
| 2238 | |
| 2239 | // /* HeapReference<Class> */ temp = temp->super_class_ |
| 2240 | __ Ldr(temp, HeapOperand(temp, super_offset)); |
| 2241 | // If heap poisoning is enabled, no need to unpoison |
| 2242 | // `temp`, as we are comparing against null below. |
| 2243 | __ Cbnz(temp, slow_path->GetEntryLabel()); |
| 2244 | __ Bind(&do_put); |
| 2245 | } else { |
| 2246 | __ B(ne, slow_path->GetEntryLabel()); |
| 2247 | } |
| 2248 | temps.Release(temp2); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2249 | } |
| 2250 | } |
| 2251 | |
| 2252 | if (kPoisonHeapReferences) { |
Nicolas Geoffray | a8a0fe2 | 2015-10-01 15:50:27 +0100 | [diff] [blame] | 2253 | Register temp2 = temps.AcquireSameSizeAs(array); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2254 | DCHECK(value.IsW()); |
Nicolas Geoffray | a8a0fe2 | 2015-10-01 15:50:27 +0100 | [diff] [blame] | 2255 | __ Mov(temp2, value.W()); |
| 2256 | GetAssembler()->PoisonHeapReference(temp2); |
| 2257 | source = temp2; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2258 | } |
| 2259 | |
| 2260 | if (!index.IsConstant()) { |
| 2261 | __ Add(temp, array, offset); |
| 2262 | } |
Nicolas Geoffray | 61b1dbe | 2015-10-01 10:27:52 +0100 | [diff] [blame] | 2263 | __ Str(source, destination); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2264 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2265 | if (!may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2266 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2267 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2268 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2269 | |
| 2270 | codegen_->MarkGCCard(array, value.W(), instruction->GetValueCanBeNull()); |
| 2271 | |
| 2272 | if (done.IsLinked()) { |
| 2273 | __ Bind(&done); |
| 2274 | } |
| 2275 | |
| 2276 | if (slow_path != nullptr) { |
| 2277 | __ Bind(slow_path->GetExitLabel()); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2278 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2279 | } |
| 2280 | } |
| 2281 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2282 | void LocationsBuilderARM64::VisitBoundsCheck(HBoundsCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2283 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 2284 | ? LocationSummary::kCallOnSlowPath |
| 2285 | : LocationSummary::kNoCall; |
| 2286 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2287 | locations->SetInAt(0, Location::RequiresRegister()); |
Serban Constantinescu | 760d8ef | 2015-03-28 18:09:56 +0000 | [diff] [blame] | 2288 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->InputAt(1), instruction)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2289 | if (instruction->HasUses()) { |
| 2290 | locations->SetOut(Location::SameAsFirstInput()); |
| 2291 | } |
| 2292 | } |
| 2293 | |
| 2294 | void InstructionCodeGeneratorARM64::VisitBoundsCheck(HBoundsCheck* instruction) { |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 2295 | BoundsCheckSlowPathARM64* slow_path = |
| 2296 | new (GetGraph()->GetArena()) BoundsCheckSlowPathARM64(instruction); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2297 | codegen_->AddSlowPath(slow_path); |
| 2298 | |
| 2299 | __ Cmp(InputRegisterAt(instruction, 0), InputOperandAt(instruction, 1)); |
| 2300 | __ B(slow_path->GetEntryLabel(), hs); |
| 2301 | } |
| 2302 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2303 | void LocationsBuilderARM64::VisitClinitCheck(HClinitCheck* check) { |
| 2304 | LocationSummary* locations = |
| 2305 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 2306 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2307 | if (check->HasUses()) { |
| 2308 | locations->SetOut(Location::SameAsFirstInput()); |
| 2309 | } |
| 2310 | } |
| 2311 | |
| 2312 | void InstructionCodeGeneratorARM64::VisitClinitCheck(HClinitCheck* check) { |
| 2313 | // We assume the class is not null. |
| 2314 | SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM64( |
| 2315 | check->GetLoadClass(), check, check->GetDexPc(), true); |
| 2316 | codegen_->AddSlowPath(slow_path); |
| 2317 | GenerateClassInitializationCheck(slow_path, InputRegisterAt(check, 0)); |
| 2318 | } |
| 2319 | |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2320 | static bool IsFloatingPointZeroConstant(HInstruction* instruction) { |
| 2321 | return (instruction->IsFloatConstant() && (instruction->AsFloatConstant()->GetValue() == 0.0f)) |
| 2322 | || (instruction->IsDoubleConstant() && (instruction->AsDoubleConstant()->GetValue() == 0.0)); |
| 2323 | } |
| 2324 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2325 | void LocationsBuilderARM64::VisitCompare(HCompare* compare) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2326 | LocationSummary* locations = |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2327 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
| 2328 | Primitive::Type in_type = compare->InputAt(0)->GetType(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2329 | switch (in_type) { |
| 2330 | case Primitive::kPrimLong: { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2331 | locations->SetInAt(0, Location::RequiresRegister()); |
Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 2332 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(compare->InputAt(1), compare)); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2333 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2334 | break; |
| 2335 | } |
| 2336 | case Primitive::kPrimFloat: |
| 2337 | case Primitive::kPrimDouble: { |
| 2338 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2339 | locations->SetInAt(1, |
| 2340 | IsFloatingPointZeroConstant(compare->InputAt(1)) |
| 2341 | ? Location::ConstantLocation(compare->InputAt(1)->AsConstant()) |
| 2342 | : Location::RequiresFpuRegister()); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2343 | locations->SetOut(Location::RequiresRegister()); |
| 2344 | break; |
| 2345 | } |
| 2346 | default: |
| 2347 | LOG(FATAL) << "Unexpected type for compare operation " << in_type; |
| 2348 | } |
| 2349 | } |
| 2350 | |
| 2351 | void InstructionCodeGeneratorARM64::VisitCompare(HCompare* compare) { |
| 2352 | Primitive::Type in_type = compare->InputAt(0)->GetType(); |
| 2353 | |
| 2354 | // 0 if: left == right |
| 2355 | // 1 if: left > right |
| 2356 | // -1 if: left < right |
| 2357 | switch (in_type) { |
| 2358 | case Primitive::kPrimLong: { |
| 2359 | Register result = OutputRegister(compare); |
| 2360 | Register left = InputRegisterAt(compare, 0); |
| 2361 | Operand right = InputOperandAt(compare, 1); |
| 2362 | |
| 2363 | __ Cmp(left, right); |
| 2364 | __ Cset(result, ne); |
| 2365 | __ Cneg(result, result, lt); |
| 2366 | break; |
| 2367 | } |
| 2368 | case Primitive::kPrimFloat: |
| 2369 | case Primitive::kPrimDouble: { |
| 2370 | Register result = OutputRegister(compare); |
| 2371 | FPRegister left = InputFPRegisterAt(compare, 0); |
Alexandre Rames | 9341546 | 2015-02-17 15:08:20 +0000 | [diff] [blame] | 2372 | if (compare->GetLocations()->InAt(1).IsConstant()) { |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2373 | DCHECK(IsFloatingPointZeroConstant(compare->GetLocations()->InAt(1).GetConstant())); |
| 2374 | // 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] | 2375 | __ Fcmp(left, 0.0); |
| 2376 | } else { |
| 2377 | __ Fcmp(left, InputFPRegisterAt(compare, 1)); |
| 2378 | } |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 2379 | __ Cset(result, ne); |
| 2380 | __ Cneg(result, result, ARM64FPCondition(kCondLT, compare->IsGtBias())); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2381 | break; |
| 2382 | } |
| 2383 | default: |
| 2384 | LOG(FATAL) << "Unimplemented compare type " << in_type; |
| 2385 | } |
| 2386 | } |
| 2387 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2388 | void LocationsBuilderARM64::HandleCondition(HCondition* instruction) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2389 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2390 | |
| 2391 | if (Primitive::IsFloatingPointType(instruction->InputAt(0)->GetType())) { |
| 2392 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2393 | locations->SetInAt(1, |
| 2394 | IsFloatingPointZeroConstant(instruction->InputAt(1)) |
| 2395 | ? Location::ConstantLocation(instruction->InputAt(1)->AsConstant()) |
| 2396 | : Location::RequiresFpuRegister()); |
| 2397 | } else { |
| 2398 | // Integer cases. |
| 2399 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2400 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->InputAt(1), instruction)); |
| 2401 | } |
| 2402 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2403 | if (instruction->NeedsMaterialization()) { |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 2404 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2405 | } |
| 2406 | } |
| 2407 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2408 | void InstructionCodeGeneratorARM64::HandleCondition(HCondition* instruction) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2409 | if (!instruction->NeedsMaterialization()) { |
| 2410 | return; |
| 2411 | } |
| 2412 | |
| 2413 | LocationSummary* locations = instruction->GetLocations(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2414 | Register res = RegisterFrom(locations->Out(), instruction->GetType()); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2415 | IfCondition if_cond = instruction->GetCondition(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2416 | |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2417 | if (Primitive::IsFloatingPointType(instruction->InputAt(0)->GetType())) { |
| 2418 | FPRegister lhs = InputFPRegisterAt(instruction, 0); |
| 2419 | if (locations->InAt(1).IsConstant()) { |
| 2420 | DCHECK(IsFloatingPointZeroConstant(locations->InAt(1).GetConstant())); |
| 2421 | // 0.0 is the only immediate that can be encoded directly in an FCMP instruction. |
| 2422 | __ Fcmp(lhs, 0.0); |
| 2423 | } else { |
| 2424 | __ Fcmp(lhs, InputFPRegisterAt(instruction, 1)); |
| 2425 | } |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 2426 | __ Cset(res, ARM64FPCondition(if_cond, instruction->IsGtBias())); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2427 | } else { |
| 2428 | // Integer cases. |
| 2429 | Register lhs = InputRegisterAt(instruction, 0); |
| 2430 | Operand rhs = InputOperandAt(instruction, 1); |
| 2431 | __ Cmp(lhs, rhs); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 2432 | __ Cset(res, ARM64Condition(if_cond)); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2433 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2434 | } |
| 2435 | |
| 2436 | #define FOR_EACH_CONDITION_INSTRUCTION(M) \ |
| 2437 | M(Equal) \ |
| 2438 | M(NotEqual) \ |
| 2439 | M(LessThan) \ |
| 2440 | M(LessThanOrEqual) \ |
| 2441 | M(GreaterThan) \ |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2442 | M(GreaterThanOrEqual) \ |
| 2443 | M(Below) \ |
| 2444 | M(BelowOrEqual) \ |
| 2445 | M(Above) \ |
| 2446 | M(AboveOrEqual) |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2447 | #define DEFINE_CONDITION_VISITORS(Name) \ |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2448 | void LocationsBuilderARM64::Visit##Name(H##Name* comp) { HandleCondition(comp); } \ |
| 2449 | void InstructionCodeGeneratorARM64::Visit##Name(H##Name* comp) { HandleCondition(comp); } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2450 | FOR_EACH_CONDITION_INSTRUCTION(DEFINE_CONDITION_VISITORS) |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2451 | #undef DEFINE_CONDITION_VISITORS |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2452 | #undef FOR_EACH_CONDITION_INSTRUCTION |
| 2453 | |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2454 | void InstructionCodeGeneratorARM64::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 2455 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2456 | |
| 2457 | LocationSummary* locations = instruction->GetLocations(); |
| 2458 | Location second = locations->InAt(1); |
| 2459 | DCHECK(second.IsConstant()); |
| 2460 | |
| 2461 | Register out = OutputRegister(instruction); |
| 2462 | Register dividend = InputRegisterAt(instruction, 0); |
| 2463 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 2464 | DCHECK(imm == 1 || imm == -1); |
| 2465 | |
| 2466 | if (instruction->IsRem()) { |
| 2467 | __ Mov(out, 0); |
| 2468 | } else { |
| 2469 | if (imm == 1) { |
| 2470 | __ Mov(out, dividend); |
| 2471 | } else { |
| 2472 | __ Neg(out, dividend); |
| 2473 | } |
| 2474 | } |
| 2475 | } |
| 2476 | |
| 2477 | void InstructionCodeGeneratorARM64::DivRemByPowerOfTwo(HBinaryOperation* instruction) { |
| 2478 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2479 | |
| 2480 | LocationSummary* locations = instruction->GetLocations(); |
| 2481 | Location second = locations->InAt(1); |
| 2482 | DCHECK(second.IsConstant()); |
| 2483 | |
| 2484 | Register out = OutputRegister(instruction); |
| 2485 | Register dividend = InputRegisterAt(instruction, 0); |
| 2486 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 2487 | uint64_t abs_imm = static_cast<uint64_t>(AbsOrMin(imm)); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2488 | int ctz_imm = CTZ(abs_imm); |
| 2489 | |
| 2490 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2491 | Register temp = temps.AcquireSameSizeAs(out); |
| 2492 | |
| 2493 | if (instruction->IsDiv()) { |
| 2494 | __ Add(temp, dividend, abs_imm - 1); |
| 2495 | __ Cmp(dividend, 0); |
| 2496 | __ Csel(out, temp, dividend, lt); |
| 2497 | if (imm > 0) { |
| 2498 | __ Asr(out, out, ctz_imm); |
| 2499 | } else { |
| 2500 | __ Neg(out, Operand(out, ASR, ctz_imm)); |
| 2501 | } |
| 2502 | } else { |
| 2503 | int bits = instruction->GetResultType() == Primitive::kPrimInt ? 32 : 64; |
| 2504 | __ Asr(temp, dividend, bits - 1); |
| 2505 | __ Lsr(temp, temp, bits - ctz_imm); |
| 2506 | __ Add(out, dividend, temp); |
| 2507 | __ And(out, out, abs_imm - 1); |
| 2508 | __ Sub(out, out, temp); |
| 2509 | } |
| 2510 | } |
| 2511 | |
| 2512 | void InstructionCodeGeneratorARM64::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 2513 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2514 | |
| 2515 | LocationSummary* locations = instruction->GetLocations(); |
| 2516 | Location second = locations->InAt(1); |
| 2517 | DCHECK(second.IsConstant()); |
| 2518 | |
| 2519 | Register out = OutputRegister(instruction); |
| 2520 | Register dividend = InputRegisterAt(instruction, 0); |
| 2521 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 2522 | |
| 2523 | Primitive::Type type = instruction->GetResultType(); |
| 2524 | DCHECK(type == Primitive::kPrimInt || type == Primitive::kPrimLong); |
| 2525 | |
| 2526 | int64_t magic; |
| 2527 | int shift; |
| 2528 | CalculateMagicAndShiftForDivRem(imm, type == Primitive::kPrimLong /* is_long */, &magic, &shift); |
| 2529 | |
| 2530 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2531 | Register temp = temps.AcquireSameSizeAs(out); |
| 2532 | |
| 2533 | // temp = get_high(dividend * magic) |
| 2534 | __ Mov(temp, magic); |
| 2535 | if (type == Primitive::kPrimLong) { |
| 2536 | __ Smulh(temp, dividend, temp); |
| 2537 | } else { |
| 2538 | __ Smull(temp.X(), dividend, temp); |
| 2539 | __ Lsr(temp.X(), temp.X(), 32); |
| 2540 | } |
| 2541 | |
| 2542 | if (imm > 0 && magic < 0) { |
| 2543 | __ Add(temp, temp, dividend); |
| 2544 | } else if (imm < 0 && magic > 0) { |
| 2545 | __ Sub(temp, temp, dividend); |
| 2546 | } |
| 2547 | |
| 2548 | if (shift != 0) { |
| 2549 | __ Asr(temp, temp, shift); |
| 2550 | } |
| 2551 | |
| 2552 | if (instruction->IsDiv()) { |
| 2553 | __ Sub(out, temp, Operand(temp, ASR, type == Primitive::kPrimLong ? 63 : 31)); |
| 2554 | } else { |
| 2555 | __ Sub(temp, temp, Operand(temp, ASR, type == Primitive::kPrimLong ? 63 : 31)); |
| 2556 | // TODO: Strength reduction for msub. |
| 2557 | Register temp_imm = temps.AcquireSameSizeAs(out); |
| 2558 | __ Mov(temp_imm, imm); |
| 2559 | __ Msub(out, temp, temp_imm, dividend); |
| 2560 | } |
| 2561 | } |
| 2562 | |
| 2563 | void InstructionCodeGeneratorARM64::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 2564 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2565 | Primitive::Type type = instruction->GetResultType(); |
| 2566 | DCHECK(type == Primitive::kPrimInt || Primitive::kPrimLong); |
| 2567 | |
| 2568 | LocationSummary* locations = instruction->GetLocations(); |
| 2569 | Register out = OutputRegister(instruction); |
| 2570 | Location second = locations->InAt(1); |
| 2571 | |
| 2572 | if (second.IsConstant()) { |
| 2573 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 2574 | |
| 2575 | if (imm == 0) { |
| 2576 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 2577 | } else if (imm == 1 || imm == -1) { |
| 2578 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 2579 | } else if (IsPowerOfTwo(AbsOrMin(imm))) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2580 | DivRemByPowerOfTwo(instruction); |
| 2581 | } else { |
| 2582 | DCHECK(imm <= -2 || imm >= 2); |
| 2583 | GenerateDivRemWithAnyConstant(instruction); |
| 2584 | } |
| 2585 | } else { |
| 2586 | Register dividend = InputRegisterAt(instruction, 0); |
| 2587 | Register divisor = InputRegisterAt(instruction, 1); |
| 2588 | if (instruction->IsDiv()) { |
| 2589 | __ Sdiv(out, dividend, divisor); |
| 2590 | } else { |
| 2591 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2592 | Register temp = temps.AcquireSameSizeAs(out); |
| 2593 | __ Sdiv(temp, dividend, divisor); |
| 2594 | __ Msub(out, temp, divisor, dividend); |
| 2595 | } |
| 2596 | } |
| 2597 | } |
| 2598 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2599 | void LocationsBuilderARM64::VisitDiv(HDiv* div) { |
| 2600 | LocationSummary* locations = |
| 2601 | new (GetGraph()->GetArena()) LocationSummary(div, LocationSummary::kNoCall); |
| 2602 | switch (div->GetResultType()) { |
| 2603 | case Primitive::kPrimInt: |
| 2604 | case Primitive::kPrimLong: |
| 2605 | locations->SetInAt(0, Location::RequiresRegister()); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2606 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2607 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2608 | break; |
| 2609 | |
| 2610 | case Primitive::kPrimFloat: |
| 2611 | case Primitive::kPrimDouble: |
| 2612 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2613 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2614 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 2615 | break; |
| 2616 | |
| 2617 | default: |
| 2618 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 2619 | } |
| 2620 | } |
| 2621 | |
| 2622 | void InstructionCodeGeneratorARM64::VisitDiv(HDiv* div) { |
| 2623 | Primitive::Type type = div->GetResultType(); |
| 2624 | switch (type) { |
| 2625 | case Primitive::kPrimInt: |
| 2626 | case Primitive::kPrimLong: |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2627 | GenerateDivRemIntegral(div); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2628 | break; |
| 2629 | |
| 2630 | case Primitive::kPrimFloat: |
| 2631 | case Primitive::kPrimDouble: |
| 2632 | __ Fdiv(OutputFPRegister(div), InputFPRegisterAt(div, 0), InputFPRegisterAt(div, 1)); |
| 2633 | break; |
| 2634 | |
| 2635 | default: |
| 2636 | LOG(FATAL) << "Unexpected div type " << type; |
| 2637 | } |
| 2638 | } |
| 2639 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2640 | void LocationsBuilderARM64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2641 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 2642 | ? LocationSummary::kCallOnSlowPath |
| 2643 | : LocationSummary::kNoCall; |
| 2644 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2645 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
| 2646 | if (instruction->HasUses()) { |
| 2647 | locations->SetOut(Location::SameAsFirstInput()); |
| 2648 | } |
| 2649 | } |
| 2650 | |
| 2651 | void InstructionCodeGeneratorARM64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 2652 | SlowPathCodeARM64* slow_path = |
| 2653 | new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM64(instruction); |
| 2654 | codegen_->AddSlowPath(slow_path); |
| 2655 | Location value = instruction->GetLocations()->InAt(0); |
| 2656 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 2657 | Primitive::Type type = instruction->GetType(); |
| 2658 | |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 2659 | if ((type == Primitive::kPrimBoolean) || !Primitive::IsIntegralType(type)) { |
| 2660 | LOG(FATAL) << "Unexpected type " << type << " for DivZeroCheck."; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 2661 | return; |
| 2662 | } |
| 2663 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2664 | if (value.IsConstant()) { |
| 2665 | int64_t divisor = Int64ConstantFrom(value); |
| 2666 | if (divisor == 0) { |
| 2667 | __ B(slow_path->GetEntryLabel()); |
| 2668 | } else { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 2669 | // A division by a non-null constant is valid. We don't need to perform |
| 2670 | // any check, so simply fall through. |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2671 | } |
| 2672 | } else { |
| 2673 | __ Cbz(InputRegisterAt(instruction, 0), slow_path->GetEntryLabel()); |
| 2674 | } |
| 2675 | } |
| 2676 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2677 | void LocationsBuilderARM64::VisitDoubleConstant(HDoubleConstant* constant) { |
| 2678 | LocationSummary* locations = |
| 2679 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 2680 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2681 | } |
| 2682 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2683 | void InstructionCodeGeneratorARM64::VisitDoubleConstant( |
| 2684 | HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2685 | // Will be generated at use site. |
| 2686 | } |
| 2687 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2688 | void LocationsBuilderARM64::VisitExit(HExit* exit) { |
| 2689 | exit->SetLocations(nullptr); |
| 2690 | } |
| 2691 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2692 | void InstructionCodeGeneratorARM64::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2693 | } |
| 2694 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2695 | void LocationsBuilderARM64::VisitFloatConstant(HFloatConstant* constant) { |
| 2696 | LocationSummary* locations = |
| 2697 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 2698 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2699 | } |
| 2700 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2701 | void InstructionCodeGeneratorARM64::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2702 | // Will be generated at use site. |
| 2703 | } |
| 2704 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2705 | void InstructionCodeGeneratorARM64::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2706 | DCHECK(!successor->IsExitBlock()); |
| 2707 | HBasicBlock* block = got->GetBlock(); |
| 2708 | HInstruction* previous = got->GetPrevious(); |
| 2709 | HLoopInformation* info = block->GetLoopInformation(); |
| 2710 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2711 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2712 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck()); |
| 2713 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 2714 | return; |
| 2715 | } |
| 2716 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 2717 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 2718 | } |
| 2719 | if (!codegen_->GoesToNextBlock(block, successor)) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2720 | __ B(codegen_->GetLabelOf(successor)); |
| 2721 | } |
| 2722 | } |
| 2723 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2724 | void LocationsBuilderARM64::VisitGoto(HGoto* got) { |
| 2725 | got->SetLocations(nullptr); |
| 2726 | } |
| 2727 | |
| 2728 | void InstructionCodeGeneratorARM64::VisitGoto(HGoto* got) { |
| 2729 | HandleGoto(got, got->GetSuccessor()); |
| 2730 | } |
| 2731 | |
| 2732 | void LocationsBuilderARM64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 2733 | try_boundary->SetLocations(nullptr); |
| 2734 | } |
| 2735 | |
| 2736 | void InstructionCodeGeneratorARM64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 2737 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 2738 | if (!successor->IsExitBlock()) { |
| 2739 | HandleGoto(try_boundary, successor); |
| 2740 | } |
| 2741 | } |
| 2742 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2743 | void InstructionCodeGeneratorARM64::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2744 | size_t condition_input_index, |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2745 | vixl::Label* true_target, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2746 | vixl::Label* false_target) { |
| 2747 | // FP branching requires both targets to be explicit. If either of the targets |
| 2748 | // is nullptr (fallthrough) use and bind `fallthrough_target` instead. |
| 2749 | vixl::Label fallthrough_target; |
| 2750 | HInstruction* cond = instruction->InputAt(condition_input_index); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2751 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2752 | if (true_target == nullptr && false_target == nullptr) { |
| 2753 | // Nothing to do. The code always falls through. |
| 2754 | return; |
| 2755 | } else if (cond->IsIntConstant()) { |
| 2756 | // Constant condition, statically compared against 1. |
| 2757 | if (cond->AsIntConstant()->IsOne()) { |
| 2758 | if (true_target != nullptr) { |
| 2759 | __ B(true_target); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2760 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2761 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2762 | DCHECK(cond->AsIntConstant()->IsZero()); |
| 2763 | if (false_target != nullptr) { |
| 2764 | __ B(false_target); |
| 2765 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2766 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2767 | return; |
| 2768 | } |
| 2769 | |
| 2770 | // The following code generates these patterns: |
| 2771 | // (1) true_target == nullptr && false_target != nullptr |
| 2772 | // - opposite condition true => branch to false_target |
| 2773 | // (2) true_target != nullptr && false_target == nullptr |
| 2774 | // - condition true => branch to true_target |
| 2775 | // (3) true_target != nullptr && false_target != nullptr |
| 2776 | // - condition true => branch to true_target |
| 2777 | // - branch to false_target |
| 2778 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2779 | // The condition instruction has been materialized, compare the output to 0. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2780 | Location cond_val = instruction->GetLocations()->InAt(condition_input_index); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2781 | DCHECK(cond_val.IsRegister()); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2782 | if (true_target == nullptr) { |
| 2783 | __ Cbz(InputRegisterAt(instruction, condition_input_index), false_target); |
| 2784 | } else { |
| 2785 | __ Cbnz(InputRegisterAt(instruction, condition_input_index), true_target); |
| 2786 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2787 | } else { |
| 2788 | // The condition instruction has not been materialized, use its inputs as |
| 2789 | // the comparison and its condition as the branch condition. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2790 | HCondition* condition = cond->AsCondition(); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2791 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2792 | Primitive::Type type = condition->InputAt(0)->GetType(); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2793 | if (Primitive::IsFloatingPointType(type)) { |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2794 | FPRegister lhs = InputFPRegisterAt(condition, 0); |
| 2795 | if (condition->GetLocations()->InAt(1).IsConstant()) { |
| 2796 | DCHECK(IsFloatingPointZeroConstant(condition->GetLocations()->InAt(1).GetConstant())); |
| 2797 | // 0.0 is the only immediate that can be encoded directly in an FCMP instruction. |
| 2798 | __ Fcmp(lhs, 0.0); |
| 2799 | } else { |
| 2800 | __ Fcmp(lhs, InputFPRegisterAt(condition, 1)); |
| 2801 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2802 | if (true_target == nullptr) { |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 2803 | IfCondition opposite_condition = condition->GetOppositeCondition(); |
| 2804 | __ B(ARM64FPCondition(opposite_condition, condition->IsGtBias()), false_target); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2805 | } else { |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 2806 | __ B(ARM64FPCondition(condition->GetCondition(), condition->IsGtBias()), true_target); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2807 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2808 | } else { |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2809 | // Integer cases. |
| 2810 | Register lhs = InputRegisterAt(condition, 0); |
| 2811 | Operand rhs = InputOperandAt(condition, 1); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2812 | |
| 2813 | Condition arm64_cond; |
| 2814 | vixl::Label* non_fallthrough_target; |
| 2815 | if (true_target == nullptr) { |
| 2816 | arm64_cond = ARM64Condition(condition->GetOppositeCondition()); |
| 2817 | non_fallthrough_target = false_target; |
| 2818 | } else { |
| 2819 | arm64_cond = ARM64Condition(condition->GetCondition()); |
| 2820 | non_fallthrough_target = true_target; |
| 2821 | } |
| 2822 | |
Aart Bik | 086d27e | 2016-01-20 17:02:00 -0800 | [diff] [blame^] | 2823 | if ((arm64_cond == eq || arm64_cond == ne || arm64_cond == lt || arm64_cond == ge) && |
| 2824 | rhs.IsImmediate() && (rhs.immediate() == 0)) { |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2825 | switch (arm64_cond) { |
| 2826 | case eq: |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2827 | __ Cbz(lhs, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2828 | break; |
| 2829 | case ne: |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2830 | __ Cbnz(lhs, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2831 | break; |
| 2832 | case lt: |
| 2833 | // Test the sign bit and branch accordingly. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2834 | __ Tbnz(lhs, (lhs.IsX() ? kXRegSize : kWRegSize) - 1, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2835 | break; |
| 2836 | case ge: |
| 2837 | // Test the sign bit and branch accordingly. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2838 | __ Tbz(lhs, (lhs.IsX() ? kXRegSize : kWRegSize) - 1, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2839 | break; |
| 2840 | default: |
| 2841 | // Without the `static_cast` the compiler throws an error for |
| 2842 | // `-Werror=sign-promo`. |
| 2843 | LOG(FATAL) << "Unexpected condition: " << static_cast<int>(arm64_cond); |
| 2844 | } |
| 2845 | } else { |
| 2846 | __ Cmp(lhs, rhs); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2847 | __ B(arm64_cond, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2848 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2849 | } |
| 2850 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2851 | |
| 2852 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 2853 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 2854 | if (true_target != nullptr && false_target != nullptr) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2855 | __ B(false_target); |
| 2856 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2857 | |
| 2858 | if (fallthrough_target.IsLinked()) { |
| 2859 | __ Bind(&fallthrough_target); |
| 2860 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2861 | } |
| 2862 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2863 | void LocationsBuilderARM64::VisitIf(HIf* if_instr) { |
| 2864 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2865 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2866 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2867 | } |
| 2868 | } |
| 2869 | |
| 2870 | void InstructionCodeGeneratorARM64::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2871 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 2872 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
| 2873 | vixl::Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 2874 | nullptr : codegen_->GetLabelOf(true_successor); |
| 2875 | vixl::Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 2876 | nullptr : codegen_->GetLabelOf(false_successor); |
| 2877 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2878 | } |
| 2879 | |
| 2880 | void LocationsBuilderARM64::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 2881 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 2882 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2883 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2884 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2885 | } |
| 2886 | } |
| 2887 | |
| 2888 | void InstructionCodeGeneratorARM64::VisitDeoptimize(HDeoptimize* deoptimize) { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 2889 | SlowPathCodeARM64* slow_path = |
| 2890 | deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathARM64>(deoptimize); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2891 | GenerateTestAndBranch(deoptimize, |
| 2892 | /* condition_input_index */ 0, |
| 2893 | slow_path->GetEntryLabel(), |
| 2894 | /* false_target */ nullptr); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2895 | } |
| 2896 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 2897 | void LocationsBuilderARM64::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| 2898 | new (GetGraph()->GetArena()) LocationSummary(info); |
| 2899 | } |
| 2900 | |
| 2901 | void InstructionCodeGeneratorARM64::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
David Srbecky | b7070a2 | 2016-01-08 18:13:53 +0000 | [diff] [blame] | 2902 | if (codegen_->HasStackMapAtCurrentPc()) { |
| 2903 | // Ensure that we do not collide with the stack map of the previous instruction. |
| 2904 | __ Nop(); |
| 2905 | } |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 2906 | codegen_->RecordPcInfo(info, info->GetDexPc()); |
| 2907 | } |
| 2908 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2909 | void LocationsBuilderARM64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2910 | HandleFieldGet(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2911 | } |
| 2912 | |
| 2913 | void InstructionCodeGeneratorARM64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2914 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2915 | } |
| 2916 | |
| 2917 | void LocationsBuilderARM64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2918 | HandleFieldSet(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2919 | } |
| 2920 | |
| 2921 | void InstructionCodeGeneratorARM64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 2922 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2923 | } |
| 2924 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2925 | void LocationsBuilderARM64::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 2926 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2927 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 2928 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 2929 | case TypeCheckKind::kExactCheck: |
| 2930 | case TypeCheckKind::kAbstractClassCheck: |
| 2931 | case TypeCheckKind::kClassHierarchyCheck: |
| 2932 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2933 | call_kind = |
| 2934 | kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 2935 | break; |
| 2936 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2937 | case TypeCheckKind::kUnresolvedCheck: |
| 2938 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 2939 | call_kind = LocationSummary::kCallOnSlowPath; |
| 2940 | break; |
| 2941 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2942 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2943 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2944 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2945 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2946 | // The "out" register is used as a temporary, so it overlaps with the inputs. |
| 2947 | // Note that TypeCheckSlowPathARM64 uses this register too. |
| 2948 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 2949 | // When read barriers are enabled, we need a temporary register for |
| 2950 | // some cases. |
| 2951 | if (kEmitCompilerReadBarrier && |
| 2952 | (type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 2953 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 2954 | type_check_kind == TypeCheckKind::kArrayObjectCheck)) { |
| 2955 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 2956 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2957 | } |
| 2958 | |
| 2959 | void InstructionCodeGeneratorARM64::VisitInstanceOf(HInstanceOf* instruction) { |
| 2960 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2961 | Location obj_loc = locations->InAt(0); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 2962 | Register obj = InputRegisterAt(instruction, 0); |
| 2963 | Register cls = InputRegisterAt(instruction, 1); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2964 | Location out_loc = locations->Out(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2965 | Register out = OutputRegister(instruction); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 2966 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2967 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 2968 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 2969 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2970 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 2971 | vixl::Label done, zero; |
| 2972 | SlowPathCodeARM64* slow_path = nullptr; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2973 | |
| 2974 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 2975 | // Avoid null check if we know `obj` is not null. |
| 2976 | if (instruction->MustDoNullCheck()) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 2977 | __ Cbz(obj, &zero); |
| 2978 | } |
| 2979 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2980 | // /* HeapReference<Class> */ out = obj->klass_ |
| 2981 | __ Ldr(out, HeapOperand(obj.W(), class_offset)); |
| 2982 | codegen_->MaybeGenerateReadBarrier(instruction, out_loc, out_loc, obj_loc, class_offset); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 2983 | |
| 2984 | switch (instruction->GetTypeCheckKind()) { |
| 2985 | case TypeCheckKind::kExactCheck: { |
| 2986 | __ Cmp(out, cls); |
| 2987 | __ Cset(out, eq); |
| 2988 | if (zero.IsLinked()) { |
| 2989 | __ B(&done); |
| 2990 | } |
| 2991 | break; |
| 2992 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2993 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 2994 | case TypeCheckKind::kAbstractClassCheck: { |
| 2995 | // If the class is abstract, we eagerly fetch the super class of the |
| 2996 | // object to avoid doing a comparison we know will fail. |
| 2997 | vixl::Label loop, success; |
| 2998 | __ Bind(&loop); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2999 | Location temp_loc = kEmitCompilerReadBarrier ? locations->GetTemp(0) : Location::NoLocation(); |
| 3000 | if (kEmitCompilerReadBarrier) { |
| 3001 | // Save the value of `out` into `temp` before overwriting it |
| 3002 | // in the following move operation, as we will need it for the |
| 3003 | // read barrier below. |
| 3004 | Register temp = WRegisterFrom(temp_loc); |
| 3005 | __ Mov(temp, out); |
| 3006 | } |
| 3007 | // /* HeapReference<Class> */ out = out->super_class_ |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3008 | __ Ldr(out, HeapOperand(out, super_offset)); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3009 | codegen_->MaybeGenerateReadBarrier(instruction, out_loc, out_loc, temp_loc, super_offset); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3010 | // If `out` is null, we use it for the result, and jump to `done`. |
| 3011 | __ Cbz(out, &done); |
| 3012 | __ Cmp(out, cls); |
| 3013 | __ B(ne, &loop); |
| 3014 | __ Mov(out, 1); |
| 3015 | if (zero.IsLinked()) { |
| 3016 | __ B(&done); |
| 3017 | } |
| 3018 | break; |
| 3019 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3020 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3021 | case TypeCheckKind::kClassHierarchyCheck: { |
| 3022 | // Walk over the class hierarchy to find a match. |
| 3023 | vixl::Label loop, success; |
| 3024 | __ Bind(&loop); |
| 3025 | __ Cmp(out, cls); |
| 3026 | __ B(eq, &success); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3027 | Location temp_loc = kEmitCompilerReadBarrier ? locations->GetTemp(0) : Location::NoLocation(); |
| 3028 | if (kEmitCompilerReadBarrier) { |
| 3029 | // Save the value of `out` into `temp` before overwriting it |
| 3030 | // in the following move operation, as we will need it for the |
| 3031 | // read barrier below. |
| 3032 | Register temp = WRegisterFrom(temp_loc); |
| 3033 | __ Mov(temp, out); |
| 3034 | } |
| 3035 | // /* HeapReference<Class> */ out = out->super_class_ |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3036 | __ Ldr(out, HeapOperand(out, super_offset)); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3037 | codegen_->MaybeGenerateReadBarrier(instruction, out_loc, out_loc, temp_loc, super_offset); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3038 | __ Cbnz(out, &loop); |
| 3039 | // If `out` is null, we use it for the result, and jump to `done`. |
| 3040 | __ B(&done); |
| 3041 | __ Bind(&success); |
| 3042 | __ Mov(out, 1); |
| 3043 | if (zero.IsLinked()) { |
| 3044 | __ B(&done); |
| 3045 | } |
| 3046 | break; |
| 3047 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3048 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3049 | case TypeCheckKind::kArrayObjectCheck: { |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 3050 | // Do an exact check. |
| 3051 | vixl::Label exact_check; |
| 3052 | __ Cmp(out, cls); |
| 3053 | __ B(eq, &exact_check); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3054 | // Otherwise, we need to check that the object's class is a non-primitive array. |
| 3055 | Location temp_loc = kEmitCompilerReadBarrier ? locations->GetTemp(0) : Location::NoLocation(); |
| 3056 | if (kEmitCompilerReadBarrier) { |
| 3057 | // Save the value of `out` into `temp` before overwriting it |
| 3058 | // in the following move operation, as we will need it for the |
| 3059 | // read barrier below. |
| 3060 | Register temp = WRegisterFrom(temp_loc); |
| 3061 | __ Mov(temp, out); |
| 3062 | } |
| 3063 | // /* HeapReference<Class> */ out = out->component_type_ |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3064 | __ Ldr(out, HeapOperand(out, component_offset)); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3065 | codegen_->MaybeGenerateReadBarrier(instruction, out_loc, out_loc, temp_loc, component_offset); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3066 | // If `out` is null, we use it for the result, and jump to `done`. |
| 3067 | __ Cbz(out, &done); |
| 3068 | __ Ldrh(out, HeapOperand(out, primitive_offset)); |
| 3069 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
| 3070 | __ Cbnz(out, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 3071 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3072 | __ Mov(out, 1); |
| 3073 | __ B(&done); |
| 3074 | break; |
| 3075 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3076 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3077 | case TypeCheckKind::kArrayCheck: { |
| 3078 | __ Cmp(out, cls); |
| 3079 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3080 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM64(instruction, |
| 3081 | /* is_fatal */ false); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3082 | codegen_->AddSlowPath(slow_path); |
| 3083 | __ B(ne, slow_path->GetEntryLabel()); |
| 3084 | __ Mov(out, 1); |
| 3085 | if (zero.IsLinked()) { |
| 3086 | __ B(&done); |
| 3087 | } |
| 3088 | break; |
| 3089 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3090 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 3091 | case TypeCheckKind::kUnresolvedCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3092 | case TypeCheckKind::kInterfaceCheck: { |
| 3093 | // Note that we indeed only call on slow path, but we always go |
| 3094 | // into the slow path for the unresolved and interface check |
| 3095 | // cases. |
| 3096 | // |
| 3097 | // We cannot directly call the InstanceofNonTrivial runtime |
| 3098 | // entry point without resorting to a type checking slow path |
| 3099 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 3100 | // require to assign fixed registers for the inputs of this |
| 3101 | // HInstanceOf instruction (following the runtime calling |
| 3102 | // convention), which might be cluttered by the potential first |
| 3103 | // read barrier emission at the beginning of this method. |
| 3104 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 3105 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM64(instruction, |
| 3106 | /* is_fatal */ false); |
| 3107 | codegen_->AddSlowPath(slow_path); |
| 3108 | __ B(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3109 | if (zero.IsLinked()) { |
| 3110 | __ B(&done); |
| 3111 | } |
| 3112 | break; |
| 3113 | } |
| 3114 | } |
| 3115 | |
| 3116 | if (zero.IsLinked()) { |
| 3117 | __ Bind(&zero); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 3118 | __ Mov(out, 0); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3119 | } |
| 3120 | |
| 3121 | if (done.IsLinked()) { |
| 3122 | __ Bind(&done); |
| 3123 | } |
| 3124 | |
| 3125 | if (slow_path != nullptr) { |
| 3126 | __ Bind(slow_path->GetExitLabel()); |
| 3127 | } |
| 3128 | } |
| 3129 | |
| 3130 | void LocationsBuilderARM64::VisitCheckCast(HCheckCast* instruction) { |
| 3131 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 3132 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
| 3133 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3134 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 3135 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3136 | case TypeCheckKind::kExactCheck: |
| 3137 | case TypeCheckKind::kAbstractClassCheck: |
| 3138 | case TypeCheckKind::kClassHierarchyCheck: |
| 3139 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3140 | call_kind = (throws_into_catch || kEmitCompilerReadBarrier) ? |
| 3141 | LocationSummary::kCallOnSlowPath : |
| 3142 | LocationSummary::kNoCall; // In fact, call on a fatal (non-returning) slow path. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3143 | break; |
| 3144 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3145 | case TypeCheckKind::kUnresolvedCheck: |
| 3146 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3147 | call_kind = LocationSummary::kCallOnSlowPath; |
| 3148 | break; |
| 3149 | } |
| 3150 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3151 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 3152 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3153 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3154 | // Note that TypeCheckSlowPathARM64 uses this "temp" register too. |
| 3155 | locations->AddTemp(Location::RequiresRegister()); |
| 3156 | locations->AddTemp(Location::RequiresRegister()); |
| 3157 | // When read barriers are enabled, we need an additional temporary |
| 3158 | // register for some cases. |
| 3159 | if (kEmitCompilerReadBarrier && |
| 3160 | (type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 3161 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 3162 | type_check_kind == TypeCheckKind::kArrayObjectCheck)) { |
| 3163 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3164 | } |
| 3165 | } |
| 3166 | |
| 3167 | void InstructionCodeGeneratorARM64::VisitCheckCast(HCheckCast* instruction) { |
| 3168 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3169 | Location obj_loc = locations->InAt(0); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3170 | Register obj = InputRegisterAt(instruction, 0); |
| 3171 | Register cls = InputRegisterAt(instruction, 1); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3172 | Location temp_loc = locations->GetTemp(0); |
| 3173 | Register temp = WRegisterFrom(temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3174 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 3175 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 3176 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 3177 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3178 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3179 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 3180 | bool is_type_check_slow_path_fatal = |
| 3181 | (type_check_kind == TypeCheckKind::kExactCheck || |
| 3182 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 3183 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 3184 | type_check_kind == TypeCheckKind::kArrayObjectCheck) && |
| 3185 | !instruction->CanThrowIntoCatchBlock(); |
| 3186 | SlowPathCodeARM64* type_check_slow_path = |
| 3187 | new (GetGraph()->GetArena()) TypeCheckSlowPathARM64(instruction, |
| 3188 | is_type_check_slow_path_fatal); |
| 3189 | codegen_->AddSlowPath(type_check_slow_path); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3190 | |
| 3191 | vixl::Label done; |
| 3192 | // Avoid null check if we know obj is not null. |
| 3193 | if (instruction->MustDoNullCheck()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 3194 | __ Cbz(obj, &done); |
| 3195 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3196 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3197 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 3198 | __ Ldr(temp, HeapOperand(obj, class_offset)); |
| 3199 | codegen_->MaybeGenerateReadBarrier(instruction, temp_loc, temp_loc, obj_loc, class_offset); |
Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame] | 3200 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3201 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3202 | case TypeCheckKind::kExactCheck: |
| 3203 | case TypeCheckKind::kArrayCheck: { |
| 3204 | __ Cmp(temp, cls); |
| 3205 | // Jump to slow path for throwing the exception or doing a |
| 3206 | // more involved array check. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3207 | __ B(ne, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3208 | break; |
| 3209 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3210 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3211 | case TypeCheckKind::kAbstractClassCheck: { |
| 3212 | // If the class is abstract, we eagerly fetch the super class of the |
| 3213 | // object to avoid doing a comparison we know will fail. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3214 | vixl::Label loop, compare_classes; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3215 | __ Bind(&loop); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3216 | Location temp2_loc = |
| 3217 | kEmitCompilerReadBarrier ? locations->GetTemp(1) : Location::NoLocation(); |
| 3218 | if (kEmitCompilerReadBarrier) { |
| 3219 | // Save the value of `temp` into `temp2` before overwriting it |
| 3220 | // in the following move operation, as we will need it for the |
| 3221 | // read barrier below. |
| 3222 | Register temp2 = WRegisterFrom(temp2_loc); |
| 3223 | __ Mov(temp2, temp); |
| 3224 | } |
| 3225 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3226 | __ Ldr(temp, HeapOperand(temp, super_offset)); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3227 | codegen_->MaybeGenerateReadBarrier(instruction, temp_loc, temp_loc, temp2_loc, super_offset); |
| 3228 | |
| 3229 | // If the class reference currently in `temp` is not null, jump |
| 3230 | // to the `compare_classes` label to compare it with the checked |
| 3231 | // class. |
| 3232 | __ Cbnz(temp, &compare_classes); |
| 3233 | // Otherwise, jump to the slow path to throw the exception. |
| 3234 | // |
| 3235 | // But before, move back the object's class into `temp` before |
| 3236 | // going into the slow path, as it has been overwritten in the |
| 3237 | // meantime. |
| 3238 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 3239 | __ Ldr(temp, HeapOperand(obj, class_offset)); |
| 3240 | codegen_->MaybeGenerateReadBarrier(instruction, temp_loc, temp_loc, obj_loc, class_offset); |
| 3241 | __ B(type_check_slow_path->GetEntryLabel()); |
| 3242 | |
| 3243 | __ Bind(&compare_classes); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3244 | __ Cmp(temp, cls); |
| 3245 | __ B(ne, &loop); |
| 3246 | break; |
| 3247 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3248 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3249 | case TypeCheckKind::kClassHierarchyCheck: { |
| 3250 | // Walk over the class hierarchy to find a match. |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 3251 | vixl::Label loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3252 | __ Bind(&loop); |
| 3253 | __ Cmp(temp, cls); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 3254 | __ B(eq, &done); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3255 | |
| 3256 | Location temp2_loc = |
| 3257 | kEmitCompilerReadBarrier ? locations->GetTemp(1) : Location::NoLocation(); |
| 3258 | if (kEmitCompilerReadBarrier) { |
| 3259 | // Save the value of `temp` into `temp2` before overwriting it |
| 3260 | // in the following move operation, as we will need it for the |
| 3261 | // read barrier below. |
| 3262 | Register temp2 = WRegisterFrom(temp2_loc); |
| 3263 | __ Mov(temp2, temp); |
| 3264 | } |
| 3265 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3266 | __ Ldr(temp, HeapOperand(temp, super_offset)); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3267 | codegen_->MaybeGenerateReadBarrier(instruction, temp_loc, temp_loc, temp2_loc, super_offset); |
| 3268 | |
| 3269 | // If the class reference currently in `temp` is not null, jump |
| 3270 | // back at the beginning of the loop. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3271 | __ Cbnz(temp, &loop); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3272 | // Otherwise, jump to the slow path to throw the exception. |
| 3273 | // |
| 3274 | // But before, move back the object's class into `temp` before |
| 3275 | // going into the slow path, as it has been overwritten in the |
| 3276 | // meantime. |
| 3277 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 3278 | __ Ldr(temp, HeapOperand(obj, class_offset)); |
| 3279 | codegen_->MaybeGenerateReadBarrier(instruction, temp_loc, temp_loc, obj_loc, class_offset); |
| 3280 | __ B(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3281 | break; |
| 3282 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3283 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3284 | case TypeCheckKind::kArrayObjectCheck: { |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 3285 | // Do an exact check. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3286 | vixl::Label check_non_primitive_component_type; |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 3287 | __ Cmp(temp, cls); |
| 3288 | __ B(eq, &done); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3289 | |
| 3290 | // Otherwise, we need to check that the object's class is a non-primitive array. |
| 3291 | Location temp2_loc = |
| 3292 | kEmitCompilerReadBarrier ? locations->GetTemp(1) : Location::NoLocation(); |
| 3293 | if (kEmitCompilerReadBarrier) { |
| 3294 | // Save the value of `temp` into `temp2` before overwriting it |
| 3295 | // in the following move operation, as we will need it for the |
| 3296 | // read barrier below. |
| 3297 | Register temp2 = WRegisterFrom(temp2_loc); |
| 3298 | __ Mov(temp2, temp); |
| 3299 | } |
| 3300 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3301 | __ Ldr(temp, HeapOperand(temp, component_offset)); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3302 | codegen_->MaybeGenerateReadBarrier( |
| 3303 | instruction, temp_loc, temp_loc, temp2_loc, component_offset); |
| 3304 | |
| 3305 | // If the component type is not null (i.e. the object is indeed |
| 3306 | // an array), jump to label `check_non_primitive_component_type` |
| 3307 | // to further check that this component type is not a primitive |
| 3308 | // type. |
| 3309 | __ Cbnz(temp, &check_non_primitive_component_type); |
| 3310 | // Otherwise, jump to the slow path to throw the exception. |
| 3311 | // |
| 3312 | // But before, move back the object's class into `temp` before |
| 3313 | // going into the slow path, as it has been overwritten in the |
| 3314 | // meantime. |
| 3315 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 3316 | __ Ldr(temp, HeapOperand(obj, class_offset)); |
| 3317 | codegen_->MaybeGenerateReadBarrier(instruction, temp_loc, temp_loc, obj_loc, class_offset); |
| 3318 | __ B(type_check_slow_path->GetEntryLabel()); |
| 3319 | |
| 3320 | __ Bind(&check_non_primitive_component_type); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3321 | __ Ldrh(temp, HeapOperand(temp, primitive_offset)); |
| 3322 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3323 | __ Cbz(temp, &done); |
| 3324 | // Same comment as above regarding `temp` and the slow path. |
| 3325 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 3326 | __ Ldr(temp, HeapOperand(obj, class_offset)); |
| 3327 | codegen_->MaybeGenerateReadBarrier(instruction, temp_loc, temp_loc, obj_loc, class_offset); |
| 3328 | __ B(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3329 | break; |
| 3330 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3331 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 3332 | case TypeCheckKind::kUnresolvedCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3333 | case TypeCheckKind::kInterfaceCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3334 | // We always go into the type check slow path for the unresolved |
| 3335 | // and interface check cases. |
| 3336 | // |
| 3337 | // We cannot directly call the CheckCast runtime entry point |
| 3338 | // without resorting to a type checking slow path here (i.e. by |
| 3339 | // calling InvokeRuntime directly), as it would require to |
| 3340 | // assign fixed registers for the inputs of this HInstanceOf |
| 3341 | // instruction (following the runtime calling convention), which |
| 3342 | // might be cluttered by the potential first read barrier |
| 3343 | // emission at the beginning of this method. |
| 3344 | __ B(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3345 | break; |
| 3346 | } |
Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame] | 3347 | __ Bind(&done); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3348 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3349 | __ Bind(type_check_slow_path->GetExitLabel()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3350 | } |
| 3351 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3352 | void LocationsBuilderARM64::VisitIntConstant(HIntConstant* constant) { |
| 3353 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant); |
| 3354 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3355 | } |
| 3356 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3357 | void InstructionCodeGeneratorARM64::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3358 | // Will be generated at use site. |
| 3359 | } |
| 3360 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 3361 | void LocationsBuilderARM64::VisitNullConstant(HNullConstant* constant) { |
| 3362 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant); |
| 3363 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3364 | } |
| 3365 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3366 | void InstructionCodeGeneratorARM64::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 3367 | // Will be generated at use site. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 3368 | } |
| 3369 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 3370 | void LocationsBuilderARM64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 3371 | // The trampoline uses the same calling convention as dex calling conventions, |
| 3372 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 3373 | // the method_idx. |
| 3374 | HandleInvoke(invoke); |
| 3375 | } |
| 3376 | |
| 3377 | void InstructionCodeGeneratorARM64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 3378 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 3379 | } |
| 3380 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3381 | void LocationsBuilderARM64::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 3382 | InvokeDexCallingConventionVisitorARM64 calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 3383 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3384 | } |
| 3385 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3386 | void LocationsBuilderARM64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 3387 | HandleInvoke(invoke); |
| 3388 | } |
| 3389 | |
| 3390 | void InstructionCodeGeneratorARM64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 3391 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3392 | LocationSummary* locations = invoke->GetLocations(); |
| 3393 | Register temp = XRegisterFrom(locations->GetTemp(0)); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 3394 | uint32_t method_offset = mirror::Class::EmbeddedImTableEntryOffset( |
| 3395 | invoke->GetImtIndex() % mirror::Class::kImtSize, kArm64PointerSize).Uint32Value(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3396 | Location receiver = locations->InAt(0); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3397 | Offset class_offset = mirror::Object::ClassOffset(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 3398 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64WordSize); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3399 | |
| 3400 | // The register ip1 is required to be used for the hidden argument in |
| 3401 | // art_quick_imt_conflict_trampoline, so prevent VIXL from using it. |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 3402 | MacroAssembler* masm = GetVIXLAssembler(); |
| 3403 | UseScratchRegisterScope scratch_scope(masm); |
| 3404 | BlockPoolsScope block_pools(masm); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3405 | scratch_scope.Exclude(ip1); |
| 3406 | __ Mov(ip1, invoke->GetDexMethodIndex()); |
| 3407 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3408 | if (receiver.IsStackSlot()) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 3409 | __ Ldr(temp.W(), StackOperandFrom(receiver)); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3410 | // /* HeapReference<Class> */ temp = temp->klass_ |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 3411 | __ Ldr(temp.W(), HeapOperand(temp.W(), class_offset)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3412 | } else { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3413 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 3414 | __ Ldr(temp.W(), HeapOperandFrom(receiver, class_offset)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3415 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3416 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3417 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 3418 | // emit a read barrier for the previous class reference load. |
| 3419 | // However this is not required in practice, as this is an |
| 3420 | // intermediate/temporary reference and because the current |
| 3421 | // concurrent copying collector keeps the from-space memory |
| 3422 | // intact/accessible until the end of the marking phase (the |
| 3423 | // concurrent copying collector may not in the future). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3424 | GetAssembler()->MaybeUnpoisonHeapReference(temp.W()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3425 | // temp = temp->GetImtEntryAt(method_offset); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 3426 | __ Ldr(temp, MemOperand(temp, method_offset)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3427 | // lr = temp->GetEntryPoint(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 3428 | __ Ldr(lr, MemOperand(temp, entry_point.Int32Value())); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3429 | // lr(); |
| 3430 | __ Blr(lr); |
| 3431 | DCHECK(!codegen_->IsLeafMethod()); |
| 3432 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 3433 | } |
| 3434 | |
| 3435 | void LocationsBuilderARM64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 3436 | IntrinsicLocationsBuilderARM64 intrinsic(GetGraph()->GetArena()); |
| 3437 | if (intrinsic.TryDispatch(invoke)) { |
| 3438 | return; |
| 3439 | } |
| 3440 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3441 | HandleInvoke(invoke); |
| 3442 | } |
| 3443 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 3444 | void LocationsBuilderARM64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 3445 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 3446 | // art::PrepareForRegisterAllocation. |
| 3447 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3448 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 3449 | IntrinsicLocationsBuilderARM64 intrinsic(GetGraph()->GetArena()); |
| 3450 | if (intrinsic.TryDispatch(invoke)) { |
| 3451 | return; |
| 3452 | } |
| 3453 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3454 | HandleInvoke(invoke); |
| 3455 | } |
| 3456 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 3457 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARM64* codegen) { |
| 3458 | if (invoke->GetLocations()->Intrinsified()) { |
| 3459 | IntrinsicCodeGeneratorARM64 intrinsic(codegen); |
| 3460 | intrinsic.Dispatch(invoke); |
| 3461 | return true; |
| 3462 | } |
| 3463 | return false; |
| 3464 | } |
| 3465 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3466 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorARM64::GetSupportedInvokeStaticOrDirectDispatch( |
| 3467 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
| 3468 | MethodReference target_method ATTRIBUTE_UNUSED) { |
| 3469 | // On arm64 we support all dispatch types. |
| 3470 | return desired_dispatch_info; |
| 3471 | } |
| 3472 | |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 3473 | void CodeGeneratorARM64::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3474 | // For better instruction scheduling we load the direct code pointer before the method pointer. |
| 3475 | bool direct_code_loaded = false; |
| 3476 | switch (invoke->GetCodePtrLocation()) { |
| 3477 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 3478 | // LR = code address from literal pool with link-time patch. |
| 3479 | __ Ldr(lr, DeduplicateMethodCodeLiteral(invoke->GetTargetMethod())); |
| 3480 | direct_code_loaded = true; |
| 3481 | break; |
| 3482 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
| 3483 | // LR = invoke->GetDirectCodePtr(); |
| 3484 | __ Ldr(lr, DeduplicateUint64Literal(invoke->GetDirectCodePtr())); |
| 3485 | direct_code_loaded = true; |
| 3486 | break; |
| 3487 | default: |
| 3488 | break; |
| 3489 | } |
| 3490 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 3491 | // 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] | 3492 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 3493 | switch (invoke->GetMethodLoadKind()) { |
| 3494 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: |
| 3495 | // temp = thread->string_init_entrypoint |
Alexandre Rames | 6dc0174 | 2015-11-12 14:44:19 +0000 | [diff] [blame] | 3496 | __ Ldr(XRegisterFrom(temp), MemOperand(tr, invoke->GetStringInitOffset())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3497 | break; |
| 3498 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3499 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3500 | break; |
| 3501 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 3502 | // Load method address from literal pool. |
Alexandre Rames | 6dc0174 | 2015-11-12 14:44:19 +0000 | [diff] [blame] | 3503 | __ Ldr(XRegisterFrom(temp), DeduplicateUint64Literal(invoke->GetMethodAddress())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3504 | break; |
| 3505 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup: |
| 3506 | // Load method address from literal pool with a link-time patch. |
Alexandre Rames | 6dc0174 | 2015-11-12 14:44:19 +0000 | [diff] [blame] | 3507 | __ Ldr(XRegisterFrom(temp), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3508 | DeduplicateMethodAddressLiteral(invoke->GetTargetMethod())); |
| 3509 | break; |
| 3510 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: { |
| 3511 | // Add ADRP with its PC-relative DexCache access patch. |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 3512 | pc_relative_dex_cache_patches_.emplace_back(*invoke->GetTargetMethod().dex_file, |
| 3513 | invoke->GetDexCacheArrayOffset()); |
| 3514 | vixl::Label* pc_insn_label = &pc_relative_dex_cache_patches_.back().label; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3515 | { |
| 3516 | vixl::SingleEmissionCheckScope guard(GetVIXLAssembler()); |
Alexandre Rames | 6dc0174 | 2015-11-12 14:44:19 +0000 | [diff] [blame] | 3517 | __ Bind(pc_insn_label); |
| 3518 | __ adrp(XRegisterFrom(temp), 0); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3519 | } |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 3520 | pc_relative_dex_cache_patches_.back().pc_insn_label = pc_insn_label; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3521 | // Add LDR with its PC-relative DexCache access patch. |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 3522 | pc_relative_dex_cache_patches_.emplace_back(*invoke->GetTargetMethod().dex_file, |
| 3523 | invoke->GetDexCacheArrayOffset()); |
Alexandre Rames | 6dc0174 | 2015-11-12 14:44:19 +0000 | [diff] [blame] | 3524 | { |
| 3525 | vixl::SingleEmissionCheckScope guard(GetVIXLAssembler()); |
| 3526 | __ Bind(&pc_relative_dex_cache_patches_.back().label); |
| 3527 | __ ldr(XRegisterFrom(temp), MemOperand(XRegisterFrom(temp), 0)); |
| 3528 | pc_relative_dex_cache_patches_.back().pc_insn_label = pc_insn_label; |
| 3529 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3530 | break; |
Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 3531 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3532 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3533 | Location current_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3534 | Register reg = XRegisterFrom(temp); |
| 3535 | Register method_reg; |
| 3536 | if (current_method.IsRegister()) { |
| 3537 | method_reg = XRegisterFrom(current_method); |
| 3538 | } else { |
| 3539 | DCHECK(invoke->GetLocations()->Intrinsified()); |
| 3540 | DCHECK(!current_method.IsValid()); |
| 3541 | method_reg = reg; |
| 3542 | __ Ldr(reg.X(), MemOperand(sp, kCurrentMethodStackOffset)); |
| 3543 | } |
Vladimir Marko | b2c431e | 2015-08-19 12:45:42 +0000 | [diff] [blame] | 3544 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3545 | // /* ArtMethod*[] */ temp = temp.ptr_sized_fields_->dex_cache_resolved_methods_; |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 3546 | __ Ldr(reg.X(), |
| 3547 | MemOperand(method_reg.X(), |
| 3548 | ArtMethod::DexCacheResolvedMethodsOffset(kArm64WordSize).Int32Value())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3549 | // temp = temp[index_in_cache]; |
| 3550 | uint32_t index_in_cache = invoke->GetTargetMethod().dex_method_index; |
| 3551 | __ Ldr(reg.X(), MemOperand(reg.X(), GetCachePointerOffset(index_in_cache))); |
| 3552 | break; |
| 3553 | } |
| 3554 | } |
| 3555 | |
| 3556 | switch (invoke->GetCodePtrLocation()) { |
| 3557 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 3558 | __ Bl(&frame_entry_label_); |
| 3559 | break; |
| 3560 | case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative: { |
| 3561 | relative_call_patches_.emplace_back(invoke->GetTargetMethod()); |
| 3562 | vixl::Label* label = &relative_call_patches_.back().label; |
Alexandre Rames | 6dc0174 | 2015-11-12 14:44:19 +0000 | [diff] [blame] | 3563 | vixl::SingleEmissionCheckScope guard(GetVIXLAssembler()); |
| 3564 | __ Bind(label); |
| 3565 | __ bl(0); // Branch and link to itself. This will be overriden at link time. |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3566 | break; |
| 3567 | } |
| 3568 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 3569 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
| 3570 | // LR prepared above for better instruction scheduling. |
| 3571 | DCHECK(direct_code_loaded); |
| 3572 | // lr() |
| 3573 | __ Blr(lr); |
| 3574 | break; |
| 3575 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 3576 | // LR = callee_method->entry_point_from_quick_compiled_code_; |
| 3577 | __ Ldr(lr, MemOperand( |
Alexandre Rames | 6dc0174 | 2015-11-12 14:44:19 +0000 | [diff] [blame] | 3578 | XRegisterFrom(callee_method), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3579 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64WordSize).Int32Value())); |
| 3580 | // lr() |
| 3581 | __ Blr(lr); |
| 3582 | break; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 3583 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3584 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 3585 | DCHECK(!IsLeafMethod()); |
| 3586 | } |
| 3587 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 3588 | void CodeGeneratorARM64::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_in) { |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 3589 | // Use the calling convention instead of the location of the receiver, as |
| 3590 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 3591 | // slow path, the arguments have been moved to the right place, so here we are |
| 3592 | // guaranteed that the receiver is the first register of the calling convention. |
| 3593 | InvokeDexCallingConvention calling_convention; |
| 3594 | Register receiver = calling_convention.GetRegisterAt(0); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 3595 | Register temp = XRegisterFrom(temp_in); |
| 3596 | size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 3597 | invoke->GetVTableIndex(), kArm64PointerSize).SizeValue(); |
| 3598 | Offset class_offset = mirror::Object::ClassOffset(); |
| 3599 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64WordSize); |
| 3600 | |
| 3601 | BlockPoolsScope block_pools(GetVIXLAssembler()); |
| 3602 | |
| 3603 | DCHECK(receiver.IsRegister()); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3604 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 3605 | __ Ldr(temp.W(), HeapOperandFrom(LocationFrom(receiver), class_offset)); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 3606 | MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3607 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 3608 | // emit a read barrier for the previous class reference load. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3609 | // intermediate/temporary reference and because the current |
| 3610 | // concurrent copying collector keeps the from-space memory |
| 3611 | // intact/accessible until the end of the marking phase (the |
| 3612 | // concurrent copying collector may not in the future). |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 3613 | GetAssembler()->MaybeUnpoisonHeapReference(temp.W()); |
| 3614 | // temp = temp->GetMethodAt(method_offset); |
| 3615 | __ Ldr(temp, MemOperand(temp, method_offset)); |
| 3616 | // lr = temp->GetEntryPoint(); |
| 3617 | __ Ldr(lr, MemOperand(temp, entry_point.SizeValue())); |
| 3618 | // lr(); |
| 3619 | __ Blr(lr); |
| 3620 | } |
| 3621 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3622 | void CodeGeneratorARM64::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) { |
| 3623 | DCHECK(linker_patches->empty()); |
| 3624 | size_t size = |
| 3625 | method_patches_.size() + |
| 3626 | call_patches_.size() + |
| 3627 | relative_call_patches_.size() + |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 3628 | pc_relative_dex_cache_patches_.size(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3629 | linker_patches->reserve(size); |
| 3630 | for (const auto& entry : method_patches_) { |
| 3631 | const MethodReference& target_method = entry.first; |
| 3632 | vixl::Literal<uint64_t>* literal = entry.second; |
| 3633 | linker_patches->push_back(LinkerPatch::MethodPatch(literal->offset(), |
| 3634 | target_method.dex_file, |
| 3635 | target_method.dex_method_index)); |
| 3636 | } |
| 3637 | for (const auto& entry : call_patches_) { |
| 3638 | const MethodReference& target_method = entry.first; |
| 3639 | vixl::Literal<uint64_t>* literal = entry.second; |
| 3640 | linker_patches->push_back(LinkerPatch::CodePatch(literal->offset(), |
| 3641 | target_method.dex_file, |
| 3642 | target_method.dex_method_index)); |
| 3643 | } |
| 3644 | for (const MethodPatchInfo<vixl::Label>& info : relative_call_patches_) { |
Alexandre Rames | 6dc0174 | 2015-11-12 14:44:19 +0000 | [diff] [blame] | 3645 | linker_patches->push_back(LinkerPatch::RelativeCodePatch(info.label.location(), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3646 | info.target_method.dex_file, |
| 3647 | info.target_method.dex_method_index)); |
| 3648 | } |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 3649 | for (const PcRelativeDexCacheAccessInfo& info : pc_relative_dex_cache_patches_) { |
Alexandre Rames | 6dc0174 | 2015-11-12 14:44:19 +0000 | [diff] [blame] | 3650 | linker_patches->push_back(LinkerPatch::DexCacheArrayPatch(info.label.location(), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3651 | &info.target_dex_file, |
Alexandre Rames | 6dc0174 | 2015-11-12 14:44:19 +0000 | [diff] [blame] | 3652 | info.pc_insn_label->location(), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3653 | info.element_offset)); |
| 3654 | } |
| 3655 | } |
| 3656 | |
| 3657 | vixl::Literal<uint64_t>* CodeGeneratorARM64::DeduplicateUint64Literal(uint64_t value) { |
| 3658 | // Look up the literal for value. |
| 3659 | auto lb = uint64_literals_.lower_bound(value); |
| 3660 | if (lb != uint64_literals_.end() && !uint64_literals_.key_comp()(value, lb->first)) { |
| 3661 | return lb->second; |
| 3662 | } |
| 3663 | // We don't have a literal for this value, insert a new one. |
| 3664 | vixl::Literal<uint64_t>* literal = __ CreateLiteralDestroyedWithPool<uint64_t>(value); |
| 3665 | uint64_literals_.PutBefore(lb, value, literal); |
| 3666 | return literal; |
| 3667 | } |
| 3668 | |
| 3669 | vixl::Literal<uint64_t>* CodeGeneratorARM64::DeduplicateMethodLiteral( |
| 3670 | MethodReference target_method, |
| 3671 | MethodToLiteralMap* map) { |
| 3672 | // Look up the literal for target_method. |
| 3673 | auto lb = map->lower_bound(target_method); |
| 3674 | if (lb != map->end() && !map->key_comp()(target_method, lb->first)) { |
| 3675 | return lb->second; |
| 3676 | } |
| 3677 | // We don't have a literal for this method yet, insert a new one. |
| 3678 | vixl::Literal<uint64_t>* literal = __ CreateLiteralDestroyedWithPool<uint64_t>(0u); |
| 3679 | map->PutBefore(lb, target_method, literal); |
| 3680 | return literal; |
| 3681 | } |
| 3682 | |
| 3683 | vixl::Literal<uint64_t>* CodeGeneratorARM64::DeduplicateMethodAddressLiteral( |
| 3684 | MethodReference target_method) { |
| 3685 | return DeduplicateMethodLiteral(target_method, &method_patches_); |
| 3686 | } |
| 3687 | |
| 3688 | vixl::Literal<uint64_t>* CodeGeneratorARM64::DeduplicateMethodCodeLiteral( |
| 3689 | MethodReference target_method) { |
| 3690 | return DeduplicateMethodLiteral(target_method, &call_patches_); |
| 3691 | } |
| 3692 | |
| 3693 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 3694 | void InstructionCodeGeneratorARM64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 3695 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 3696 | // art::PrepareForRegisterAllocation. |
| 3697 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3698 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 3699 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 3700 | return; |
| 3701 | } |
| 3702 | |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 3703 | BlockPoolsScope block_pools(GetVIXLAssembler()); |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 3704 | LocationSummary* locations = invoke->GetLocations(); |
| 3705 | codegen_->GenerateStaticOrDirectCall( |
| 3706 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 3707 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3708 | } |
| 3709 | |
| 3710 | void InstructionCodeGeneratorARM64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 3711 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 3712 | return; |
| 3713 | } |
| 3714 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 3715 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3716 | DCHECK(!codegen_->IsLeafMethod()); |
| 3717 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 3718 | } |
| 3719 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3720 | void LocationsBuilderARM64::VisitLoadClass(HLoadClass* cls) { |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 3721 | InvokeRuntimeCallingConvention calling_convention; |
| 3722 | CodeGenerator::CreateLoadClassLocationSummary( |
| 3723 | cls, |
| 3724 | LocationFrom(calling_convention.GetRegisterAt(0)), |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3725 | LocationFrom(vixl::x0), |
| 3726 | /* code_generator_supports_read_barrier */ true); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3727 | } |
| 3728 | |
| 3729 | void InstructionCodeGeneratorARM64::VisitLoadClass(HLoadClass* cls) { |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 3730 | if (cls->NeedsAccessCheck()) { |
| 3731 | codegen_->MoveConstant(cls->GetLocations()->GetTemp(0), cls->GetTypeIndex()); |
| 3732 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pInitializeTypeAndVerifyAccess), |
| 3733 | cls, |
| 3734 | cls->GetDexPc(), |
| 3735 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3736 | CheckEntrypointTypes<kQuickInitializeTypeAndVerifyAccess, void*, uint32_t>(); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 3737 | return; |
| 3738 | } |
| 3739 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3740 | Location out_loc = cls->GetLocations()->Out(); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 3741 | Register out = OutputRegister(cls); |
| 3742 | Register current_method = InputRegisterAt(cls, 0); |
| 3743 | if (cls->IsReferrersClass()) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3744 | DCHECK(!cls->CanCallRuntime()); |
| 3745 | DCHECK(!cls->MustGenerateClinitCheck()); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3746 | uint32_t declaring_class_offset = ArtMethod::DeclaringClassOffset().Int32Value(); |
| 3747 | if (kEmitCompilerReadBarrier) { |
| 3748 | // /* GcRoot<mirror::Class>* */ out = &(current_method->declaring_class_) |
| 3749 | __ Add(out.X(), current_method.X(), declaring_class_offset); |
| 3750 | // /* mirror::Class* */ out = out->Read() |
| 3751 | codegen_->GenerateReadBarrierForRoot(cls, out_loc, out_loc); |
| 3752 | } else { |
| 3753 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 3754 | __ Ldr(out, MemOperand(current_method, declaring_class_offset)); |
| 3755 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3756 | } else { |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 3757 | MemberOffset resolved_types_offset = ArtMethod::DexCacheResolvedTypesOffset(kArm64PointerSize); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3758 | // /* GcRoot<mirror::Class>[] */ out = |
| 3759 | // current_method.ptr_sized_fields_->dex_cache_resolved_types_ |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 3760 | __ Ldr(out.X(), MemOperand(current_method, resolved_types_offset.Int32Value())); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3761 | |
| 3762 | size_t cache_offset = CodeGenerator::GetCacheOffset(cls->GetTypeIndex()); |
| 3763 | if (kEmitCompilerReadBarrier) { |
| 3764 | // /* GcRoot<mirror::Class>* */ out = &out[type_index] |
| 3765 | __ Add(out.X(), out.X(), cache_offset); |
| 3766 | // /* mirror::Class* */ out = out->Read() |
| 3767 | codegen_->GenerateReadBarrierForRoot(cls, out_loc, out_loc); |
| 3768 | } else { |
| 3769 | // /* GcRoot<mirror::Class> */ out = out[type_index] |
| 3770 | __ Ldr(out, MemOperand(out.X(), cache_offset)); |
| 3771 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3772 | |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 3773 | if (!cls->IsInDexCache() || cls->MustGenerateClinitCheck()) { |
| 3774 | DCHECK(cls->CanCallRuntime()); |
| 3775 | SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM64( |
| 3776 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 3777 | codegen_->AddSlowPath(slow_path); |
| 3778 | if (!cls->IsInDexCache()) { |
| 3779 | __ Cbz(out, slow_path->GetEntryLabel()); |
| 3780 | } |
| 3781 | if (cls->MustGenerateClinitCheck()) { |
| 3782 | GenerateClassInitializationCheck(slow_path, out); |
| 3783 | } else { |
| 3784 | __ Bind(slow_path->GetExitLabel()); |
| 3785 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3786 | } |
| 3787 | } |
| 3788 | } |
| 3789 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 3790 | static MemOperand GetExceptionTlsAddress() { |
| 3791 | return MemOperand(tr, Thread::ExceptionOffset<kArm64WordSize>().Int32Value()); |
| 3792 | } |
| 3793 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3794 | void LocationsBuilderARM64::VisitLoadException(HLoadException* load) { |
| 3795 | LocationSummary* locations = |
| 3796 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 3797 | locations->SetOut(Location::RequiresRegister()); |
| 3798 | } |
| 3799 | |
| 3800 | void InstructionCodeGeneratorARM64::VisitLoadException(HLoadException* instruction) { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 3801 | __ Ldr(OutputRegister(instruction), GetExceptionTlsAddress()); |
| 3802 | } |
| 3803 | |
| 3804 | void LocationsBuilderARM64::VisitClearException(HClearException* clear) { |
| 3805 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 3806 | } |
| 3807 | |
| 3808 | void InstructionCodeGeneratorARM64::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 3809 | __ Str(wzr, GetExceptionTlsAddress()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3810 | } |
| 3811 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3812 | void LocationsBuilderARM64::VisitLoadLocal(HLoadLocal* load) { |
| 3813 | load->SetLocations(nullptr); |
| 3814 | } |
| 3815 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3816 | void InstructionCodeGeneratorARM64::VisitLoadLocal(HLoadLocal* load ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3817 | // Nothing to do, this is driven by the code generator. |
| 3818 | } |
| 3819 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3820 | void LocationsBuilderARM64::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 3821 | LocationSummary::CallKind call_kind = (!load->IsInDexCache() || kEmitCompilerReadBarrier) |
| 3822 | ? LocationSummary::kCallOnSlowPath |
| 3823 | : LocationSummary::kNoCall; |
| 3824 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind); |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 3825 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3826 | locations->SetOut(Location::RequiresRegister()); |
| 3827 | } |
| 3828 | |
| 3829 | void InstructionCodeGeneratorARM64::VisitLoadString(HLoadString* load) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3830 | Location out_loc = load->GetLocations()->Out(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3831 | Register out = OutputRegister(load); |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 3832 | Register current_method = InputRegisterAt(load, 0); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3833 | |
| 3834 | uint32_t declaring_class_offset = ArtMethod::DeclaringClassOffset().Int32Value(); |
| 3835 | if (kEmitCompilerReadBarrier) { |
| 3836 | // /* GcRoot<mirror::Class>* */ out = &(current_method->declaring_class_) |
| 3837 | __ Add(out.X(), current_method.X(), declaring_class_offset); |
| 3838 | // /* mirror::Class* */ out = out->Read() |
| 3839 | codegen_->GenerateReadBarrierForRoot(load, out_loc, out_loc); |
| 3840 | } else { |
| 3841 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 3842 | __ Ldr(out, MemOperand(current_method, declaring_class_offset)); |
| 3843 | } |
| 3844 | |
| 3845 | // /* GcRoot<mirror::String>[] */ out = out->dex_cache_strings_ |
| 3846 | __ Ldr(out.X(), HeapOperand(out, mirror::Class::DexCacheStringsOffset().Uint32Value())); |
| 3847 | |
| 3848 | size_t cache_offset = CodeGenerator::GetCacheOffset(load->GetStringIndex()); |
| 3849 | if (kEmitCompilerReadBarrier) { |
| 3850 | // /* GcRoot<mirror::String>* */ out = &out[string_index] |
| 3851 | __ Add(out.X(), out.X(), cache_offset); |
| 3852 | // /* mirror::String* */ out = out->Read() |
| 3853 | codegen_->GenerateReadBarrierForRoot(load, out_loc, out_loc); |
| 3854 | } else { |
| 3855 | // /* GcRoot<mirror::String> */ out = out[string_index] |
| 3856 | __ Ldr(out, MemOperand(out.X(), cache_offset)); |
| 3857 | } |
| 3858 | |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 3859 | if (!load->IsInDexCache()) { |
| 3860 | SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathARM64(load); |
| 3861 | codegen_->AddSlowPath(slow_path); |
| 3862 | __ Cbz(out, slow_path->GetEntryLabel()); |
| 3863 | __ Bind(slow_path->GetExitLabel()); |
| 3864 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3865 | } |
| 3866 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3867 | void LocationsBuilderARM64::VisitLocal(HLocal* local) { |
| 3868 | local->SetLocations(nullptr); |
| 3869 | } |
| 3870 | |
| 3871 | void InstructionCodeGeneratorARM64::VisitLocal(HLocal* local) { |
| 3872 | DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock()); |
| 3873 | } |
| 3874 | |
| 3875 | void LocationsBuilderARM64::VisitLongConstant(HLongConstant* constant) { |
| 3876 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant); |
| 3877 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3878 | } |
| 3879 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3880 | void InstructionCodeGeneratorARM64::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3881 | // Will be generated at use site. |
| 3882 | } |
| 3883 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3884 | void LocationsBuilderARM64::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 3885 | LocationSummary* locations = |
| 3886 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 3887 | InvokeRuntimeCallingConvention calling_convention; |
| 3888 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 3889 | } |
| 3890 | |
| 3891 | void InstructionCodeGeneratorARM64::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 3892 | codegen_->InvokeRuntime(instruction->IsEnter() |
| 3893 | ? QUICK_ENTRY_POINT(pLockObject) : QUICK_ENTRY_POINT(pUnlockObject), |
| 3894 | instruction, |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 3895 | instruction->GetDexPc(), |
| 3896 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3897 | if (instruction->IsEnter()) { |
| 3898 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 3899 | } else { |
| 3900 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 3901 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3902 | } |
| 3903 | |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 3904 | void LocationsBuilderARM64::VisitMul(HMul* mul) { |
| 3905 | LocationSummary* locations = |
| 3906 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 3907 | switch (mul->GetResultType()) { |
| 3908 | case Primitive::kPrimInt: |
| 3909 | case Primitive::kPrimLong: |
| 3910 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3911 | locations->SetInAt(1, Location::RequiresRegister()); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 3912 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 3913 | break; |
| 3914 | |
| 3915 | case Primitive::kPrimFloat: |
| 3916 | case Primitive::kPrimDouble: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3917 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3918 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3919 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 3920 | break; |
| 3921 | |
| 3922 | default: |
| 3923 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 3924 | } |
| 3925 | } |
| 3926 | |
| 3927 | void InstructionCodeGeneratorARM64::VisitMul(HMul* mul) { |
| 3928 | switch (mul->GetResultType()) { |
| 3929 | case Primitive::kPrimInt: |
| 3930 | case Primitive::kPrimLong: |
| 3931 | __ Mul(OutputRegister(mul), InputRegisterAt(mul, 0), InputRegisterAt(mul, 1)); |
| 3932 | break; |
| 3933 | |
| 3934 | case Primitive::kPrimFloat: |
| 3935 | case Primitive::kPrimDouble: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3936 | __ Fmul(OutputFPRegister(mul), InputFPRegisterAt(mul, 0), InputFPRegisterAt(mul, 1)); |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 3937 | break; |
| 3938 | |
| 3939 | default: |
| 3940 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 3941 | } |
| 3942 | } |
| 3943 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3944 | void LocationsBuilderARM64::VisitNeg(HNeg* neg) { |
| 3945 | LocationSummary* locations = |
| 3946 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 3947 | switch (neg->GetResultType()) { |
| 3948 | case Primitive::kPrimInt: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3949 | case Primitive::kPrimLong: |
Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 3950 | locations->SetInAt(0, ARM64EncodableConstantOrRegister(neg->InputAt(0), neg)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3951 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3952 | break; |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3953 | |
| 3954 | case Primitive::kPrimFloat: |
| 3955 | case Primitive::kPrimDouble: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3956 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3957 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3958 | break; |
| 3959 | |
| 3960 | default: |
| 3961 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 3962 | } |
| 3963 | } |
| 3964 | |
| 3965 | void InstructionCodeGeneratorARM64::VisitNeg(HNeg* neg) { |
| 3966 | switch (neg->GetResultType()) { |
| 3967 | case Primitive::kPrimInt: |
| 3968 | case Primitive::kPrimLong: |
| 3969 | __ Neg(OutputRegister(neg), InputOperandAt(neg, 0)); |
| 3970 | break; |
| 3971 | |
| 3972 | case Primitive::kPrimFloat: |
| 3973 | case Primitive::kPrimDouble: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3974 | __ Fneg(OutputFPRegister(neg), InputFPRegisterAt(neg, 0)); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3975 | break; |
| 3976 | |
| 3977 | default: |
| 3978 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 3979 | } |
| 3980 | } |
| 3981 | |
| 3982 | void LocationsBuilderARM64::VisitNewArray(HNewArray* instruction) { |
| 3983 | LocationSummary* locations = |
| 3984 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 3985 | InvokeRuntimeCallingConvention calling_convention; |
| 3986 | locations->AddTemp(LocationFrom(calling_convention.GetRegisterAt(0))); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3987 | locations->SetOut(LocationFrom(x0)); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 3988 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3989 | locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(2))); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3990 | } |
| 3991 | |
| 3992 | void InstructionCodeGeneratorARM64::VisitNewArray(HNewArray* instruction) { |
| 3993 | LocationSummary* locations = instruction->GetLocations(); |
| 3994 | InvokeRuntimeCallingConvention calling_convention; |
| 3995 | Register type_index = RegisterFrom(locations->GetTemp(0), Primitive::kPrimInt); |
| 3996 | DCHECK(type_index.Is(w0)); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3997 | __ Mov(type_index, instruction->GetTypeIndex()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3998 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 3999 | // of poisoning the reference. |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4000 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), |
| 4001 | instruction, |
| 4002 | instruction->GetDexPc(), |
| 4003 | nullptr); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4004 | CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck, void*, uint32_t, int32_t, ArtMethod*>(); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 4005 | } |
| 4006 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4007 | void LocationsBuilderARM64::VisitNewInstance(HNewInstance* instruction) { |
| 4008 | LocationSummary* locations = |
| 4009 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 4010 | InvokeRuntimeCallingConvention calling_convention; |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4011 | if (instruction->IsStringAlloc()) { |
| 4012 | locations->AddTemp(LocationFrom(kArtMethodRegister)); |
| 4013 | } else { |
| 4014 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 4015 | locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(1))); |
| 4016 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4017 | locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimNot)); |
| 4018 | } |
| 4019 | |
| 4020 | void InstructionCodeGeneratorARM64::VisitNewInstance(HNewInstance* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4021 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 4022 | // of poisoning the reference. |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4023 | if (instruction->IsStringAlloc()) { |
| 4024 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 4025 | Location temp = instruction->GetLocations()->GetTemp(0); |
| 4026 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64WordSize); |
| 4027 | __ Ldr(XRegisterFrom(temp), MemOperand(tr, QUICK_ENTRY_POINT(pNewEmptyString))); |
| 4028 | __ Ldr(lr, MemOperand(XRegisterFrom(temp), code_offset.Int32Value())); |
| 4029 | __ Blr(lr); |
| 4030 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 4031 | } else { |
| 4032 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), |
| 4033 | instruction, |
| 4034 | instruction->GetDexPc(), |
| 4035 | nullptr); |
| 4036 | CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, ArtMethod*>(); |
| 4037 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4038 | } |
| 4039 | |
| 4040 | void LocationsBuilderARM64::VisitNot(HNot* instruction) { |
| 4041 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Alexandre Rames | 4e59651 | 2014-11-07 15:56:50 +0000 | [diff] [blame] | 4042 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 4043 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4044 | } |
| 4045 | |
| 4046 | void InstructionCodeGeneratorARM64::VisitNot(HNot* instruction) { |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 4047 | switch (instruction->GetResultType()) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4048 | case Primitive::kPrimInt: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4049 | case Primitive::kPrimLong: |
Roland Levillain | 55dcfb5 | 2014-10-24 18:09:09 +0100 | [diff] [blame] | 4050 | __ Mvn(OutputRegister(instruction), InputOperandAt(instruction, 0)); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4051 | break; |
| 4052 | |
| 4053 | default: |
| 4054 | LOG(FATAL) << "Unexpected type for not operation " << instruction->GetResultType(); |
| 4055 | } |
| 4056 | } |
| 4057 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4058 | void LocationsBuilderARM64::VisitBooleanNot(HBooleanNot* instruction) { |
| 4059 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 4060 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4061 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4062 | } |
| 4063 | |
| 4064 | void InstructionCodeGeneratorARM64::VisitBooleanNot(HBooleanNot* instruction) { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4065 | __ Eor(OutputRegister(instruction), InputRegisterAt(instruction, 0), vixl::Operand(1)); |
| 4066 | } |
| 4067 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4068 | void LocationsBuilderARM64::VisitNullCheck(HNullCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4069 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 4070 | ? LocationSummary::kCallOnSlowPath |
| 4071 | : LocationSummary::kNoCall; |
| 4072 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4073 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4074 | if (instruction->HasUses()) { |
| 4075 | locations->SetOut(Location::SameAsFirstInput()); |
| 4076 | } |
| 4077 | } |
| 4078 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4079 | void InstructionCodeGeneratorARM64::GenerateImplicitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4080 | if (codegen_->CanMoveNullCheckToUser(instruction)) { |
| 4081 | return; |
| 4082 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4083 | |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 4084 | BlockPoolsScope block_pools(GetVIXLAssembler()); |
| 4085 | Location obj = instruction->GetLocations()->InAt(0); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4086 | __ Ldr(wzr, HeapOperandFrom(obj, Offset(0))); |
| 4087 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 4088 | } |
| 4089 | |
| 4090 | void InstructionCodeGeneratorARM64::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4091 | SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM64(instruction); |
| 4092 | codegen_->AddSlowPath(slow_path); |
| 4093 | |
| 4094 | LocationSummary* locations = instruction->GetLocations(); |
| 4095 | Location obj = locations->InAt(0); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4096 | |
| 4097 | __ Cbz(RegisterFrom(obj, instruction->InputAt(0)->GetType()), slow_path->GetEntryLabel()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4098 | } |
| 4099 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4100 | void InstructionCodeGeneratorARM64::VisitNullCheck(HNullCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4101 | if (codegen_->IsImplicitNullCheckAllowed(instruction)) { |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4102 | GenerateImplicitNullCheck(instruction); |
| 4103 | } else { |
| 4104 | GenerateExplicitNullCheck(instruction); |
| 4105 | } |
| 4106 | } |
| 4107 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4108 | void LocationsBuilderARM64::VisitOr(HOr* instruction) { |
| 4109 | HandleBinaryOp(instruction); |
| 4110 | } |
| 4111 | |
| 4112 | void InstructionCodeGeneratorARM64::VisitOr(HOr* instruction) { |
| 4113 | HandleBinaryOp(instruction); |
| 4114 | } |
| 4115 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 4116 | void LocationsBuilderARM64::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
| 4117 | LOG(FATAL) << "Unreachable"; |
| 4118 | } |
| 4119 | |
| 4120 | void InstructionCodeGeneratorARM64::VisitParallelMove(HParallelMove* instruction) { |
| 4121 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 4122 | } |
| 4123 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4124 | void LocationsBuilderARM64::VisitParameterValue(HParameterValue* instruction) { |
| 4125 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 4126 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 4127 | if (location.IsStackSlot()) { |
| 4128 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 4129 | } else if (location.IsDoubleStackSlot()) { |
| 4130 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 4131 | } |
| 4132 | locations->SetOut(location); |
| 4133 | } |
| 4134 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4135 | void InstructionCodeGeneratorARM64::VisitParameterValue( |
| 4136 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4137 | // Nothing to do, the parameter is already at its location. |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4138 | } |
| 4139 | |
| 4140 | void LocationsBuilderARM64::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 4141 | LocationSummary* locations = |
| 4142 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 4143 | locations->SetOut(LocationFrom(kArtMethodRegister)); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4144 | } |
| 4145 | |
| 4146 | void InstructionCodeGeneratorARM64::VisitCurrentMethod( |
| 4147 | HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
| 4148 | // Nothing to do, the method is already at its location. |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4149 | } |
| 4150 | |
| 4151 | void LocationsBuilderARM64::VisitPhi(HPhi* instruction) { |
| 4152 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 4153 | for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) { |
| 4154 | locations->SetInAt(i, Location::Any()); |
| 4155 | } |
| 4156 | locations->SetOut(Location::Any()); |
| 4157 | } |
| 4158 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4159 | void InstructionCodeGeneratorARM64::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4160 | LOG(FATAL) << "Unreachable"; |
| 4161 | } |
| 4162 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4163 | void LocationsBuilderARM64::VisitRem(HRem* rem) { |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 4164 | Primitive::Type type = rem->GetResultType(); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 4165 | LocationSummary::CallKind call_kind = |
| 4166 | Primitive::IsFloatingPointType(type) ? LocationSummary::kCall : LocationSummary::kNoCall; |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 4167 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind); |
| 4168 | |
| 4169 | switch (type) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4170 | case Primitive::kPrimInt: |
| 4171 | case Primitive::kPrimLong: |
| 4172 | locations->SetInAt(0, Location::RequiresRegister()); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 4173 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4174 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4175 | break; |
| 4176 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 4177 | case Primitive::kPrimFloat: |
| 4178 | case Primitive::kPrimDouble: { |
| 4179 | InvokeRuntimeCallingConvention calling_convention; |
| 4180 | locations->SetInAt(0, LocationFrom(calling_convention.GetFpuRegisterAt(0))); |
| 4181 | locations->SetInAt(1, LocationFrom(calling_convention.GetFpuRegisterAt(1))); |
| 4182 | locations->SetOut(calling_convention.GetReturnLocation(type)); |
| 4183 | |
| 4184 | break; |
| 4185 | } |
| 4186 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4187 | default: |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 4188 | LOG(FATAL) << "Unexpected rem type " << type; |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4189 | } |
| 4190 | } |
| 4191 | |
| 4192 | void InstructionCodeGeneratorARM64::VisitRem(HRem* rem) { |
| 4193 | Primitive::Type type = rem->GetResultType(); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 4194 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4195 | switch (type) { |
| 4196 | case Primitive::kPrimInt: |
| 4197 | case Primitive::kPrimLong: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 4198 | GenerateDivRemIntegral(rem); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4199 | break; |
| 4200 | } |
| 4201 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 4202 | case Primitive::kPrimFloat: |
| 4203 | case Primitive::kPrimDouble: { |
| 4204 | int32_t entry_offset = (type == Primitive::kPrimFloat) ? QUICK_ENTRY_POINT(pFmodf) |
| 4205 | : QUICK_ENTRY_POINT(pFmod); |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 4206 | codegen_->InvokeRuntime(entry_offset, rem, rem->GetDexPc(), nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 4207 | if (type == Primitive::kPrimFloat) { |
| 4208 | CheckEntrypointTypes<kQuickFmodf, float, float, float>(); |
| 4209 | } else { |
| 4210 | CheckEntrypointTypes<kQuickFmod, double, double, double>(); |
| 4211 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 4212 | break; |
| 4213 | } |
| 4214 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4215 | default: |
| 4216 | LOG(FATAL) << "Unexpected rem type " << type; |
Vladimir Marko | 351dddf | 2015-12-11 16:34:46 +0000 | [diff] [blame] | 4217 | UNREACHABLE(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4218 | } |
| 4219 | } |
| 4220 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 4221 | void LocationsBuilderARM64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 4222 | memory_barrier->SetLocations(nullptr); |
| 4223 | } |
| 4224 | |
| 4225 | void InstructionCodeGeneratorARM64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 4226 | GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
| 4227 | } |
| 4228 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4229 | void LocationsBuilderARM64::VisitReturn(HReturn* instruction) { |
| 4230 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 4231 | Primitive::Type return_type = instruction->InputAt(0)->GetType(); |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 4232 | locations->SetInAt(0, ARM64ReturnLocation(return_type)); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4233 | } |
| 4234 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4235 | void InstructionCodeGeneratorARM64::VisitReturn(HReturn* instruction ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4236 | codegen_->GenerateFrameExit(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4237 | } |
| 4238 | |
| 4239 | void LocationsBuilderARM64::VisitReturnVoid(HReturnVoid* instruction) { |
| 4240 | instruction->SetLocations(nullptr); |
| 4241 | } |
| 4242 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4243 | void InstructionCodeGeneratorARM64::VisitReturnVoid(HReturnVoid* instruction ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4244 | codegen_->GenerateFrameExit(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4245 | } |
| 4246 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4247 | void LocationsBuilderARM64::VisitRor(HRor* ror) { |
| 4248 | HandleBinaryOp(ror); |
| 4249 | } |
| 4250 | |
| 4251 | void InstructionCodeGeneratorARM64::VisitRor(HRor* ror) { |
| 4252 | HandleBinaryOp(ror); |
| 4253 | } |
| 4254 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4255 | void LocationsBuilderARM64::VisitShl(HShl* shl) { |
| 4256 | HandleShift(shl); |
| 4257 | } |
| 4258 | |
| 4259 | void InstructionCodeGeneratorARM64::VisitShl(HShl* shl) { |
| 4260 | HandleShift(shl); |
| 4261 | } |
| 4262 | |
| 4263 | void LocationsBuilderARM64::VisitShr(HShr* shr) { |
| 4264 | HandleShift(shr); |
| 4265 | } |
| 4266 | |
| 4267 | void InstructionCodeGeneratorARM64::VisitShr(HShr* shr) { |
| 4268 | HandleShift(shr); |
| 4269 | } |
| 4270 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4271 | void LocationsBuilderARM64::VisitStoreLocal(HStoreLocal* store) { |
| 4272 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(store); |
| 4273 | Primitive::Type field_type = store->InputAt(1)->GetType(); |
| 4274 | switch (field_type) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 4275 | case Primitive::kPrimNot: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4276 | case Primitive::kPrimBoolean: |
| 4277 | case Primitive::kPrimByte: |
| 4278 | case Primitive::kPrimChar: |
| 4279 | case Primitive::kPrimShort: |
| 4280 | case Primitive::kPrimInt: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 4281 | case Primitive::kPrimFloat: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4282 | locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 4283 | break; |
| 4284 | |
| 4285 | case Primitive::kPrimLong: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 4286 | case Primitive::kPrimDouble: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4287 | locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 4288 | break; |
| 4289 | |
| 4290 | default: |
| 4291 | LOG(FATAL) << "Unimplemented local type " << field_type; |
Vladimir Marko | 351dddf | 2015-12-11 16:34:46 +0000 | [diff] [blame] | 4292 | UNREACHABLE(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4293 | } |
| 4294 | } |
| 4295 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4296 | void InstructionCodeGeneratorARM64::VisitStoreLocal(HStoreLocal* store ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4297 | } |
| 4298 | |
| 4299 | void LocationsBuilderARM64::VisitSub(HSub* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4300 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4301 | } |
| 4302 | |
| 4303 | void InstructionCodeGeneratorARM64::VisitSub(HSub* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4304 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4305 | } |
| 4306 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4307 | void LocationsBuilderARM64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 4308 | HandleFieldGet(instruction); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4309 | } |
| 4310 | |
| 4311 | void InstructionCodeGeneratorARM64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 4312 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4313 | } |
| 4314 | |
| 4315 | void LocationsBuilderARM64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 4316 | HandleFieldSet(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4317 | } |
| 4318 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4319 | void InstructionCodeGeneratorARM64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4320 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4321 | } |
| 4322 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 4323 | void LocationsBuilderARM64::VisitUnresolvedInstanceFieldGet( |
| 4324 | HUnresolvedInstanceFieldGet* instruction) { |
| 4325 | FieldAccessCallingConventionARM64 calling_convention; |
| 4326 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4327 | instruction, instruction->GetFieldType(), calling_convention); |
| 4328 | } |
| 4329 | |
| 4330 | void InstructionCodeGeneratorARM64::VisitUnresolvedInstanceFieldGet( |
| 4331 | HUnresolvedInstanceFieldGet* instruction) { |
| 4332 | FieldAccessCallingConventionARM64 calling_convention; |
| 4333 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4334 | instruction->GetFieldType(), |
| 4335 | instruction->GetFieldIndex(), |
| 4336 | instruction->GetDexPc(), |
| 4337 | calling_convention); |
| 4338 | } |
| 4339 | |
| 4340 | void LocationsBuilderARM64::VisitUnresolvedInstanceFieldSet( |
| 4341 | HUnresolvedInstanceFieldSet* instruction) { |
| 4342 | FieldAccessCallingConventionARM64 calling_convention; |
| 4343 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4344 | instruction, instruction->GetFieldType(), calling_convention); |
| 4345 | } |
| 4346 | |
| 4347 | void InstructionCodeGeneratorARM64::VisitUnresolvedInstanceFieldSet( |
| 4348 | HUnresolvedInstanceFieldSet* instruction) { |
| 4349 | FieldAccessCallingConventionARM64 calling_convention; |
| 4350 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4351 | instruction->GetFieldType(), |
| 4352 | instruction->GetFieldIndex(), |
| 4353 | instruction->GetDexPc(), |
| 4354 | calling_convention); |
| 4355 | } |
| 4356 | |
| 4357 | void LocationsBuilderARM64::VisitUnresolvedStaticFieldGet( |
| 4358 | HUnresolvedStaticFieldGet* instruction) { |
| 4359 | FieldAccessCallingConventionARM64 calling_convention; |
| 4360 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4361 | instruction, instruction->GetFieldType(), calling_convention); |
| 4362 | } |
| 4363 | |
| 4364 | void InstructionCodeGeneratorARM64::VisitUnresolvedStaticFieldGet( |
| 4365 | HUnresolvedStaticFieldGet* instruction) { |
| 4366 | FieldAccessCallingConventionARM64 calling_convention; |
| 4367 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4368 | instruction->GetFieldType(), |
| 4369 | instruction->GetFieldIndex(), |
| 4370 | instruction->GetDexPc(), |
| 4371 | calling_convention); |
| 4372 | } |
| 4373 | |
| 4374 | void LocationsBuilderARM64::VisitUnresolvedStaticFieldSet( |
| 4375 | HUnresolvedStaticFieldSet* instruction) { |
| 4376 | FieldAccessCallingConventionARM64 calling_convention; |
| 4377 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4378 | instruction, instruction->GetFieldType(), calling_convention); |
| 4379 | } |
| 4380 | |
| 4381 | void InstructionCodeGeneratorARM64::VisitUnresolvedStaticFieldSet( |
| 4382 | HUnresolvedStaticFieldSet* instruction) { |
| 4383 | FieldAccessCallingConventionARM64 calling_convention; |
| 4384 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4385 | instruction->GetFieldType(), |
| 4386 | instruction->GetFieldIndex(), |
| 4387 | instruction->GetDexPc(), |
| 4388 | calling_convention); |
| 4389 | } |
| 4390 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4391 | void LocationsBuilderARM64::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 4392 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
| 4393 | } |
| 4394 | |
| 4395 | void InstructionCodeGeneratorARM64::VisitSuspendCheck(HSuspendCheck* instruction) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4396 | HBasicBlock* block = instruction->GetBlock(); |
| 4397 | if (block->GetLoopInformation() != nullptr) { |
| 4398 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 4399 | // The back edge will generate the suspend check. |
| 4400 | return; |
| 4401 | } |
| 4402 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 4403 | // The goto will generate the suspend check. |
| 4404 | return; |
| 4405 | } |
| 4406 | GenerateSuspendCheck(instruction, nullptr); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4407 | } |
| 4408 | |
| 4409 | void LocationsBuilderARM64::VisitTemporary(HTemporary* temp) { |
| 4410 | temp->SetLocations(nullptr); |
| 4411 | } |
| 4412 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4413 | void InstructionCodeGeneratorARM64::VisitTemporary(HTemporary* temp ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4414 | // Nothing to do, this is driven by the code generator. |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4415 | } |
| 4416 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4417 | void LocationsBuilderARM64::VisitThrow(HThrow* instruction) { |
| 4418 | LocationSummary* locations = |
| 4419 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 4420 | InvokeRuntimeCallingConvention calling_convention; |
| 4421 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 4422 | } |
| 4423 | |
| 4424 | void InstructionCodeGeneratorARM64::VisitThrow(HThrow* instruction) { |
| 4425 | codegen_->InvokeRuntime( |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 4426 | QUICK_ENTRY_POINT(pDeliverException), instruction, instruction->GetDexPc(), nullptr); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 4427 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4428 | } |
| 4429 | |
| 4430 | void LocationsBuilderARM64::VisitTypeConversion(HTypeConversion* conversion) { |
| 4431 | LocationSummary* locations = |
| 4432 | new (GetGraph()->GetArena()) LocationSummary(conversion, LocationSummary::kNoCall); |
| 4433 | Primitive::Type input_type = conversion->GetInputType(); |
| 4434 | Primitive::Type result_type = conversion->GetResultType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 4435 | DCHECK_NE(input_type, result_type); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4436 | if ((input_type == Primitive::kPrimNot) || (input_type == Primitive::kPrimVoid) || |
| 4437 | (result_type == Primitive::kPrimNot) || (result_type == Primitive::kPrimVoid)) { |
| 4438 | LOG(FATAL) << "Unexpected type conversion from " << input_type << " to " << result_type; |
| 4439 | } |
| 4440 | |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 4441 | if (Primitive::IsFloatingPointType(input_type)) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4442 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4443 | } else { |
| 4444 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4445 | } |
| 4446 | |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 4447 | if (Primitive::IsFloatingPointType(result_type)) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4448 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4449 | } else { |
| 4450 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4451 | } |
| 4452 | } |
| 4453 | |
| 4454 | void InstructionCodeGeneratorARM64::VisitTypeConversion(HTypeConversion* conversion) { |
| 4455 | Primitive::Type result_type = conversion->GetResultType(); |
| 4456 | Primitive::Type input_type = conversion->GetInputType(); |
| 4457 | |
| 4458 | DCHECK_NE(input_type, result_type); |
| 4459 | |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 4460 | if (Primitive::IsIntegralType(result_type) && Primitive::IsIntegralType(input_type)) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4461 | int result_size = Primitive::ComponentSize(result_type); |
| 4462 | int input_size = Primitive::ComponentSize(input_type); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 4463 | int min_size = std::min(result_size, input_size); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4464 | Register output = OutputRegister(conversion); |
| 4465 | Register source = InputRegisterAt(conversion, 0); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 4466 | if (result_type == Primitive::kPrimInt && input_type == Primitive::kPrimLong) { |
Alexandre Rames | 4dff2fd | 2015-08-20 13:36:35 +0100 | [diff] [blame] | 4467 | // 'int' values are used directly as W registers, discarding the top |
| 4468 | // bits, so we don't need to sign-extend and can just perform a move. |
| 4469 | // We do not pass the `kDiscardForSameWReg` argument to force clearing the |
| 4470 | // top 32 bits of the target register. We theoretically could leave those |
| 4471 | // bits unchanged, but we would have to make sure that no code uses a |
| 4472 | // 32bit input value as a 64bit value assuming that the top 32 bits are |
| 4473 | // zero. |
| 4474 | __ Mov(output.W(), source.W()); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 4475 | } else if (result_type == Primitive::kPrimChar || |
| 4476 | (input_type == Primitive::kPrimChar && input_size < result_size)) { |
| 4477 | __ Ubfx(output, |
| 4478 | output.IsX() ? source.X() : source.W(), |
| 4479 | 0, Primitive::ComponentSize(Primitive::kPrimChar) * kBitsPerByte); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4480 | } else { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 4481 | __ Sbfx(output, output.IsX() ? source.X() : source.W(), 0, min_size * kBitsPerByte); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4482 | } |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 4483 | } else if (Primitive::IsFloatingPointType(result_type) && Primitive::IsIntegralType(input_type)) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4484 | __ Scvtf(OutputFPRegister(conversion), InputRegisterAt(conversion, 0)); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 4485 | } else if (Primitive::IsIntegralType(result_type) && Primitive::IsFloatingPointType(input_type)) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4486 | CHECK(result_type == Primitive::kPrimInt || result_type == Primitive::kPrimLong); |
| 4487 | __ Fcvtzs(OutputRegister(conversion), InputFPRegisterAt(conversion, 0)); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 4488 | } else if (Primitive::IsFloatingPointType(result_type) && |
| 4489 | Primitive::IsFloatingPointType(input_type)) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4490 | __ Fcvt(OutputFPRegister(conversion), InputFPRegisterAt(conversion, 0)); |
| 4491 | } else { |
| 4492 | LOG(FATAL) << "Unexpected or unimplemented type conversion from " << input_type |
| 4493 | << " to " << result_type; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4494 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4495 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4496 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4497 | void LocationsBuilderARM64::VisitUShr(HUShr* ushr) { |
| 4498 | HandleShift(ushr); |
| 4499 | } |
| 4500 | |
| 4501 | void InstructionCodeGeneratorARM64::VisitUShr(HUShr* ushr) { |
| 4502 | HandleShift(ushr); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4503 | } |
| 4504 | |
| 4505 | void LocationsBuilderARM64::VisitXor(HXor* instruction) { |
| 4506 | HandleBinaryOp(instruction); |
| 4507 | } |
| 4508 | |
| 4509 | void InstructionCodeGeneratorARM64::VisitXor(HXor* instruction) { |
| 4510 | HandleBinaryOp(instruction); |
| 4511 | } |
| 4512 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4513 | void LocationsBuilderARM64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 4514 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 4515 | LOG(FATAL) << "Unreachable"; |
| 4516 | } |
| 4517 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4518 | void InstructionCodeGeneratorARM64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 4519 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 4520 | LOG(FATAL) << "Unreachable"; |
| 4521 | } |
| 4522 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 4523 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 4524 | void LocationsBuilderARM64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 4525 | LocationSummary* locations = |
| 4526 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 4527 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4528 | } |
| 4529 | |
| 4530 | void InstructionCodeGeneratorARM64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 4531 | int32_t lower_bound = switch_instr->GetStartValue(); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 4532 | uint32_t num_entries = switch_instr->GetNumEntries(); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 4533 | Register value_reg = InputRegisterAt(switch_instr, 0); |
| 4534 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 4535 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 4536 | // Roughly set 16 as max average assemblies generated per HIR in a graph. |
| 4537 | static constexpr int32_t kMaxExpectedSizePerHInstruction = 16 * vixl::kInstructionSize; |
| 4538 | // ADR has a limited range(+/-1MB), so we set a threshold for the number of HIRs in the graph to |
| 4539 | // make sure we don't emit it if the target may run out of range. |
| 4540 | // TODO: Instead of emitting all jump tables at the end of the code, we could keep track of ADR |
| 4541 | // ranges and emit the tables only as required. |
| 4542 | static constexpr int32_t kJumpTableInstructionThreshold = 1* MB / kMaxExpectedSizePerHInstruction; |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 4543 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 4544 | if (num_entries <= kPackedSwitchCompareJumpThreshold || |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 4545 | // Current instruction id is an upper bound of the number of HIRs in the graph. |
| 4546 | GetGraph()->GetCurrentInstructionId() > kJumpTableInstructionThreshold) { |
| 4547 | // Create a series of compare/jumps. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 4548 | UseScratchRegisterScope temps(codegen_->GetVIXLAssembler()); |
| 4549 | Register temp = temps.AcquireW(); |
| 4550 | __ Subs(temp, value_reg, Operand(lower_bound)); |
| 4551 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 4552 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 4553 | // Jump to successors[0] if value == lower_bound. |
| 4554 | __ B(eq, codegen_->GetLabelOf(successors[0])); |
| 4555 | int32_t last_index = 0; |
| 4556 | for (; num_entries - last_index > 2; last_index += 2) { |
| 4557 | __ Subs(temp, temp, Operand(2)); |
| 4558 | // Jump to successors[last_index + 1] if value < case_value[last_index + 2]. |
| 4559 | __ B(lo, codegen_->GetLabelOf(successors[last_index + 1])); |
| 4560 | // Jump to successors[last_index + 2] if value == case_value[last_index + 2]. |
| 4561 | __ B(eq, codegen_->GetLabelOf(successors[last_index + 2])); |
| 4562 | } |
| 4563 | if (num_entries - last_index == 2) { |
| 4564 | // The last missing case_value. |
| 4565 | __ Cmp(temp, Operand(1)); |
| 4566 | __ B(eq, codegen_->GetLabelOf(successors[last_index + 1])); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 4567 | } |
| 4568 | |
| 4569 | // And the default for any other value. |
| 4570 | if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) { |
| 4571 | __ B(codegen_->GetLabelOf(default_block)); |
| 4572 | } |
| 4573 | } else { |
| 4574 | JumpTableARM64* jump_table = new (GetGraph()->GetArena()) JumpTableARM64(switch_instr); |
| 4575 | codegen_->AddJumpTable(jump_table); |
| 4576 | |
| 4577 | UseScratchRegisterScope temps(codegen_->GetVIXLAssembler()); |
| 4578 | |
| 4579 | // Below instructions should use at most one blocked register. Since there are two blocked |
| 4580 | // registers, we are free to block one. |
| 4581 | Register temp_w = temps.AcquireW(); |
| 4582 | Register index; |
| 4583 | // Remove the bias. |
| 4584 | if (lower_bound != 0) { |
| 4585 | index = temp_w; |
| 4586 | __ Sub(index, value_reg, Operand(lower_bound)); |
| 4587 | } else { |
| 4588 | index = value_reg; |
| 4589 | } |
| 4590 | |
| 4591 | // Jump to default block if index is out of the range. |
| 4592 | __ Cmp(index, Operand(num_entries)); |
| 4593 | __ B(hs, codegen_->GetLabelOf(default_block)); |
| 4594 | |
| 4595 | // In current VIXL implementation, it won't require any blocked registers to encode the |
| 4596 | // immediate value for Adr. So we are free to use both VIXL blocked registers to reduce the |
| 4597 | // register pressure. |
| 4598 | Register table_base = temps.AcquireX(); |
| 4599 | // Load jump offset from the table. |
| 4600 | __ Adr(table_base, jump_table->GetTableStartLabel()); |
| 4601 | Register jump_offset = temp_w; |
| 4602 | __ Ldr(jump_offset, MemOperand(table_base, index, UXTW, 2)); |
| 4603 | |
| 4604 | // Jump to target block by branching to table_base(pc related) + offset. |
| 4605 | Register target_address = table_base; |
| 4606 | __ Add(target_address, table_base, Operand(jump_offset, SXTW)); |
| 4607 | __ Br(target_address); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 4608 | } |
| 4609 | } |
| 4610 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4611 | void CodeGeneratorARM64::GenerateReadBarrier(HInstruction* instruction, |
| 4612 | Location out, |
| 4613 | Location ref, |
| 4614 | Location obj, |
| 4615 | uint32_t offset, |
| 4616 | Location index) { |
| 4617 | DCHECK(kEmitCompilerReadBarrier); |
| 4618 | |
| 4619 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 4620 | // reference will be carried out by the runtime within the slow |
| 4621 | // path. |
| 4622 | // |
| 4623 | // Note that `ref` currently does not get unpoisoned (when heap |
| 4624 | // poisoning is enabled), which is alright as the `ref` argument is |
| 4625 | // not used by the artReadBarrierSlow entry point. |
| 4626 | // |
| 4627 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
| 4628 | SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) |
| 4629 | ReadBarrierForHeapReferenceSlowPathARM64(instruction, out, ref, obj, offset, index); |
| 4630 | AddSlowPath(slow_path); |
| 4631 | |
| 4632 | // TODO: When read barrier has a fast path, add it here. |
| 4633 | /* Currently the read barrier call is inserted after the original load. |
| 4634 | * However, if we have a fast path, we need to perform the load of obj.LockWord *before* the |
| 4635 | * original load. This load-load ordering is required by the read barrier. |
| 4636 | * The fast path/slow path (for Baker's algorithm) should look like: |
| 4637 | * |
| 4638 | * bool isGray = obj.LockWord & kReadBarrierMask; |
| 4639 | * lfence; // load fence or artificial data dependence to prevent load-load reordering |
| 4640 | * ref = obj.field; // this is the original load |
| 4641 | * if (isGray) { |
| 4642 | * ref = Mark(ref); // ideally the slow path just does Mark(ref) |
| 4643 | * } |
| 4644 | */ |
| 4645 | |
| 4646 | __ B(slow_path->GetEntryLabel()); |
| 4647 | __ Bind(slow_path->GetExitLabel()); |
| 4648 | } |
| 4649 | |
| 4650 | void CodeGeneratorARM64::MaybeGenerateReadBarrier(HInstruction* instruction, |
| 4651 | Location out, |
| 4652 | Location ref, |
| 4653 | Location obj, |
| 4654 | uint32_t offset, |
| 4655 | Location index) { |
| 4656 | if (kEmitCompilerReadBarrier) { |
| 4657 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 4658 | // by the runtime within the slow path. |
| 4659 | GenerateReadBarrier(instruction, out, ref, obj, offset, index); |
| 4660 | } else if (kPoisonHeapReferences) { |
| 4661 | GetAssembler()->UnpoisonHeapReference(WRegisterFrom(out)); |
| 4662 | } |
| 4663 | } |
| 4664 | |
| 4665 | void CodeGeneratorARM64::GenerateReadBarrierForRoot(HInstruction* instruction, |
| 4666 | Location out, |
| 4667 | Location root) { |
| 4668 | DCHECK(kEmitCompilerReadBarrier); |
| 4669 | |
| 4670 | // Note that GC roots are not affected by heap poisoning, so we do |
| 4671 | // not need to do anything special for this here. |
| 4672 | SlowPathCodeARM64* slow_path = |
| 4673 | new (GetGraph()->GetArena()) ReadBarrierForRootSlowPathARM64(instruction, out, root); |
| 4674 | AddSlowPath(slow_path); |
| 4675 | |
| 4676 | // TODO: Implement a fast path for ReadBarrierForRoot, performing |
| 4677 | // the following operation (for Baker's algorithm): |
| 4678 | // |
| 4679 | // if (thread.tls32_.is_gc_marking) { |
| 4680 | // root = Mark(root); |
| 4681 | // } |
| 4682 | |
| 4683 | __ B(slow_path->GetEntryLabel()); |
| 4684 | __ Bind(slow_path->GetExitLabel()); |
| 4685 | } |
| 4686 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4687 | #undef __ |
| 4688 | #undef QUICK_ENTRY_POINT |
| 4689 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4690 | } // namespace arm64 |
| 4691 | } // namespace art |