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 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 36 | using namespace vixl::aarch64; // NOLINT(build/namespaces) |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 37 | |
| 38 | #ifdef __ |
| 39 | #error "ARM64 Codegen VIXL macro-assembler macro already defined." |
| 40 | #endif |
| 41 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 42 | namespace art { |
| 43 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 44 | template<class MirrorType> |
| 45 | class GcRoot; |
| 46 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 47 | namespace arm64 { |
| 48 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 49 | using helpers::CPURegisterFrom; |
| 50 | using helpers::DRegisterFrom; |
| 51 | using helpers::FPRegisterFrom; |
| 52 | using helpers::HeapOperand; |
| 53 | using helpers::HeapOperandFrom; |
| 54 | using helpers::InputCPURegisterAt; |
| 55 | using helpers::InputFPRegisterAt; |
| 56 | using helpers::InputRegisterAt; |
| 57 | using helpers::InputOperandAt; |
| 58 | using helpers::Int64ConstantFrom; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 59 | using helpers::LocationFrom; |
| 60 | using helpers::OperandFromMemOperand; |
| 61 | using helpers::OutputCPURegister; |
| 62 | using helpers::OutputFPRegister; |
| 63 | using helpers::OutputRegister; |
| 64 | using helpers::RegisterFrom; |
| 65 | using helpers::StackOperandFrom; |
| 66 | using helpers::VIXLRegCodeFromART; |
| 67 | using helpers::WRegisterFrom; |
| 68 | using helpers::XRegisterFrom; |
Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 69 | using helpers::ARM64EncodableConstantOrRegister; |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 70 | using helpers::ArtVixlRegCodeCoherentForRegSet; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 71 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 72 | static constexpr int kCurrentMethodStackOffset = 0; |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 73 | // 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] | 74 | // table version generates 7 instructions and num_entries literals. Compare/jump sequence will |
| 75 | // generates less code/data with a small num_entries. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 76 | static constexpr uint32_t kPackedSwitchCompareJumpThreshold = 7; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 77 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 78 | inline Condition ARM64Condition(IfCondition cond) { |
| 79 | switch (cond) { |
| 80 | case kCondEQ: return eq; |
| 81 | case kCondNE: return ne; |
| 82 | case kCondLT: return lt; |
| 83 | case kCondLE: return le; |
| 84 | case kCondGT: return gt; |
| 85 | case kCondGE: return ge; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 86 | case kCondB: return lo; |
| 87 | case kCondBE: return ls; |
| 88 | case kCondA: return hi; |
| 89 | case kCondAE: return hs; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 90 | } |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 91 | LOG(FATAL) << "Unreachable"; |
| 92 | UNREACHABLE(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 93 | } |
| 94 | |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 95 | inline Condition ARM64FPCondition(IfCondition cond, bool gt_bias) { |
| 96 | // The ARM64 condition codes can express all the necessary branches, see the |
| 97 | // "Meaning (floating-point)" column in the table C1-1 in the ARMv8 reference manual. |
| 98 | // There is no dex instruction or HIR that would need the missing conditions |
| 99 | // "equal or unordered" or "not equal". |
| 100 | switch (cond) { |
| 101 | case kCondEQ: return eq; |
| 102 | case kCondNE: return ne /* unordered */; |
| 103 | case kCondLT: return gt_bias ? cc : lt /* unordered */; |
| 104 | case kCondLE: return gt_bias ? ls : le /* unordered */; |
| 105 | case kCondGT: return gt_bias ? hi /* unordered */ : gt; |
| 106 | case kCondGE: return gt_bias ? cs /* unordered */ : ge; |
| 107 | default: |
| 108 | LOG(FATAL) << "UNREACHABLE"; |
| 109 | UNREACHABLE(); |
| 110 | } |
| 111 | } |
| 112 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 113 | Location ARM64ReturnLocation(Primitive::Type return_type) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 114 | // Note that in practice, `LocationFrom(x0)` and `LocationFrom(w0)` create the |
| 115 | // same Location object, and so do `LocationFrom(d0)` and `LocationFrom(s0)`, |
| 116 | // but we use the exact registers for clarity. |
| 117 | if (return_type == Primitive::kPrimFloat) { |
| 118 | return LocationFrom(s0); |
| 119 | } else if (return_type == Primitive::kPrimDouble) { |
| 120 | return LocationFrom(d0); |
| 121 | } else if (return_type == Primitive::kPrimLong) { |
| 122 | return LocationFrom(x0); |
Nicolas Geoffray | 925e562 | 2015-06-03 12:23:32 +0100 | [diff] [blame] | 123 | } else if (return_type == Primitive::kPrimVoid) { |
| 124 | return Location::NoLocation(); |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 125 | } else { |
| 126 | return LocationFrom(w0); |
| 127 | } |
| 128 | } |
| 129 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 130 | Location InvokeRuntimeCallingConvention::GetReturnLocation(Primitive::Type return_type) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 131 | return ARM64ReturnLocation(return_type); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 132 | } |
| 133 | |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 134 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 135 | #define __ down_cast<CodeGeneratorARM64*>(codegen)->GetVIXLAssembler()-> // NOLINT |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 136 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kArm64PointerSize, 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, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 149 | register_set->GetCoreRegisters() & (~callee_saved_core_registers.GetList())); |
Nicolas Geoffray | 75d5b9b | 2015-10-05 07:40:35 +0000 | [diff] [blame] | 150 | CPURegList fp_list = CPURegList(CPURegister::kFPRegister, kDRegSize, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 151 | register_set->GetFloatingPointRegisters() & (~callee_saved_fp_registers.GetList())); |
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(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 157 | int64_t core_spill_size = core_list.GetTotalSizeInBytes(); |
| 158 | int64_t fp_spill_size = fp_list.GetTotalSizeInBytes(); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 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); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 162 | if (((core_list.GetCount() > 1) || (fp_list.GetCount() > 1)) && |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 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: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 222 | explicit BoundsCheckSlowPathARM64(HBoundsCheck* instruction) : SlowPathCodeARM64(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); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 239 | uint32_t entry_point_offset = instruction_->AsBoundsCheck()->IsStringCharAt() |
| 240 | ? QUICK_ENTRY_POINT(pThrowStringBounds) |
| 241 | : QUICK_ENTRY_POINT(pThrowArrayBounds); |
| 242 | arm64_codegen->InvokeRuntime(entry_point_offset, instruction_, instruction_->GetDexPc(), this); |
| 243 | CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>(); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 244 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 245 | } |
| 246 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 247 | bool IsFatal() const OVERRIDE { return true; } |
| 248 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 249 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathARM64"; } |
| 250 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 251 | private: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 252 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathARM64); |
| 253 | }; |
| 254 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 255 | class DivZeroCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 256 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 257 | explicit DivZeroCheckSlowPathARM64(HDivZeroCheck* instruction) : SlowPathCodeARM64(instruction) {} |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 258 | |
| 259 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 260 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 261 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 262 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 263 | // Live registers will be restored in the catch block if caught. |
| 264 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 265 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 266 | arm64_codegen->InvokeRuntime( |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 267 | QUICK_ENTRY_POINT(pThrowDivZero), instruction_, instruction_->GetDexPc(), this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 268 | CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 269 | } |
| 270 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 271 | bool IsFatal() const OVERRIDE { return true; } |
| 272 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 273 | const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathARM64"; } |
| 274 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 275 | private: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 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) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 285 | : SlowPathCodeARM64(at), cls_(cls), at_(at), dex_pc_(dex_pc), do_clinit_(do_clinit) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 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: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 340 | explicit LoadStringSlowPathARM64(HLoadString* instruction) : SlowPathCodeARM64(instruction) {} |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 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; |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 351 | const uint32_t string_index = instruction_->AsLoadString()->GetStringIndex(); |
| 352 | __ Mov(calling_convention.GetRegisterAt(0).W(), string_index); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 353 | arm64_codegen->InvokeRuntime( |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 354 | QUICK_ENTRY_POINT(pResolveString), instruction_, instruction_->GetDexPc(), this); |
Vladimir Marko | 5ea536a | 2015-04-20 20:11:30 +0100 | [diff] [blame] | 355 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 356 | Primitive::Type type = instruction_->GetType(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 357 | arm64_codegen->MoveLocation(locations->Out(), calling_convention.GetReturnLocation(type), type); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 358 | |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 359 | RestoreLiveRegisters(codegen, locations); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 360 | __ B(GetExitLabel()); |
| 361 | } |
| 362 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 363 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathARM64"; } |
| 364 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 365 | private: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 366 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathARM64); |
| 367 | }; |
| 368 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 369 | class NullCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 370 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 371 | explicit NullCheckSlowPathARM64(HNullCheck* instr) : SlowPathCodeARM64(instr) {} |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 372 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 373 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 374 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 375 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 376 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 377 | // Live registers will be restored in the catch block if caught. |
| 378 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 379 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 380 | arm64_codegen->InvokeRuntime( |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 381 | QUICK_ENTRY_POINT(pThrowNullPointer), instruction_, instruction_->GetDexPc(), this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 382 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 383 | } |
| 384 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 385 | bool IsFatal() const OVERRIDE { return true; } |
| 386 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 387 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathARM64"; } |
| 388 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 389 | private: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 390 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathARM64); |
| 391 | }; |
| 392 | |
| 393 | class SuspendCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 394 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 395 | SuspendCheckSlowPathARM64(HSuspendCheck* instruction, HBasicBlock* successor) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 396 | : SlowPathCodeARM64(instruction), successor_(successor) {} |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 397 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 398 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 399 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 400 | __ Bind(GetEntryLabel()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 401 | arm64_codegen->InvokeRuntime( |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 402 | QUICK_ENTRY_POINT(pTestSuspend), instruction_, instruction_->GetDexPc(), this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 403 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 404 | if (successor_ == nullptr) { |
| 405 | __ B(GetReturnLabel()); |
| 406 | } else { |
| 407 | __ B(arm64_codegen->GetLabelOf(successor_)); |
| 408 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 409 | } |
| 410 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 411 | vixl::aarch64::Label* GetReturnLabel() { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 412 | DCHECK(successor_ == nullptr); |
| 413 | return &return_label_; |
| 414 | } |
| 415 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 416 | HBasicBlock* GetSuccessor() const { |
| 417 | return successor_; |
| 418 | } |
| 419 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 420 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathARM64"; } |
| 421 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 422 | private: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 423 | // If not null, the block to branch to after the suspend check. |
| 424 | HBasicBlock* const successor_; |
| 425 | |
| 426 | // If `successor_` is null, the label to branch to after the suspend check. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 427 | vixl::aarch64::Label return_label_; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 428 | |
| 429 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathARM64); |
| 430 | }; |
| 431 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 432 | class TypeCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 433 | public: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 434 | TypeCheckSlowPathARM64(HInstruction* instruction, bool is_fatal) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 435 | : SlowPathCodeARM64(instruction), is_fatal_(is_fatal) {} |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 436 | |
| 437 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 438 | LocationSummary* locations = instruction_->GetLocations(); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 439 | Location class_to_check = locations->InAt(1); |
| 440 | Location object_class = instruction_->IsCheckCast() ? locations->GetTemp(0) |
| 441 | : locations->Out(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 442 | DCHECK(instruction_->IsCheckCast() |
| 443 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 444 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 445 | uint32_t dex_pc = instruction_->GetDexPc(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 446 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 447 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 448 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 449 | if (!is_fatal_) { |
| 450 | SaveLiveRegisters(codegen, locations); |
| 451 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 452 | |
| 453 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 454 | // move resolver. |
| 455 | InvokeRuntimeCallingConvention calling_convention; |
| 456 | codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 457 | class_to_check, LocationFrom(calling_convention.GetRegisterAt(0)), Primitive::kPrimNot, |
| 458 | object_class, LocationFrom(calling_convention.GetRegisterAt(1)), Primitive::kPrimNot); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 459 | |
| 460 | if (instruction_->IsInstanceOf()) { |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 461 | arm64_codegen->InvokeRuntime( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 462 | QUICK_ENTRY_POINT(pInstanceofNonTrivial), instruction_, dex_pc, this); |
Andreas Gampe | 6740997 | 2016-07-19 22:34:53 -0700 | [diff] [blame] | 463 | CheckEntrypointTypes<kQuickInstanceofNonTrivial, size_t, |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 464 | const mirror::Class*, const mirror::Class*>(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 465 | Primitive::Type ret_type = instruction_->GetType(); |
| 466 | Location ret_loc = calling_convention.GetReturnLocation(ret_type); |
| 467 | arm64_codegen->MoveLocation(locations->Out(), ret_loc, ret_type); |
| 468 | } else { |
| 469 | DCHECK(instruction_->IsCheckCast()); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 470 | arm64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pCheckCast), instruction_, dex_pc, this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 471 | CheckEntrypointTypes<kQuickCheckCast, void, const mirror::Class*, const mirror::Class*>(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 472 | } |
| 473 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 474 | if (!is_fatal_) { |
| 475 | RestoreLiveRegisters(codegen, locations); |
| 476 | __ B(GetExitLabel()); |
| 477 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 478 | } |
| 479 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 480 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathARM64"; } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 481 | bool IsFatal() const { return is_fatal_; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 482 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 483 | private: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 484 | const bool is_fatal_; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 485 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 486 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathARM64); |
| 487 | }; |
| 488 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 489 | class DeoptimizationSlowPathARM64 : public SlowPathCodeARM64 { |
| 490 | public: |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 491 | explicit DeoptimizationSlowPathARM64(HDeoptimize* instruction) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 492 | : SlowPathCodeARM64(instruction) {} |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 493 | |
| 494 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 495 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 496 | __ Bind(GetEntryLabel()); |
| 497 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 498 | arm64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pDeoptimize), |
| 499 | instruction_, |
| 500 | instruction_->GetDexPc(), |
| 501 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 502 | CheckEntrypointTypes<kQuickDeoptimize, void, void>(); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 503 | } |
| 504 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 505 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathARM64"; } |
| 506 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 507 | private: |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 508 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathARM64); |
| 509 | }; |
| 510 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 511 | class ArraySetSlowPathARM64 : public SlowPathCodeARM64 { |
| 512 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 513 | explicit ArraySetSlowPathARM64(HInstruction* instruction) : SlowPathCodeARM64(instruction) {} |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 514 | |
| 515 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 516 | LocationSummary* locations = instruction_->GetLocations(); |
| 517 | __ Bind(GetEntryLabel()); |
| 518 | SaveLiveRegisters(codegen, locations); |
| 519 | |
| 520 | InvokeRuntimeCallingConvention calling_convention; |
| 521 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 522 | parallel_move.AddMove( |
| 523 | locations->InAt(0), |
| 524 | LocationFrom(calling_convention.GetRegisterAt(0)), |
| 525 | Primitive::kPrimNot, |
| 526 | nullptr); |
| 527 | parallel_move.AddMove( |
| 528 | locations->InAt(1), |
| 529 | LocationFrom(calling_convention.GetRegisterAt(1)), |
| 530 | Primitive::kPrimInt, |
| 531 | nullptr); |
| 532 | parallel_move.AddMove( |
| 533 | locations->InAt(2), |
| 534 | LocationFrom(calling_convention.GetRegisterAt(2)), |
| 535 | Primitive::kPrimNot, |
| 536 | nullptr); |
| 537 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 538 | |
| 539 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 540 | arm64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject), |
| 541 | instruction_, |
| 542 | instruction_->GetDexPc(), |
| 543 | this); |
| 544 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
| 545 | RestoreLiveRegisters(codegen, locations); |
| 546 | __ B(GetExitLabel()); |
| 547 | } |
| 548 | |
| 549 | const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathARM64"; } |
| 550 | |
| 551 | private: |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 552 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathARM64); |
| 553 | }; |
| 554 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 555 | void JumpTableARM64::EmitTable(CodeGeneratorARM64* codegen) { |
| 556 | uint32_t num_entries = switch_instr_->GetNumEntries(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 557 | DCHECK_GE(num_entries, kPackedSwitchCompareJumpThreshold); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 558 | |
| 559 | // We are about to use the assembler to place literals directly. Make sure we have enough |
| 560 | // underlying code buffer and we have generated the jump table with right size. |
| 561 | CodeBufferCheckScope scope(codegen->GetVIXLAssembler(), num_entries * sizeof(int32_t), |
| 562 | CodeBufferCheckScope::kCheck, CodeBufferCheckScope::kExactSize); |
| 563 | |
| 564 | __ Bind(&table_start_); |
| 565 | const ArenaVector<HBasicBlock*>& successors = switch_instr_->GetBlock()->GetSuccessors(); |
| 566 | for (uint32_t i = 0; i < num_entries; i++) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 567 | vixl::aarch64::Label* target_label = codegen->GetLabelOf(successors[i]); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 568 | DCHECK(target_label->IsBound()); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 569 | ptrdiff_t jump_offset = target_label->GetLocation() - table_start_.GetLocation(); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 570 | DCHECK_GT(jump_offset, std::numeric_limits<int32_t>::min()); |
| 571 | DCHECK_LE(jump_offset, std::numeric_limits<int32_t>::max()); |
| 572 | Literal<int32_t> literal(jump_offset); |
| 573 | __ place(&literal); |
| 574 | } |
| 575 | } |
| 576 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 577 | // Slow path marking an object during a read barrier. |
| 578 | class ReadBarrierMarkSlowPathARM64 : public SlowPathCodeARM64 { |
| 579 | public: |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 580 | ReadBarrierMarkSlowPathARM64(HInstruction* instruction, Location obj) |
| 581 | : SlowPathCodeARM64(instruction), obj_(obj) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 582 | DCHECK(kEmitCompilerReadBarrier); |
| 583 | } |
| 584 | |
| 585 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathARM64"; } |
| 586 | |
| 587 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 588 | LocationSummary* locations = instruction_->GetLocations(); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 589 | DCHECK(locations->CanCall()); |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 590 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(obj_.reg())); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 591 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 592 | instruction_->IsStaticFieldGet() || |
| 593 | instruction_->IsArrayGet() || |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame^] | 594 | instruction_->IsArraySet() || |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 595 | instruction_->IsLoadClass() || |
| 596 | instruction_->IsLoadString() || |
| 597 | instruction_->IsInstanceOf() || |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 598 | instruction_->IsCheckCast() || |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 599 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()) || |
| 600 | (instruction_->IsInvokeStaticOrDirect() && instruction_->GetLocations()->Intrinsified())) |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 601 | << "Unexpected instruction in read barrier marking slow path: " |
| 602 | << instruction_->DebugName(); |
| 603 | |
| 604 | __ Bind(GetEntryLabel()); |
Roland Levillain | 4359e61 | 2016-07-20 11:32:19 +0100 | [diff] [blame] | 605 | // No need to save live registers; it's taken care of by the |
| 606 | // entrypoint. Also, there is no need to update the stack mask, |
| 607 | // as this runtime call will not trigger a garbage collection. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 608 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 609 | DCHECK_NE(obj_.reg(), LR); |
| 610 | DCHECK_NE(obj_.reg(), WSP); |
| 611 | DCHECK_NE(obj_.reg(), WZR); |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 612 | // IP0 is used internally by the ReadBarrierMarkRegX entry point |
| 613 | // as a temporary, it cannot be the entry point's input/output. |
Mathieu Chartier | 36a270a | 2016-07-28 18:08:51 -0700 | [diff] [blame] | 614 | DCHECK_NE(obj_.reg(), IP0); |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 615 | DCHECK(0 <= obj_.reg() && obj_.reg() < kNumberOfWRegisters) << obj_.reg(); |
| 616 | // "Compact" slow path, saving two moves. |
| 617 | // |
| 618 | // Instead of using the standard runtime calling convention (input |
| 619 | // and output in W0): |
| 620 | // |
| 621 | // W0 <- obj |
| 622 | // W0 <- ReadBarrierMark(W0) |
| 623 | // obj <- W0 |
| 624 | // |
| 625 | // we just use rX (the register holding `obj`) as input and output |
| 626 | // of a dedicated entrypoint: |
| 627 | // |
| 628 | // rX <- ReadBarrierMarkRegX(rX) |
| 629 | // |
| 630 | int32_t entry_point_offset = |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 631 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArm64PointerSize>(obj_.reg()); |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 632 | // This runtime call does not require a stack map. |
| 633 | arm64_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 634 | __ B(GetExitLabel()); |
| 635 | } |
| 636 | |
| 637 | private: |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 638 | const Location obj_; |
| 639 | |
| 640 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathARM64); |
| 641 | }; |
| 642 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 643 | // Slow path generating a read barrier for a heap reference. |
| 644 | class ReadBarrierForHeapReferenceSlowPathARM64 : public SlowPathCodeARM64 { |
| 645 | public: |
| 646 | ReadBarrierForHeapReferenceSlowPathARM64(HInstruction* instruction, |
| 647 | Location out, |
| 648 | Location ref, |
| 649 | Location obj, |
| 650 | uint32_t offset, |
| 651 | Location index) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 652 | : SlowPathCodeARM64(instruction), |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 653 | out_(out), |
| 654 | ref_(ref), |
| 655 | obj_(obj), |
| 656 | offset_(offset), |
| 657 | index_(index) { |
| 658 | DCHECK(kEmitCompilerReadBarrier); |
| 659 | // If `obj` is equal to `out` or `ref`, it means the initial object |
| 660 | // has been overwritten by (or after) the heap object reference load |
| 661 | // to be instrumented, e.g.: |
| 662 | // |
| 663 | // __ Ldr(out, HeapOperand(out, class_offset); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 664 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 665 | // |
| 666 | // In that case, we have lost the information about the original |
| 667 | // object, and the emitted read barrier cannot work properly. |
| 668 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 669 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 670 | } |
| 671 | |
| 672 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 673 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 674 | LocationSummary* locations = instruction_->GetLocations(); |
| 675 | Primitive::Type type = Primitive::kPrimNot; |
| 676 | DCHECK(locations->CanCall()); |
| 677 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(out_.reg())); |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 678 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 679 | instruction_->IsStaticFieldGet() || |
| 680 | instruction_->IsArrayGet() || |
| 681 | instruction_->IsInstanceOf() || |
| 682 | instruction_->IsCheckCast() || |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 683 | (instruction_->IsInvokeVirtual()) && instruction_->GetLocations()->Intrinsified()) |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 684 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 685 | << instruction_->DebugName(); |
Roland Levillain | 4a3aa57 | 2016-08-15 13:17:06 +0000 | [diff] [blame] | 686 | // The read barrier instrumentation does not support the HIntermediateAddress instruction yet. |
Roland Levillain | cd3d0fb | 2016-01-15 19:26:48 +0000 | [diff] [blame] | 687 | DCHECK(!(instruction_->IsArrayGet() && |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 688 | instruction_->AsArrayGet()->GetArray()->IsIntermediateAddress())); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 689 | |
| 690 | __ Bind(GetEntryLabel()); |
| 691 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 692 | SaveLiveRegisters(codegen, locations); |
| 693 | |
| 694 | // We may have to change the index's value, but as `index_` is a |
| 695 | // constant member (like other "inputs" of this slow path), |
| 696 | // introduce a copy of it, `index`. |
| 697 | Location index = index_; |
| 698 | if (index_.IsValid()) { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 699 | // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 700 | if (instruction_->IsArrayGet()) { |
| 701 | // Compute the actual memory offset and store it in `index`. |
| 702 | Register index_reg = RegisterFrom(index_, Primitive::kPrimInt); |
| 703 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_.reg())); |
| 704 | if (codegen->IsCoreCalleeSaveRegister(index_.reg())) { |
| 705 | // We are about to change the value of `index_reg` (see the |
| 706 | // calls to vixl::MacroAssembler::Lsl and |
| 707 | // vixl::MacroAssembler::Mov below), but it has |
| 708 | // not been saved by the previous call to |
| 709 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 710 | // callee-save register -- |
| 711 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 712 | // callee-save registers, as it has been designed with the |
| 713 | // assumption that callee-save registers are supposed to be |
| 714 | // handled by the called function. So, as a callee-save |
| 715 | // register, `index_reg` _would_ eventually be saved onto |
| 716 | // the stack, but it would be too late: we would have |
| 717 | // changed its value earlier. Therefore, we manually save |
| 718 | // it here into another freely available register, |
| 719 | // `free_reg`, chosen of course among the caller-save |
| 720 | // registers (as a callee-save `free_reg` register would |
| 721 | // exhibit the same problem). |
| 722 | // |
| 723 | // Note we could have requested a temporary register from |
| 724 | // the register allocator instead; but we prefer not to, as |
| 725 | // this is a slow path, and we know we can find a |
| 726 | // caller-save register that is available. |
| 727 | Register free_reg = FindAvailableCallerSaveRegister(codegen); |
| 728 | __ Mov(free_reg.W(), index_reg); |
| 729 | index_reg = free_reg; |
| 730 | index = LocationFrom(index_reg); |
| 731 | } else { |
| 732 | // The initial register stored in `index_` has already been |
| 733 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 734 | // (as it is not a callee-save register), so we can freely |
| 735 | // use it. |
| 736 | } |
| 737 | // Shifting the index value contained in `index_reg` by the scale |
| 738 | // factor (2) cannot overflow in practice, as the runtime is |
| 739 | // unable to allocate object arrays with a size larger than |
| 740 | // 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 741 | __ Lsl(index_reg, index_reg, Primitive::ComponentSizeShift(type)); |
| 742 | static_assert( |
| 743 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 744 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 745 | __ Add(index_reg, index_reg, Operand(offset_)); |
| 746 | } else { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 747 | // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile |
| 748 | // intrinsics, `index_` is not shifted by a scale factor of 2 |
| 749 | // (as in the case of ArrayGet), as it is actually an offset |
| 750 | // to an object field within an object. |
| 751 | DCHECK(instruction_->IsInvoke()) << instruction_->DebugName(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 752 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 753 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 754 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 755 | << instruction_->AsInvoke()->GetIntrinsic(); |
| 756 | DCHECK_EQ(offset_, 0U); |
Roland Levillain | a7426c6 | 2016-08-03 15:02:10 +0100 | [diff] [blame] | 757 | DCHECK(index_.IsRegister()); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 758 | } |
| 759 | } |
| 760 | |
| 761 | // We're moving two or three locations to locations that could |
| 762 | // overlap, so we need a parallel move resolver. |
| 763 | InvokeRuntimeCallingConvention calling_convention; |
| 764 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 765 | parallel_move.AddMove(ref_, |
| 766 | LocationFrom(calling_convention.GetRegisterAt(0)), |
| 767 | type, |
| 768 | nullptr); |
| 769 | parallel_move.AddMove(obj_, |
| 770 | LocationFrom(calling_convention.GetRegisterAt(1)), |
| 771 | type, |
| 772 | nullptr); |
| 773 | if (index.IsValid()) { |
| 774 | parallel_move.AddMove(index, |
| 775 | LocationFrom(calling_convention.GetRegisterAt(2)), |
| 776 | Primitive::kPrimInt, |
| 777 | nullptr); |
| 778 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 779 | } else { |
| 780 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 781 | arm64_codegen->MoveConstant(LocationFrom(calling_convention.GetRegisterAt(2)), offset_); |
| 782 | } |
| 783 | arm64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pReadBarrierSlow), |
| 784 | instruction_, |
| 785 | instruction_->GetDexPc(), |
| 786 | this); |
| 787 | CheckEntrypointTypes< |
| 788 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 789 | arm64_codegen->MoveLocation(out_, calling_convention.GetReturnLocation(type), type); |
| 790 | |
| 791 | RestoreLiveRegisters(codegen, locations); |
| 792 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 793 | __ B(GetExitLabel()); |
| 794 | } |
| 795 | |
| 796 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForHeapReferenceSlowPathARM64"; } |
| 797 | |
| 798 | private: |
| 799 | Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 800 | size_t ref = static_cast<int>(XRegisterFrom(ref_).GetCode()); |
| 801 | size_t obj = static_cast<int>(XRegisterFrom(obj_).GetCode()); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 802 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 803 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 804 | return Register(VIXLRegCodeFromART(i), kXRegSize); |
| 805 | } |
| 806 | } |
| 807 | // We shall never fail to find a free caller-save register, as |
| 808 | // there are more than two core caller-save registers on ARM64 |
| 809 | // (meaning it is possible to find one which is different from |
| 810 | // `ref` and `obj`). |
| 811 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 812 | LOG(FATAL) << "Could not find a free register"; |
| 813 | UNREACHABLE(); |
| 814 | } |
| 815 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 816 | const Location out_; |
| 817 | const Location ref_; |
| 818 | const Location obj_; |
| 819 | const uint32_t offset_; |
| 820 | // An additional location containing an index to an array. |
| 821 | // Only used for HArrayGet and the UnsafeGetObject & |
| 822 | // UnsafeGetObjectVolatile intrinsics. |
| 823 | const Location index_; |
| 824 | |
| 825 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathARM64); |
| 826 | }; |
| 827 | |
| 828 | // Slow path generating a read barrier for a GC root. |
| 829 | class ReadBarrierForRootSlowPathARM64 : public SlowPathCodeARM64 { |
| 830 | public: |
| 831 | ReadBarrierForRootSlowPathARM64(HInstruction* instruction, Location out, Location root) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 832 | : SlowPathCodeARM64(instruction), out_(out), root_(root) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 833 | DCHECK(kEmitCompilerReadBarrier); |
| 834 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 835 | |
| 836 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 837 | LocationSummary* locations = instruction_->GetLocations(); |
| 838 | Primitive::Type type = Primitive::kPrimNot; |
| 839 | DCHECK(locations->CanCall()); |
| 840 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(out_.reg())); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 841 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 842 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 843 | << instruction_->DebugName(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 844 | |
| 845 | __ Bind(GetEntryLabel()); |
| 846 | SaveLiveRegisters(codegen, locations); |
| 847 | |
| 848 | InvokeRuntimeCallingConvention calling_convention; |
| 849 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 850 | // The argument of the ReadBarrierForRootSlow is not a managed |
| 851 | // reference (`mirror::Object*`), but a `GcRoot<mirror::Object>*`; |
| 852 | // thus we need a 64-bit move here, and we cannot use |
| 853 | // |
| 854 | // arm64_codegen->MoveLocation( |
| 855 | // LocationFrom(calling_convention.GetRegisterAt(0)), |
| 856 | // root_, |
| 857 | // type); |
| 858 | // |
| 859 | // which would emit a 32-bit move, as `type` is a (32-bit wide) |
| 860 | // reference type (`Primitive::kPrimNot`). |
| 861 | __ Mov(calling_convention.GetRegisterAt(0), XRegisterFrom(out_)); |
| 862 | arm64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pReadBarrierForRootSlow), |
| 863 | instruction_, |
| 864 | instruction_->GetDexPc(), |
| 865 | this); |
| 866 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 867 | arm64_codegen->MoveLocation(out_, calling_convention.GetReturnLocation(type), type); |
| 868 | |
| 869 | RestoreLiveRegisters(codegen, locations); |
| 870 | __ B(GetExitLabel()); |
| 871 | } |
| 872 | |
| 873 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathARM64"; } |
| 874 | |
| 875 | private: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 876 | const Location out_; |
| 877 | const Location root_; |
| 878 | |
| 879 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathARM64); |
| 880 | }; |
| 881 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 882 | #undef __ |
| 883 | |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 884 | Location InvokeDexCallingConventionVisitorARM64::GetNextLocation(Primitive::Type type) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 885 | Location next_location; |
| 886 | if (type == Primitive::kPrimVoid) { |
| 887 | LOG(FATAL) << "Unreachable type " << type; |
| 888 | } |
| 889 | |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 890 | if (Primitive::IsFloatingPointType(type) && |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 891 | (float_index_ < calling_convention.GetNumberOfFpuRegisters())) { |
| 892 | next_location = LocationFrom(calling_convention.GetFpuRegisterAt(float_index_++)); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 893 | } else if (!Primitive::IsFloatingPointType(type) && |
| 894 | (gp_index_ < calling_convention.GetNumberOfRegisters())) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 895 | next_location = LocationFrom(calling_convention.GetRegisterAt(gp_index_++)); |
| 896 | } else { |
| 897 | size_t stack_offset = calling_convention.GetStackOffsetOf(stack_index_); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 898 | next_location = Primitive::Is64BitType(type) ? Location::DoubleStackSlot(stack_offset) |
| 899 | : Location::StackSlot(stack_offset); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 900 | } |
| 901 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 902 | // Space on the stack is reserved for all arguments. |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 903 | stack_index_ += Primitive::Is64BitType(type) ? 2 : 1; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 904 | return next_location; |
| 905 | } |
| 906 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 907 | Location InvokeDexCallingConventionVisitorARM64::GetMethodLocation() const { |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 908 | return LocationFrom(kArtMethodRegister); |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 909 | } |
| 910 | |
Serban Constantinescu | 579885a | 2015-02-22 20:51:33 +0000 | [diff] [blame] | 911 | CodeGeneratorARM64::CodeGeneratorARM64(HGraph* graph, |
| 912 | const Arm64InstructionSetFeatures& isa_features, |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 913 | const CompilerOptions& compiler_options, |
| 914 | OptimizingCompilerStats* stats) |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 915 | : CodeGenerator(graph, |
| 916 | kNumberOfAllocatableRegisters, |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 917 | kNumberOfAllocatableFPRegisters, |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 918 | kNumberOfAllocatableRegisterPairs, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 919 | callee_saved_core_registers.GetList(), |
| 920 | callee_saved_fp_registers.GetList(), |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 921 | compiler_options, |
| 922 | stats), |
Alexandre Rames | c01a664 | 2016-04-15 11:54:06 +0100 | [diff] [blame] | 923 | block_labels_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 924 | jump_tables_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 925 | location_builder_(graph, this), |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 926 | instruction_visitor_(graph, this), |
Serban Constantinescu | 579885a | 2015-02-22 20:51:33 +0000 | [diff] [blame] | 927 | move_resolver_(graph->GetArena(), this), |
Vladimir Marko | 93205e3 | 2016-04-13 11:59:46 +0100 | [diff] [blame] | 928 | assembler_(graph->GetArena()), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 929 | isa_features_(isa_features), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 930 | uint32_literals_(std::less<uint32_t>(), |
| 931 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 932 | uint64_literals_(std::less<uint64_t>(), |
| 933 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 934 | method_patches_(MethodReferenceComparator(), |
| 935 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 936 | call_patches_(MethodReferenceComparator(), |
| 937 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 938 | relative_call_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 939 | pc_relative_dex_cache_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 940 | boot_image_string_patches_(StringReferenceValueComparator(), |
| 941 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 942 | pc_relative_string_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 943 | boot_image_type_patches_(TypeReferenceValueComparator(), |
| 944 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 945 | pc_relative_type_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 946 | boot_image_address_patches_(std::less<uint32_t>(), |
| 947 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 948 | // Save the link register (containing the return address) to mimic Quick. |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 949 | AddAllocatedRegister(LocationFrom(lr)); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 950 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 951 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 952 | #define __ GetVIXLAssembler()-> |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 953 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 954 | void CodeGeneratorARM64::EmitJumpTables() { |
Alexandre Rames | c01a664 | 2016-04-15 11:54:06 +0100 | [diff] [blame] | 955 | for (auto&& jump_table : jump_tables_) { |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 956 | jump_table->EmitTable(this); |
| 957 | } |
| 958 | } |
| 959 | |
Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 960 | void CodeGeneratorARM64::Finalize(CodeAllocator* allocator) { |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 961 | EmitJumpTables(); |
Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 962 | // Ensure we emit the literal pool. |
| 963 | __ FinalizeCode(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 964 | |
Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 965 | CodeGenerator::Finalize(allocator); |
| 966 | } |
| 967 | |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 968 | void ParallelMoveResolverARM64::PrepareForEmitNativeCode() { |
| 969 | // Note: There are 6 kinds of moves: |
| 970 | // 1. constant -> GPR/FPR (non-cycle) |
| 971 | // 2. constant -> stack (non-cycle) |
| 972 | // 3. GPR/FPR -> GPR/FPR |
| 973 | // 4. GPR/FPR -> stack |
| 974 | // 5. stack -> GPR/FPR |
| 975 | // 6. stack -> stack (non-cycle) |
| 976 | // Case 1, 2 and 6 should never be included in a dependency cycle on ARM64. For case 3, 4, and 5 |
| 977 | // VIXL uses at most 1 GPR. VIXL has 2 GPR and 1 FPR temps, and there should be no intersecting |
| 978 | // cycles on ARM64, so we always have 1 GPR and 1 FPR available VIXL temps to resolve the |
| 979 | // dependency. |
| 980 | vixl_temps_.Open(GetVIXLAssembler()); |
| 981 | } |
| 982 | |
| 983 | void ParallelMoveResolverARM64::FinishEmitNativeCode() { |
| 984 | vixl_temps_.Close(); |
| 985 | } |
| 986 | |
| 987 | Location ParallelMoveResolverARM64::AllocateScratchLocationFor(Location::Kind kind) { |
| 988 | DCHECK(kind == Location::kRegister || kind == Location::kFpuRegister || |
| 989 | kind == Location::kStackSlot || kind == Location::kDoubleStackSlot); |
| 990 | kind = (kind == Location::kFpuRegister) ? Location::kFpuRegister : Location::kRegister; |
| 991 | Location scratch = GetScratchLocation(kind); |
| 992 | if (!scratch.Equals(Location::NoLocation())) { |
| 993 | return scratch; |
| 994 | } |
| 995 | // Allocate from VIXL temp registers. |
| 996 | if (kind == Location::kRegister) { |
| 997 | scratch = LocationFrom(vixl_temps_.AcquireX()); |
| 998 | } else { |
| 999 | DCHECK(kind == Location::kFpuRegister); |
| 1000 | scratch = LocationFrom(vixl_temps_.AcquireD()); |
| 1001 | } |
| 1002 | AddScratchLocation(scratch); |
| 1003 | return scratch; |
| 1004 | } |
| 1005 | |
| 1006 | void ParallelMoveResolverARM64::FreeScratchLocation(Location loc) { |
| 1007 | if (loc.IsRegister()) { |
| 1008 | vixl_temps_.Release(XRegisterFrom(loc)); |
| 1009 | } else { |
| 1010 | DCHECK(loc.IsFpuRegister()); |
| 1011 | vixl_temps_.Release(DRegisterFrom(loc)); |
| 1012 | } |
| 1013 | RemoveScratchLocation(loc); |
| 1014 | } |
| 1015 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1016 | void ParallelMoveResolverARM64::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 1017 | MoveOperands* move = moves_[index]; |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1018 | codegen_->MoveLocation(move->GetDestination(), move->GetSource(), Primitive::kPrimVoid); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1019 | } |
| 1020 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1021 | void CodeGeneratorARM64::GenerateFrameEntry() { |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1022 | MacroAssembler* masm = GetVIXLAssembler(); |
| 1023 | BlockPoolsScope block_pools(masm); |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1024 | __ Bind(&frame_entry_label_); |
| 1025 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1026 | bool do_overflow_check = FrameNeedsStackCheck(GetFrameSize(), kArm64) || !IsLeafMethod(); |
| 1027 | if (do_overflow_check) { |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1028 | UseScratchRegisterScope temps(masm); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1029 | Register temp = temps.AcquireX(); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1030 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1031 | __ Sub(temp, sp, static_cast<int32_t>(GetStackOverflowReservedBytes(kArm64))); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1032 | __ Ldr(wzr, MemOperand(temp, 0)); |
| 1033 | RecordPcInfo(nullptr, 0); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1034 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1035 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1036 | if (!HasEmptyFrame()) { |
| 1037 | int frame_size = GetFrameSize(); |
| 1038 | // Stack layout: |
| 1039 | // sp[frame_size - 8] : lr. |
| 1040 | // ... : other preserved core registers. |
| 1041 | // ... : other preserved fp registers. |
| 1042 | // ... : reserved frame space. |
| 1043 | // sp[0] : current method. |
| 1044 | __ Str(kArtMethodRegister, MemOperand(sp, -frame_size, PreIndex)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1045 | GetAssembler()->cfi().AdjustCFAOffset(frame_size); |
Zheng Xu | 69a5030 | 2015-04-14 20:04:41 +0800 | [diff] [blame] | 1046 | GetAssembler()->SpillRegisters(GetFramePreservedCoreRegisters(), |
| 1047 | frame_size - GetCoreSpillSize()); |
| 1048 | GetAssembler()->SpillRegisters(GetFramePreservedFPRegisters(), |
| 1049 | frame_size - FrameEntrySpillSize()); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1050 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1051 | } |
| 1052 | |
| 1053 | void CodeGeneratorARM64::GenerateFrameExit() { |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1054 | BlockPoolsScope block_pools(GetVIXLAssembler()); |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1055 | GetAssembler()->cfi().RememberState(); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1056 | if (!HasEmptyFrame()) { |
| 1057 | int frame_size = GetFrameSize(); |
Zheng Xu | 69a5030 | 2015-04-14 20:04:41 +0800 | [diff] [blame] | 1058 | GetAssembler()->UnspillRegisters(GetFramePreservedFPRegisters(), |
| 1059 | frame_size - FrameEntrySpillSize()); |
| 1060 | GetAssembler()->UnspillRegisters(GetFramePreservedCoreRegisters(), |
| 1061 | frame_size - GetCoreSpillSize()); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1062 | __ Drop(frame_size); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1063 | GetAssembler()->cfi().AdjustCFAOffset(-frame_size); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1064 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1065 | __ Ret(); |
| 1066 | GetAssembler()->cfi().RestoreState(); |
| 1067 | GetAssembler()->cfi().DefCFAOffset(GetFrameSize()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1068 | } |
| 1069 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1070 | CPURegList CodeGeneratorARM64::GetFramePreservedCoreRegisters() const { |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1071 | DCHECK(ArtVixlRegCodeCoherentForRegSet(core_spill_mask_, GetNumberOfCoreRegisters(), 0, 0)); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1072 | return CPURegList(CPURegister::kRegister, kXRegSize, |
| 1073 | core_spill_mask_); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1074 | } |
| 1075 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1076 | CPURegList CodeGeneratorARM64::GetFramePreservedFPRegisters() const { |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1077 | DCHECK(ArtVixlRegCodeCoherentForRegSet(0, 0, fpu_spill_mask_, |
| 1078 | GetNumberOfFloatingPointRegisters())); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1079 | return CPURegList(CPURegister::kFPRegister, kDRegSize, |
| 1080 | fpu_spill_mask_); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1081 | } |
| 1082 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1083 | void CodeGeneratorARM64::Bind(HBasicBlock* block) { |
| 1084 | __ Bind(GetLabelOf(block)); |
| 1085 | } |
| 1086 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1087 | void CodeGeneratorARM64::MoveConstant(Location location, int32_t value) { |
| 1088 | DCHECK(location.IsRegister()); |
| 1089 | __ Mov(RegisterFrom(location, Primitive::kPrimInt), value); |
| 1090 | } |
| 1091 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1092 | void CodeGeneratorARM64::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1093 | if (location.IsRegister()) { |
| 1094 | locations->AddTemp(location); |
| 1095 | } else { |
| 1096 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1097 | } |
| 1098 | } |
| 1099 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1100 | void CodeGeneratorARM64::MarkGCCard(Register object, Register value, bool value_can_be_null) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1101 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1102 | Register card = temps.AcquireX(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1103 | Register temp = temps.AcquireW(); // Index within the CardTable - 32bit. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1104 | vixl::aarch64::Label done; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1105 | if (value_can_be_null) { |
| 1106 | __ Cbz(value, &done); |
| 1107 | } |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1108 | __ Ldr(card, MemOperand(tr, Thread::CardTableOffset<kArm64PointerSize>().Int32Value())); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1109 | __ Lsr(temp, object, gc::accounting::CardTable::kCardShift); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1110 | __ Strb(card, MemOperand(card, temp.X())); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1111 | if (value_can_be_null) { |
| 1112 | __ Bind(&done); |
| 1113 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1114 | } |
| 1115 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1116 | void CodeGeneratorARM64::SetupBlockedRegisters() const { |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1117 | // Blocked core registers: |
| 1118 | // lr : Runtime reserved. |
| 1119 | // tr : Runtime reserved. |
| 1120 | // xSuspend : Runtime reserved. TODO: Unblock this when the runtime stops using it. |
| 1121 | // ip1 : VIXL core temp. |
| 1122 | // ip0 : VIXL core temp. |
| 1123 | // |
| 1124 | // Blocked fp registers: |
| 1125 | // d31 : VIXL fp temp. |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1126 | CPURegList reserved_core_registers = vixl_reserved_core_registers; |
| 1127 | reserved_core_registers.Combine(runtime_reserved_core_registers); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1128 | while (!reserved_core_registers.IsEmpty()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1129 | blocked_core_registers_[reserved_core_registers.PopLowestIndex().GetCode()] = true; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1130 | } |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1131 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1132 | CPURegList reserved_fp_registers = vixl_reserved_fp_registers; |
Zheng Xu | a3ec394 | 2015-02-15 18:39:46 +0800 | [diff] [blame] | 1133 | while (!reserved_fp_registers.IsEmpty()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1134 | blocked_fpu_registers_[reserved_fp_registers.PopLowestIndex().GetCode()] = true; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1135 | } |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1136 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1137 | if (GetGraph()->IsDebuggable()) { |
Nicolas Geoffray | ecf680d | 2015-10-05 11:15:37 +0100 | [diff] [blame] | 1138 | // Stubs do not save callee-save floating point registers. If the graph |
| 1139 | // is debuggable, we need to deal with these registers differently. For |
| 1140 | // now, just block them. |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1141 | CPURegList reserved_fp_registers_debuggable = callee_saved_fp_registers; |
| 1142 | while (!reserved_fp_registers_debuggable.IsEmpty()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1143 | blocked_fpu_registers_[reserved_fp_registers_debuggable.PopLowestIndex().GetCode()] = true; |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1144 | } |
| 1145 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1146 | } |
| 1147 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1148 | size_t CodeGeneratorARM64::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1149 | Register reg = Register(VIXLRegCodeFromART(reg_id), kXRegSize); |
| 1150 | __ Str(reg, MemOperand(sp, stack_index)); |
| 1151 | return kArm64WordSize; |
| 1152 | } |
| 1153 | |
| 1154 | size_t CodeGeneratorARM64::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1155 | Register reg = Register(VIXLRegCodeFromART(reg_id), kXRegSize); |
| 1156 | __ Ldr(reg, MemOperand(sp, stack_index)); |
| 1157 | return kArm64WordSize; |
| 1158 | } |
| 1159 | |
| 1160 | size_t CodeGeneratorARM64::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 1161 | FPRegister reg = FPRegister(reg_id, kDRegSize); |
| 1162 | __ Str(reg, MemOperand(sp, stack_index)); |
| 1163 | return kArm64WordSize; |
| 1164 | } |
| 1165 | |
| 1166 | size_t CodeGeneratorARM64::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 1167 | FPRegister reg = FPRegister(reg_id, kDRegSize); |
| 1168 | __ Ldr(reg, MemOperand(sp, stack_index)); |
| 1169 | return kArm64WordSize; |
| 1170 | } |
| 1171 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1172 | void CodeGeneratorARM64::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1173 | stream << XRegister(reg); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1174 | } |
| 1175 | |
| 1176 | void CodeGeneratorARM64::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1177 | stream << DRegister(reg); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1178 | } |
| 1179 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1180 | void CodeGeneratorARM64::MoveConstant(CPURegister destination, HConstant* constant) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1181 | if (constant->IsIntConstant()) { |
| 1182 | __ Mov(Register(destination), constant->AsIntConstant()->GetValue()); |
| 1183 | } else if (constant->IsLongConstant()) { |
| 1184 | __ Mov(Register(destination), constant->AsLongConstant()->GetValue()); |
| 1185 | } else if (constant->IsNullConstant()) { |
| 1186 | __ Mov(Register(destination), 0); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1187 | } else if (constant->IsFloatConstant()) { |
| 1188 | __ Fmov(FPRegister(destination), constant->AsFloatConstant()->GetValue()); |
| 1189 | } else { |
| 1190 | DCHECK(constant->IsDoubleConstant()); |
| 1191 | __ Fmov(FPRegister(destination), constant->AsDoubleConstant()->GetValue()); |
| 1192 | } |
| 1193 | } |
| 1194 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1195 | |
| 1196 | static bool CoherentConstantAndType(Location constant, Primitive::Type type) { |
| 1197 | DCHECK(constant.IsConstant()); |
| 1198 | HConstant* cst = constant.GetConstant(); |
| 1199 | return (cst->IsIntConstant() && type == Primitive::kPrimInt) || |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1200 | // Null is mapped to a core W register, which we associate with kPrimInt. |
| 1201 | (cst->IsNullConstant() && type == Primitive::kPrimInt) || |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1202 | (cst->IsLongConstant() && type == Primitive::kPrimLong) || |
| 1203 | (cst->IsFloatConstant() && type == Primitive::kPrimFloat) || |
| 1204 | (cst->IsDoubleConstant() && type == Primitive::kPrimDouble); |
| 1205 | } |
| 1206 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1207 | void CodeGeneratorARM64::MoveLocation(Location destination, |
| 1208 | Location source, |
| 1209 | Primitive::Type dst_type) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1210 | if (source.Equals(destination)) { |
| 1211 | return; |
| 1212 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1213 | |
| 1214 | // A valid move can always be inferred from the destination and source |
| 1215 | // locations. When moving from and to a register, the argument type can be |
| 1216 | // used to generate 32bit instead of 64bit moves. In debug mode we also |
| 1217 | // checks the coherency of the locations and the type. |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1218 | bool unspecified_type = (dst_type == Primitive::kPrimVoid); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1219 | |
| 1220 | if (destination.IsRegister() || destination.IsFpuRegister()) { |
| 1221 | if (unspecified_type) { |
| 1222 | HConstant* src_cst = source.IsConstant() ? source.GetConstant() : nullptr; |
| 1223 | if (source.IsStackSlot() || |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1224 | (src_cst != nullptr && (src_cst->IsIntConstant() |
| 1225 | || src_cst->IsFloatConstant() |
| 1226 | || src_cst->IsNullConstant()))) { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1227 | // For stack slots and 32bit constants, a 64bit type is appropriate. |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1228 | dst_type = destination.IsRegister() ? Primitive::kPrimInt : Primitive::kPrimFloat; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1229 | } else { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1230 | // If the source is a double stack slot or a 64bit constant, a 64bit |
| 1231 | // type is appropriate. Else the source is a register, and since the |
| 1232 | // type has not been specified, we chose a 64bit type to force a 64bit |
| 1233 | // move. |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1234 | dst_type = destination.IsRegister() ? Primitive::kPrimLong : Primitive::kPrimDouble; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1235 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1236 | } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1237 | DCHECK((destination.IsFpuRegister() && Primitive::IsFloatingPointType(dst_type)) || |
| 1238 | (destination.IsRegister() && !Primitive::IsFloatingPointType(dst_type))); |
| 1239 | CPURegister dst = CPURegisterFrom(destination, dst_type); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1240 | if (source.IsStackSlot() || source.IsDoubleStackSlot()) { |
| 1241 | DCHECK(dst.Is64Bits() == source.IsDoubleStackSlot()); |
| 1242 | __ Ldr(dst, StackOperandFrom(source)); |
| 1243 | } else if (source.IsConstant()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1244 | DCHECK(CoherentConstantAndType(source, dst_type)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1245 | MoveConstant(dst, source.GetConstant()); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1246 | } else if (source.IsRegister()) { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1247 | if (destination.IsRegister()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1248 | __ Mov(Register(dst), RegisterFrom(source, dst_type)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1249 | } else { |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1250 | DCHECK(destination.IsFpuRegister()); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1251 | Primitive::Type source_type = Primitive::Is64BitType(dst_type) |
| 1252 | ? Primitive::kPrimLong |
| 1253 | : Primitive::kPrimInt; |
| 1254 | __ Fmov(FPRegisterFrom(destination, dst_type), RegisterFrom(source, source_type)); |
| 1255 | } |
| 1256 | } else { |
| 1257 | DCHECK(source.IsFpuRegister()); |
| 1258 | if (destination.IsRegister()) { |
| 1259 | Primitive::Type source_type = Primitive::Is64BitType(dst_type) |
| 1260 | ? Primitive::kPrimDouble |
| 1261 | : Primitive::kPrimFloat; |
| 1262 | __ Fmov(RegisterFrom(destination, dst_type), FPRegisterFrom(source, source_type)); |
| 1263 | } else { |
| 1264 | DCHECK(destination.IsFpuRegister()); |
| 1265 | __ Fmov(FPRegister(dst), FPRegisterFrom(source, dst_type)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1266 | } |
| 1267 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1268 | } else { // The destination is not a register. It must be a stack slot. |
| 1269 | DCHECK(destination.IsStackSlot() || destination.IsDoubleStackSlot()); |
| 1270 | if (source.IsRegister() || source.IsFpuRegister()) { |
| 1271 | if (unspecified_type) { |
| 1272 | if (source.IsRegister()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1273 | dst_type = destination.IsStackSlot() ? Primitive::kPrimInt : Primitive::kPrimLong; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1274 | } else { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1275 | dst_type = destination.IsStackSlot() ? Primitive::kPrimFloat : Primitive::kPrimDouble; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1276 | } |
| 1277 | } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1278 | DCHECK((destination.IsDoubleStackSlot() == Primitive::Is64BitType(dst_type)) && |
| 1279 | (source.IsFpuRegister() == Primitive::IsFloatingPointType(dst_type))); |
| 1280 | __ Str(CPURegisterFrom(source, dst_type), StackOperandFrom(destination)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1281 | } else if (source.IsConstant()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1282 | DCHECK(unspecified_type || CoherentConstantAndType(source, dst_type)) |
| 1283 | << source << " " << dst_type; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1284 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 1285 | HConstant* src_cst = source.GetConstant(); |
| 1286 | CPURegister temp; |
Alexandre Rames | b2b753c | 2016-08-02 13:45:28 +0100 | [diff] [blame] | 1287 | if (src_cst->IsZeroBitPattern()) { |
| 1288 | temp = (src_cst->IsLongConstant() || src_cst->IsDoubleConstant()) ? xzr : wzr; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1289 | } else { |
Alexandre Rames | b2b753c | 2016-08-02 13:45:28 +0100 | [diff] [blame] | 1290 | if (src_cst->IsIntConstant()) { |
| 1291 | temp = temps.AcquireW(); |
| 1292 | } else if (src_cst->IsLongConstant()) { |
| 1293 | temp = temps.AcquireX(); |
| 1294 | } else if (src_cst->IsFloatConstant()) { |
| 1295 | temp = temps.AcquireS(); |
| 1296 | } else { |
| 1297 | DCHECK(src_cst->IsDoubleConstant()); |
| 1298 | temp = temps.AcquireD(); |
| 1299 | } |
| 1300 | MoveConstant(temp, src_cst); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1301 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1302 | __ Str(temp, StackOperandFrom(destination)); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1303 | } else { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1304 | DCHECK(source.IsStackSlot() || source.IsDoubleStackSlot()); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1305 | DCHECK(source.IsDoubleStackSlot() == destination.IsDoubleStackSlot()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1306 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1307 | // There is generally less pressure on FP registers. |
| 1308 | FPRegister temp = destination.IsDoubleStackSlot() ? temps.AcquireD() : temps.AcquireS(); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1309 | __ Ldr(temp, StackOperandFrom(source)); |
| 1310 | __ Str(temp, StackOperandFrom(destination)); |
| 1311 | } |
| 1312 | } |
| 1313 | } |
| 1314 | |
| 1315 | void CodeGeneratorARM64::Load(Primitive::Type type, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1316 | CPURegister dst, |
| 1317 | const MemOperand& src) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1318 | switch (type) { |
| 1319 | case Primitive::kPrimBoolean: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1320 | __ Ldrb(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1321 | break; |
| 1322 | case Primitive::kPrimByte: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1323 | __ Ldrsb(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1324 | break; |
| 1325 | case Primitive::kPrimShort: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1326 | __ Ldrsh(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1327 | break; |
| 1328 | case Primitive::kPrimChar: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1329 | __ Ldrh(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1330 | break; |
| 1331 | case Primitive::kPrimInt: |
| 1332 | case Primitive::kPrimNot: |
| 1333 | case Primitive::kPrimLong: |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1334 | case Primitive::kPrimFloat: |
| 1335 | case Primitive::kPrimDouble: |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 1336 | DCHECK_EQ(dst.Is64Bits(), Primitive::Is64BitType(type)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1337 | __ Ldr(dst, src); |
| 1338 | break; |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1339 | case Primitive::kPrimVoid: |
| 1340 | LOG(FATAL) << "Unreachable type " << type; |
| 1341 | } |
| 1342 | } |
| 1343 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1344 | void CodeGeneratorARM64::LoadAcquire(HInstruction* instruction, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1345 | CPURegister dst, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1346 | const MemOperand& src, |
| 1347 | bool needs_null_check) { |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1348 | MacroAssembler* masm = GetVIXLAssembler(); |
| 1349 | BlockPoolsScope block_pools(masm); |
| 1350 | UseScratchRegisterScope temps(masm); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1351 | Register temp_base = temps.AcquireX(); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1352 | Primitive::Type type = instruction->GetType(); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1353 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1354 | DCHECK(!src.IsPreIndex()); |
| 1355 | DCHECK(!src.IsPostIndex()); |
| 1356 | |
| 1357 | // TODO(vixl): Let the MacroAssembler handle MemOperand. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1358 | __ Add(temp_base, src.GetBaseRegister(), OperandFromMemOperand(src)); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1359 | MemOperand base = MemOperand(temp_base); |
| 1360 | switch (type) { |
| 1361 | case Primitive::kPrimBoolean: |
| 1362 | __ Ldarb(Register(dst), base); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1363 | if (needs_null_check) { |
| 1364 | MaybeRecordImplicitNullCheck(instruction); |
| 1365 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1366 | break; |
| 1367 | case Primitive::kPrimByte: |
| 1368 | __ Ldarb(Register(dst), base); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1369 | if (needs_null_check) { |
| 1370 | MaybeRecordImplicitNullCheck(instruction); |
| 1371 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1372 | __ Sbfx(Register(dst), Register(dst), 0, Primitive::ComponentSize(type) * kBitsPerByte); |
| 1373 | break; |
| 1374 | case Primitive::kPrimChar: |
| 1375 | __ Ldarh(Register(dst), base); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1376 | if (needs_null_check) { |
| 1377 | MaybeRecordImplicitNullCheck(instruction); |
| 1378 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1379 | break; |
| 1380 | case Primitive::kPrimShort: |
| 1381 | __ Ldarh(Register(dst), base); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1382 | if (needs_null_check) { |
| 1383 | MaybeRecordImplicitNullCheck(instruction); |
| 1384 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1385 | __ Sbfx(Register(dst), Register(dst), 0, Primitive::ComponentSize(type) * kBitsPerByte); |
| 1386 | break; |
| 1387 | case Primitive::kPrimInt: |
| 1388 | case Primitive::kPrimNot: |
| 1389 | case Primitive::kPrimLong: |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 1390 | DCHECK_EQ(dst.Is64Bits(), Primitive::Is64BitType(type)); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1391 | __ Ldar(Register(dst), base); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1392 | if (needs_null_check) { |
| 1393 | MaybeRecordImplicitNullCheck(instruction); |
| 1394 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1395 | break; |
| 1396 | case Primitive::kPrimFloat: |
| 1397 | case Primitive::kPrimDouble: { |
| 1398 | DCHECK(dst.IsFPRegister()); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 1399 | DCHECK_EQ(dst.Is64Bits(), Primitive::Is64BitType(type)); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1400 | |
| 1401 | Register temp = dst.Is64Bits() ? temps.AcquireX() : temps.AcquireW(); |
| 1402 | __ Ldar(temp, base); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1403 | if (needs_null_check) { |
| 1404 | MaybeRecordImplicitNullCheck(instruction); |
| 1405 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1406 | __ Fmov(FPRegister(dst), temp); |
| 1407 | break; |
| 1408 | } |
| 1409 | case Primitive::kPrimVoid: |
| 1410 | LOG(FATAL) << "Unreachable type " << type; |
| 1411 | } |
| 1412 | } |
| 1413 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1414 | void CodeGeneratorARM64::Store(Primitive::Type type, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1415 | CPURegister src, |
| 1416 | const MemOperand& dst) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1417 | switch (type) { |
| 1418 | case Primitive::kPrimBoolean: |
| 1419 | case Primitive::kPrimByte: |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1420 | __ Strb(Register(src), dst); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1421 | break; |
| 1422 | case Primitive::kPrimChar: |
| 1423 | case Primitive::kPrimShort: |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1424 | __ Strh(Register(src), dst); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1425 | break; |
| 1426 | case Primitive::kPrimInt: |
| 1427 | case Primitive::kPrimNot: |
| 1428 | case Primitive::kPrimLong: |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1429 | case Primitive::kPrimFloat: |
| 1430 | case Primitive::kPrimDouble: |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 1431 | DCHECK_EQ(src.Is64Bits(), Primitive::Is64BitType(type)); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1432 | __ Str(src, dst); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1433 | break; |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1434 | case Primitive::kPrimVoid: |
| 1435 | LOG(FATAL) << "Unreachable type " << type; |
| 1436 | } |
| 1437 | } |
| 1438 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1439 | void CodeGeneratorARM64::StoreRelease(Primitive::Type type, |
| 1440 | CPURegister src, |
| 1441 | const MemOperand& dst) { |
| 1442 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 1443 | Register temp_base = temps.AcquireX(); |
| 1444 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1445 | DCHECK(!dst.IsPreIndex()); |
| 1446 | DCHECK(!dst.IsPostIndex()); |
| 1447 | |
| 1448 | // TODO(vixl): Let the MacroAssembler handle this. |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 1449 | Operand op = OperandFromMemOperand(dst); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1450 | __ Add(temp_base, dst.GetBaseRegister(), op); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1451 | MemOperand base = MemOperand(temp_base); |
| 1452 | switch (type) { |
| 1453 | case Primitive::kPrimBoolean: |
| 1454 | case Primitive::kPrimByte: |
| 1455 | __ Stlrb(Register(src), base); |
| 1456 | break; |
| 1457 | case Primitive::kPrimChar: |
| 1458 | case Primitive::kPrimShort: |
| 1459 | __ Stlrh(Register(src), base); |
| 1460 | break; |
| 1461 | case Primitive::kPrimInt: |
| 1462 | case Primitive::kPrimNot: |
| 1463 | case Primitive::kPrimLong: |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 1464 | DCHECK_EQ(src.Is64Bits(), Primitive::Is64BitType(type)); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1465 | __ Stlr(Register(src), base); |
| 1466 | break; |
| 1467 | case Primitive::kPrimFloat: |
| 1468 | case Primitive::kPrimDouble: { |
| 1469 | DCHECK(src.IsFPRegister()); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 1470 | DCHECK_EQ(src.Is64Bits(), Primitive::Is64BitType(type)); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1471 | |
| 1472 | Register temp = src.Is64Bits() ? temps.AcquireX() : temps.AcquireW(); |
| 1473 | __ Fmov(temp, FPRegister(src)); |
| 1474 | __ Stlr(temp, base); |
| 1475 | break; |
| 1476 | } |
| 1477 | case Primitive::kPrimVoid: |
| 1478 | LOG(FATAL) << "Unreachable type " << type; |
| 1479 | } |
| 1480 | } |
| 1481 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1482 | void CodeGeneratorARM64::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 1483 | HInstruction* instruction, |
| 1484 | uint32_t dex_pc, |
| 1485 | SlowPathCode* slow_path) { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1486 | InvokeRuntime(GetThreadOffset<kArm64PointerSize>(entrypoint).Int32Value(), |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1487 | instruction, |
| 1488 | dex_pc, |
| 1489 | slow_path); |
| 1490 | } |
| 1491 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1492 | void CodeGeneratorARM64::InvokeRuntime(int32_t entry_point_offset, |
| 1493 | HInstruction* instruction, |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 1494 | uint32_t dex_pc, |
| 1495 | SlowPathCode* slow_path) { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1496 | ValidateInvokeRuntime(instruction, slow_path); |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1497 | BlockPoolsScope block_pools(GetVIXLAssembler()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1498 | __ Ldr(lr, MemOperand(tr, entry_point_offset)); |
| 1499 | __ Blr(lr); |
Roland Levillain | 896e32d | 2015-05-05 18:07:10 +0100 | [diff] [blame] | 1500 | RecordPcInfo(instruction, dex_pc, slow_path); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1501 | } |
| 1502 | |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 1503 | void CodeGeneratorARM64::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 1504 | HInstruction* instruction, |
| 1505 | SlowPathCode* slow_path) { |
| 1506 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
| 1507 | BlockPoolsScope block_pools(GetVIXLAssembler()); |
| 1508 | __ Ldr(lr, MemOperand(tr, entry_point_offset)); |
| 1509 | __ Blr(lr); |
| 1510 | } |
| 1511 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1512 | void InstructionCodeGeneratorARM64::GenerateClassInitializationCheck(SlowPathCodeARM64* slow_path, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1513 | Register class_reg) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1514 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 1515 | Register temp = temps.AcquireW(); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1516 | size_t status_offset = mirror::Class::StatusOffset().SizeValue(); |
| 1517 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1518 | // Even if the initialized flag is set, we need to ensure consistent memory ordering. |
Serban Constantinescu | 4a6a67c | 2016-01-27 09:19:56 +0000 | [diff] [blame] | 1519 | // TODO(vixl): Let the MacroAssembler handle MemOperand. |
| 1520 | __ Add(temp, class_reg, status_offset); |
| 1521 | __ Ldar(temp, HeapOperand(temp)); |
| 1522 | __ Cmp(temp, mirror::Class::kStatusInitialized); |
| 1523 | __ B(lt, slow_path->GetEntryLabel()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1524 | __ Bind(slow_path->GetExitLabel()); |
| 1525 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1526 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1527 | void CodeGeneratorARM64::GenerateMemoryBarrier(MemBarrierKind kind) { |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1528 | BarrierType type = BarrierAll; |
| 1529 | |
| 1530 | switch (kind) { |
| 1531 | case MemBarrierKind::kAnyAny: |
| 1532 | case MemBarrierKind::kAnyStore: { |
| 1533 | type = BarrierAll; |
| 1534 | break; |
| 1535 | } |
| 1536 | case MemBarrierKind::kLoadAny: { |
| 1537 | type = BarrierReads; |
| 1538 | break; |
| 1539 | } |
| 1540 | case MemBarrierKind::kStoreStore: { |
| 1541 | type = BarrierWrites; |
| 1542 | break; |
| 1543 | } |
| 1544 | default: |
| 1545 | LOG(FATAL) << "Unexpected memory barrier " << kind; |
| 1546 | } |
| 1547 | __ Dmb(InnerShareable, type); |
| 1548 | } |
| 1549 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1550 | void InstructionCodeGeneratorARM64::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 1551 | HBasicBlock* successor) { |
| 1552 | SuspendCheckSlowPathARM64* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 1553 | down_cast<SuspendCheckSlowPathARM64*>(instruction->GetSlowPath()); |
| 1554 | if (slow_path == nullptr) { |
| 1555 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathARM64(instruction, successor); |
| 1556 | instruction->SetSlowPath(slow_path); |
| 1557 | codegen_->AddSlowPath(slow_path); |
| 1558 | if (successor != nullptr) { |
| 1559 | DCHECK(successor->IsLoopHeader()); |
| 1560 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 1561 | } |
| 1562 | } else { |
| 1563 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 1564 | } |
| 1565 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1566 | UseScratchRegisterScope temps(codegen_->GetVIXLAssembler()); |
| 1567 | Register temp = temps.AcquireW(); |
| 1568 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1569 | __ Ldrh(temp, MemOperand(tr, Thread::ThreadFlagsOffset<kArm64PointerSize>().SizeValue())); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1570 | if (successor == nullptr) { |
| 1571 | __ Cbnz(temp, slow_path->GetEntryLabel()); |
| 1572 | __ Bind(slow_path->GetReturnLabel()); |
| 1573 | } else { |
| 1574 | __ Cbz(temp, codegen_->GetLabelOf(successor)); |
| 1575 | __ B(slow_path->GetEntryLabel()); |
| 1576 | // slow_path will return to GetLabelOf(successor). |
| 1577 | } |
| 1578 | } |
| 1579 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1580 | InstructionCodeGeneratorARM64::InstructionCodeGeneratorARM64(HGraph* graph, |
| 1581 | CodeGeneratorARM64* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1582 | : InstructionCodeGenerator(graph, codegen), |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1583 | assembler_(codegen->GetAssembler()), |
| 1584 | codegen_(codegen) {} |
| 1585 | |
| 1586 | #define FOR_EACH_UNIMPLEMENTED_INSTRUCTION(M) \ |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1587 | /* No unimplemented IR. */ |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1588 | |
| 1589 | #define UNIMPLEMENTED_INSTRUCTION_BREAK_CODE(name) name##UnimplementedInstructionBreakCode |
| 1590 | |
| 1591 | enum UnimplementedInstructionBreakCode { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1592 | // Using a base helps identify when we hit such breakpoints. |
| 1593 | UnimplementedInstructionBreakCodeBaseCode = 0x900, |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1594 | #define ENUM_UNIMPLEMENTED_INSTRUCTION(name) UNIMPLEMENTED_INSTRUCTION_BREAK_CODE(name), |
| 1595 | FOR_EACH_UNIMPLEMENTED_INSTRUCTION(ENUM_UNIMPLEMENTED_INSTRUCTION) |
| 1596 | #undef ENUM_UNIMPLEMENTED_INSTRUCTION |
| 1597 | }; |
| 1598 | |
| 1599 | #define DEFINE_UNIMPLEMENTED_INSTRUCTION_VISITORS(name) \ |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1600 | void InstructionCodeGeneratorARM64::Visit##name(H##name* instr ATTRIBUTE_UNUSED) { \ |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1601 | __ Brk(UNIMPLEMENTED_INSTRUCTION_BREAK_CODE(name)); \ |
| 1602 | } \ |
| 1603 | void LocationsBuilderARM64::Visit##name(H##name* instr) { \ |
| 1604 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr); \ |
| 1605 | locations->SetOut(Location::Any()); \ |
| 1606 | } |
| 1607 | FOR_EACH_UNIMPLEMENTED_INSTRUCTION(DEFINE_UNIMPLEMENTED_INSTRUCTION_VISITORS) |
| 1608 | #undef DEFINE_UNIMPLEMENTED_INSTRUCTION_VISITORS |
| 1609 | |
| 1610 | #undef UNIMPLEMENTED_INSTRUCTION_BREAK_CODE |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1611 | #undef FOR_EACH_UNIMPLEMENTED_INSTRUCTION |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1612 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1613 | void LocationsBuilderARM64::HandleBinaryOp(HBinaryOperation* instr) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1614 | DCHECK_EQ(instr->InputCount(), 2U); |
| 1615 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr); |
| 1616 | Primitive::Type type = instr->GetResultType(); |
| 1617 | switch (type) { |
| 1618 | case Primitive::kPrimInt: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1619 | case Primitive::kPrimLong: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1620 | locations->SetInAt(0, Location::RequiresRegister()); |
Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 1621 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instr->InputAt(1), instr)); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 1622 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1623 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1624 | |
| 1625 | case Primitive::kPrimFloat: |
| 1626 | case Primitive::kPrimDouble: |
| 1627 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1628 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1629 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1630 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1631 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1632 | default: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1633 | LOG(FATAL) << "Unexpected " << instr->DebugName() << " type " << type; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1634 | } |
| 1635 | } |
| 1636 | |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1637 | void LocationsBuilderARM64::HandleFieldGet(HInstruction* instruction) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1638 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 1639 | |
| 1640 | bool object_field_get_with_read_barrier = |
| 1641 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1642 | LocationSummary* locations = |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1643 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 1644 | object_field_get_with_read_barrier ? |
| 1645 | LocationSummary::kCallOnSlowPath : |
| 1646 | LocationSummary::kNoCall); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1647 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1648 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 1649 | locations->SetOut(Location::RequiresFpuRegister()); |
| 1650 | } else { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1651 | // The output overlaps for an object field get when read barriers |
| 1652 | // are enabled: we do not want the load to overwrite the object's |
| 1653 | // location, as we need it to emit the read barrier. |
| 1654 | locations->SetOut( |
| 1655 | Location::RequiresRegister(), |
| 1656 | object_field_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1657 | } |
| 1658 | } |
| 1659 | |
| 1660 | void InstructionCodeGeneratorARM64::HandleFieldGet(HInstruction* instruction, |
| 1661 | const FieldInfo& field_info) { |
| 1662 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1663 | LocationSummary* locations = instruction->GetLocations(); |
| 1664 | Location base_loc = locations->InAt(0); |
| 1665 | Location out = locations->Out(); |
| 1666 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1667 | Primitive::Type field_type = field_info.GetFieldType(); |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1668 | BlockPoolsScope block_pools(GetVIXLAssembler()); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1669 | MemOperand field = HeapOperand(InputRegisterAt(instruction, 0), field_info.GetFieldOffset()); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1670 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1671 | if (field_type == Primitive::kPrimNot && kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 1672 | // Object FieldGet with Baker's read barrier case. |
| 1673 | MacroAssembler* masm = GetVIXLAssembler(); |
| 1674 | UseScratchRegisterScope temps(masm); |
| 1675 | // /* HeapReference<Object> */ out = *(base + offset) |
| 1676 | Register base = RegisterFrom(base_loc, Primitive::kPrimNot); |
| 1677 | Register temp = temps.AcquireW(); |
| 1678 | // Note that potential implicit null checks are handled in this |
| 1679 | // CodeGeneratorARM64::GenerateFieldLoadWithBakerReadBarrier call. |
| 1680 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 1681 | instruction, |
| 1682 | out, |
| 1683 | base, |
| 1684 | offset, |
| 1685 | temp, |
| 1686 | /* needs_null_check */ true, |
Serban Constantinescu | 4a6a67c | 2016-01-27 09:19:56 +0000 | [diff] [blame] | 1687 | field_info.IsVolatile()); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1688 | } else { |
| 1689 | // General case. |
| 1690 | if (field_info.IsVolatile()) { |
Serban Constantinescu | 4a6a67c | 2016-01-27 09:19:56 +0000 | [diff] [blame] | 1691 | // Note that a potential implicit null check is handled in this |
| 1692 | // CodeGeneratorARM64::LoadAcquire call. |
| 1693 | // NB: LoadAcquire will record the pc info if needed. |
| 1694 | codegen_->LoadAcquire( |
| 1695 | instruction, OutputCPURegister(instruction), field, /* needs_null_check */ true); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1696 | } else { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1697 | codegen_->Load(field_type, OutputCPURegister(instruction), field); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1698 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1699 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1700 | if (field_type == Primitive::kPrimNot) { |
| 1701 | // If read barriers are enabled, emit read barriers other than |
| 1702 | // Baker's using a slow path (and also unpoison the loaded |
| 1703 | // reference, if heap poisoning is enabled). |
| 1704 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 1705 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1706 | } |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1707 | } |
| 1708 | |
| 1709 | void LocationsBuilderARM64::HandleFieldSet(HInstruction* instruction) { |
| 1710 | LocationSummary* locations = |
| 1711 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 1712 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1713 | if (Primitive::IsFloatingPointType(instruction->InputAt(1)->GetType())) { |
| 1714 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1715 | } else { |
| 1716 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1717 | } |
| 1718 | } |
| 1719 | |
| 1720 | void InstructionCodeGeneratorARM64::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1721 | const FieldInfo& field_info, |
| 1722 | bool value_can_be_null) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1723 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1724 | BlockPoolsScope block_pools(GetVIXLAssembler()); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1725 | |
| 1726 | Register obj = InputRegisterAt(instruction, 0); |
| 1727 | CPURegister value = InputCPURegisterAt(instruction, 1); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1728 | CPURegister source = value; |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1729 | Offset offset = field_info.GetFieldOffset(); |
| 1730 | Primitive::Type field_type = field_info.GetFieldType(); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1731 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1732 | { |
| 1733 | // We use a block to end the scratch scope before the write barrier, thus |
| 1734 | // freeing the temporary registers so they can be used in `MarkGCCard`. |
| 1735 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 1736 | |
| 1737 | if (kPoisonHeapReferences && field_type == Primitive::kPrimNot) { |
| 1738 | DCHECK(value.IsW()); |
| 1739 | Register temp = temps.AcquireW(); |
| 1740 | __ Mov(temp, value.W()); |
| 1741 | GetAssembler()->PoisonHeapReference(temp.W()); |
| 1742 | source = temp; |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1743 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1744 | |
| 1745 | if (field_info.IsVolatile()) { |
Serban Constantinescu | 4a6a67c | 2016-01-27 09:19:56 +0000 | [diff] [blame] | 1746 | codegen_->StoreRelease(field_type, source, HeapOperand(obj, offset)); |
| 1747 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1748 | } else { |
| 1749 | codegen_->Store(field_type, source, HeapOperand(obj, offset)); |
| 1750 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 1751 | } |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1752 | } |
| 1753 | |
| 1754 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1755 | codegen_->MarkGCCard(obj, Register(value), value_can_be_null); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1756 | } |
| 1757 | } |
| 1758 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1759 | void InstructionCodeGeneratorARM64::HandleBinaryOp(HBinaryOperation* instr) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1760 | Primitive::Type type = instr->GetType(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1761 | |
| 1762 | switch (type) { |
| 1763 | case Primitive::kPrimInt: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1764 | case Primitive::kPrimLong: { |
| 1765 | Register dst = OutputRegister(instr); |
| 1766 | Register lhs = InputRegisterAt(instr, 0); |
| 1767 | Operand rhs = InputOperandAt(instr, 1); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1768 | if (instr->IsAdd()) { |
| 1769 | __ Add(dst, lhs, rhs); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1770 | } else if (instr->IsAnd()) { |
| 1771 | __ And(dst, lhs, rhs); |
| 1772 | } else if (instr->IsOr()) { |
| 1773 | __ Orr(dst, lhs, rhs); |
| 1774 | } else if (instr->IsSub()) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1775 | __ Sub(dst, lhs, rhs); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 1776 | } else if (instr->IsRor()) { |
| 1777 | if (rhs.IsImmediate()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1778 | uint32_t shift = rhs.GetImmediate() & (lhs.GetSizeInBits() - 1); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 1779 | __ Ror(dst, lhs, shift); |
| 1780 | } else { |
| 1781 | // Ensure shift distance is in the same size register as the result. If |
| 1782 | // we are rotating a long and the shift comes in a w register originally, |
| 1783 | // we don't need to sxtw for use as an x since the shift distances are |
| 1784 | // all & reg_bits - 1. |
| 1785 | __ Ror(dst, lhs, RegisterFrom(instr->GetLocations()->InAt(1), type)); |
| 1786 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1787 | } else { |
| 1788 | DCHECK(instr->IsXor()); |
| 1789 | __ Eor(dst, lhs, rhs); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1790 | } |
| 1791 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1792 | } |
| 1793 | case Primitive::kPrimFloat: |
| 1794 | case Primitive::kPrimDouble: { |
| 1795 | FPRegister dst = OutputFPRegister(instr); |
| 1796 | FPRegister lhs = InputFPRegisterAt(instr, 0); |
| 1797 | FPRegister rhs = InputFPRegisterAt(instr, 1); |
| 1798 | if (instr->IsAdd()) { |
| 1799 | __ Fadd(dst, lhs, rhs); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1800 | } else if (instr->IsSub()) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1801 | __ Fsub(dst, lhs, rhs); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1802 | } else { |
| 1803 | LOG(FATAL) << "Unexpected floating-point binary operation"; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1804 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1805 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1806 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1807 | default: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1808 | LOG(FATAL) << "Unexpected binary operation type " << type; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1809 | } |
| 1810 | } |
| 1811 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1812 | void LocationsBuilderARM64::HandleShift(HBinaryOperation* instr) { |
| 1813 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr()); |
| 1814 | |
| 1815 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr); |
| 1816 | Primitive::Type type = instr->GetResultType(); |
| 1817 | switch (type) { |
| 1818 | case Primitive::kPrimInt: |
| 1819 | case Primitive::kPrimLong: { |
| 1820 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1821 | locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1))); |
| 1822 | locations->SetOut(Location::RequiresRegister()); |
| 1823 | break; |
| 1824 | } |
| 1825 | default: |
| 1826 | LOG(FATAL) << "Unexpected shift type " << type; |
| 1827 | } |
| 1828 | } |
| 1829 | |
| 1830 | void InstructionCodeGeneratorARM64::HandleShift(HBinaryOperation* instr) { |
| 1831 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr()); |
| 1832 | |
| 1833 | Primitive::Type type = instr->GetType(); |
| 1834 | switch (type) { |
| 1835 | case Primitive::kPrimInt: |
| 1836 | case Primitive::kPrimLong: { |
| 1837 | Register dst = OutputRegister(instr); |
| 1838 | Register lhs = InputRegisterAt(instr, 0); |
| 1839 | Operand rhs = InputOperandAt(instr, 1); |
| 1840 | if (rhs.IsImmediate()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1841 | uint32_t shift_value = rhs.GetImmediate() & |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 1842 | (type == Primitive::kPrimInt ? kMaxIntShiftDistance : kMaxLongShiftDistance); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1843 | if (instr->IsShl()) { |
| 1844 | __ Lsl(dst, lhs, shift_value); |
| 1845 | } else if (instr->IsShr()) { |
| 1846 | __ Asr(dst, lhs, shift_value); |
| 1847 | } else { |
| 1848 | __ Lsr(dst, lhs, shift_value); |
| 1849 | } |
| 1850 | } else { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1851 | Register rhs_reg = dst.IsX() ? rhs.GetRegister().X() : rhs.GetRegister().W(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1852 | |
| 1853 | if (instr->IsShl()) { |
| 1854 | __ Lsl(dst, lhs, rhs_reg); |
| 1855 | } else if (instr->IsShr()) { |
| 1856 | __ Asr(dst, lhs, rhs_reg); |
| 1857 | } else { |
| 1858 | __ Lsr(dst, lhs, rhs_reg); |
| 1859 | } |
| 1860 | } |
| 1861 | break; |
| 1862 | } |
| 1863 | default: |
| 1864 | LOG(FATAL) << "Unexpected shift operation type " << type; |
| 1865 | } |
| 1866 | } |
| 1867 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1868 | void LocationsBuilderARM64::VisitAdd(HAdd* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1869 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1870 | } |
| 1871 | |
| 1872 | void InstructionCodeGeneratorARM64::VisitAdd(HAdd* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1873 | HandleBinaryOp(instruction); |
| 1874 | } |
| 1875 | |
| 1876 | void LocationsBuilderARM64::VisitAnd(HAnd* instruction) { |
| 1877 | HandleBinaryOp(instruction); |
| 1878 | } |
| 1879 | |
| 1880 | void InstructionCodeGeneratorARM64::VisitAnd(HAnd* instruction) { |
| 1881 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1882 | } |
| 1883 | |
Artem Serov | 7fc6350 | 2016-02-09 17:15:29 +0000 | [diff] [blame] | 1884 | void LocationsBuilderARM64::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instr) { |
Kevin Brodsky | 9ff0d20 | 2016-01-11 13:43:31 +0000 | [diff] [blame] | 1885 | DCHECK(Primitive::IsIntegralType(instr->GetType())) << instr->GetType(); |
| 1886 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr); |
| 1887 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1888 | // There is no immediate variant of negated bitwise instructions in AArch64. |
| 1889 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1890 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1891 | } |
| 1892 | |
Artem Serov | 7fc6350 | 2016-02-09 17:15:29 +0000 | [diff] [blame] | 1893 | void InstructionCodeGeneratorARM64::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instr) { |
Kevin Brodsky | 9ff0d20 | 2016-01-11 13:43:31 +0000 | [diff] [blame] | 1894 | Register dst = OutputRegister(instr); |
| 1895 | Register lhs = InputRegisterAt(instr, 0); |
| 1896 | Register rhs = InputRegisterAt(instr, 1); |
| 1897 | |
| 1898 | switch (instr->GetOpKind()) { |
| 1899 | case HInstruction::kAnd: |
| 1900 | __ Bic(dst, lhs, rhs); |
| 1901 | break; |
| 1902 | case HInstruction::kOr: |
| 1903 | __ Orn(dst, lhs, rhs); |
| 1904 | break; |
| 1905 | case HInstruction::kXor: |
| 1906 | __ Eon(dst, lhs, rhs); |
| 1907 | break; |
| 1908 | default: |
| 1909 | LOG(FATAL) << "Unreachable"; |
| 1910 | } |
| 1911 | } |
| 1912 | |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 1913 | void LocationsBuilderARM64::VisitArm64DataProcWithShifterOp( |
| 1914 | HArm64DataProcWithShifterOp* instruction) { |
| 1915 | DCHECK(instruction->GetType() == Primitive::kPrimInt || |
| 1916 | instruction->GetType() == Primitive::kPrimLong); |
| 1917 | LocationSummary* locations = |
| 1918 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 1919 | if (instruction->GetInstrKind() == HInstruction::kNeg) { |
| 1920 | locations->SetInAt(0, Location::ConstantLocation(instruction->InputAt(0)->AsConstant())); |
| 1921 | } else { |
| 1922 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1923 | } |
| 1924 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1925 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1926 | } |
| 1927 | |
| 1928 | void InstructionCodeGeneratorARM64::VisitArm64DataProcWithShifterOp( |
| 1929 | HArm64DataProcWithShifterOp* instruction) { |
| 1930 | Primitive::Type type = instruction->GetType(); |
| 1931 | HInstruction::InstructionKind kind = instruction->GetInstrKind(); |
| 1932 | DCHECK(type == Primitive::kPrimInt || type == Primitive::kPrimLong); |
| 1933 | Register out = OutputRegister(instruction); |
| 1934 | Register left; |
| 1935 | if (kind != HInstruction::kNeg) { |
| 1936 | left = InputRegisterAt(instruction, 0); |
| 1937 | } |
| 1938 | // If this `HArm64DataProcWithShifterOp` was created by merging a type conversion as the |
| 1939 | // shifter operand operation, the IR generating `right_reg` (input to the type |
| 1940 | // conversion) can have a different type from the current instruction's type, |
| 1941 | // so we manually indicate the type. |
| 1942 | Register right_reg = RegisterFrom(instruction->GetLocations()->InAt(1), type); |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 1943 | int64_t shift_amount = instruction->GetShiftAmount() & |
| 1944 | (type == Primitive::kPrimInt ? kMaxIntShiftDistance : kMaxLongShiftDistance); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 1945 | |
| 1946 | Operand right_operand(0); |
| 1947 | |
| 1948 | HArm64DataProcWithShifterOp::OpKind op_kind = instruction->GetOpKind(); |
| 1949 | if (HArm64DataProcWithShifterOp::IsExtensionOp(op_kind)) { |
| 1950 | right_operand = Operand(right_reg, helpers::ExtendFromOpKind(op_kind)); |
| 1951 | } else { |
| 1952 | right_operand = Operand(right_reg, helpers::ShiftFromOpKind(op_kind), shift_amount); |
| 1953 | } |
| 1954 | |
| 1955 | // Logical binary operations do not support extension operations in the |
| 1956 | // operand. Note that VIXL would still manage if it was passed by generating |
| 1957 | // the extension as a separate instruction. |
| 1958 | // `HNeg` also does not support extension. See comments in `ShifterOperandSupportsExtension()`. |
| 1959 | DCHECK(!right_operand.IsExtendedRegister() || |
| 1960 | (kind != HInstruction::kAnd && kind != HInstruction::kOr && kind != HInstruction::kXor && |
| 1961 | kind != HInstruction::kNeg)); |
| 1962 | switch (kind) { |
| 1963 | case HInstruction::kAdd: |
| 1964 | __ Add(out, left, right_operand); |
| 1965 | break; |
| 1966 | case HInstruction::kAnd: |
| 1967 | __ And(out, left, right_operand); |
| 1968 | break; |
| 1969 | case HInstruction::kNeg: |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1970 | DCHECK(instruction->InputAt(0)->AsConstant()->IsArithmeticZero()); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 1971 | __ Neg(out, right_operand); |
| 1972 | break; |
| 1973 | case HInstruction::kOr: |
| 1974 | __ Orr(out, left, right_operand); |
| 1975 | break; |
| 1976 | case HInstruction::kSub: |
| 1977 | __ Sub(out, left, right_operand); |
| 1978 | break; |
| 1979 | case HInstruction::kXor: |
| 1980 | __ Eor(out, left, right_operand); |
| 1981 | break; |
| 1982 | default: |
| 1983 | LOG(FATAL) << "Unexpected operation kind: " << kind; |
| 1984 | UNREACHABLE(); |
| 1985 | } |
| 1986 | } |
| 1987 | |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 1988 | void LocationsBuilderARM64::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
Roland Levillain | 4a3aa57 | 2016-08-15 13:17:06 +0000 | [diff] [blame] | 1989 | // The read barrier instrumentation does not support the HIntermediateAddress instruction yet. |
| 1990 | DCHECK(!kEmitCompilerReadBarrier); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1991 | LocationSummary* locations = |
| 1992 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 1993 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1994 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->GetOffset(), instruction)); |
| 1995 | locations->SetOut(Location::RequiresRegister()); |
| 1996 | } |
| 1997 | |
Roland Levillain | 4a3aa57 | 2016-08-15 13:17:06 +0000 | [diff] [blame] | 1998 | void InstructionCodeGeneratorARM64::VisitIntermediateAddress( |
| 1999 | HIntermediateAddress* instruction) { |
| 2000 | // The read barrier instrumentation does not support the HIntermediateAddress instruction yet. |
| 2001 | DCHECK(!kEmitCompilerReadBarrier); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2002 | __ Add(OutputRegister(instruction), |
| 2003 | InputRegisterAt(instruction, 0), |
| 2004 | Operand(InputOperandAt(instruction, 1))); |
| 2005 | } |
| 2006 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2007 | void LocationsBuilderARM64::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2008 | LocationSummary* locations = |
| 2009 | new (GetGraph()->GetArena()) LocationSummary(instr, LocationSummary::kNoCall); |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2010 | HInstruction* accumulator = instr->InputAt(HMultiplyAccumulate::kInputAccumulatorIndex); |
| 2011 | if (instr->GetOpKind() == HInstruction::kSub && |
| 2012 | accumulator->IsConstant() && |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2013 | accumulator->AsConstant()->IsArithmeticZero()) { |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2014 | // Don't allocate register for Mneg instruction. |
| 2015 | } else { |
| 2016 | locations->SetInAt(HMultiplyAccumulate::kInputAccumulatorIndex, |
| 2017 | Location::RequiresRegister()); |
| 2018 | } |
| 2019 | locations->SetInAt(HMultiplyAccumulate::kInputMulLeftIndex, Location::RequiresRegister()); |
| 2020 | locations->SetInAt(HMultiplyAccumulate::kInputMulRightIndex, Location::RequiresRegister()); |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2021 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2022 | } |
| 2023 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2024 | void InstructionCodeGeneratorARM64::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2025 | Register res = OutputRegister(instr); |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2026 | Register mul_left = InputRegisterAt(instr, HMultiplyAccumulate::kInputMulLeftIndex); |
| 2027 | Register mul_right = InputRegisterAt(instr, HMultiplyAccumulate::kInputMulRightIndex); |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2028 | |
| 2029 | // Avoid emitting code that could trigger Cortex A53's erratum 835769. |
| 2030 | // This fixup should be carried out for all multiply-accumulate instructions: |
| 2031 | // madd, msub, smaddl, smsubl, umaddl and umsubl. |
| 2032 | if (instr->GetType() == Primitive::kPrimLong && |
| 2033 | codegen_->GetInstructionSetFeatures().NeedFixCortexA53_835769()) { |
| 2034 | MacroAssembler* masm = down_cast<CodeGeneratorARM64*>(codegen_)->GetVIXLAssembler(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2035 | vixl::aarch64::Instruction* prev = |
| 2036 | masm->GetCursorAddress<vixl::aarch64::Instruction*>() - kInstructionSize; |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2037 | if (prev->IsLoadOrStore()) { |
| 2038 | // Make sure we emit only exactly one nop. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2039 | vixl::aarch64::CodeBufferCheckScope scope(masm, |
| 2040 | kInstructionSize, |
| 2041 | vixl::aarch64::CodeBufferCheckScope::kCheck, |
| 2042 | vixl::aarch64::CodeBufferCheckScope::kExactSize); |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2043 | __ nop(); |
| 2044 | } |
| 2045 | } |
| 2046 | |
| 2047 | if (instr->GetOpKind() == HInstruction::kAdd) { |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2048 | Register accumulator = InputRegisterAt(instr, HMultiplyAccumulate::kInputAccumulatorIndex); |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2049 | __ Madd(res, mul_left, mul_right, accumulator); |
| 2050 | } else { |
| 2051 | DCHECK(instr->GetOpKind() == HInstruction::kSub); |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2052 | HInstruction* accum_instr = instr->InputAt(HMultiplyAccumulate::kInputAccumulatorIndex); |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2053 | if (accum_instr->IsConstant() && accum_instr->AsConstant()->IsArithmeticZero()) { |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2054 | __ Mneg(res, mul_left, mul_right); |
| 2055 | } else { |
| 2056 | Register accumulator = InputRegisterAt(instr, HMultiplyAccumulate::kInputAccumulatorIndex); |
| 2057 | __ Msub(res, mul_left, mul_right, accumulator); |
| 2058 | } |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2059 | } |
| 2060 | } |
| 2061 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2062 | void LocationsBuilderARM64::VisitArrayGet(HArrayGet* instruction) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2063 | bool object_array_get_with_read_barrier = |
| 2064 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2065 | LocationSummary* locations = |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2066 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 2067 | object_array_get_with_read_barrier ? |
| 2068 | LocationSummary::kCallOnSlowPath : |
| 2069 | LocationSummary::kNoCall); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2070 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2071 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 2072 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 2073 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 2074 | } else { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2075 | // The output overlaps in the case of an object array get with |
| 2076 | // read barriers enabled: we do not want the move to overwrite the |
| 2077 | // array's location, as we need it to emit the read barrier. |
| 2078 | locations->SetOut( |
| 2079 | Location::RequiresRegister(), |
| 2080 | object_array_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 2081 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2082 | } |
| 2083 | |
| 2084 | void InstructionCodeGeneratorARM64::VisitArrayGet(HArrayGet* instruction) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2085 | Primitive::Type type = instruction->GetType(); |
| 2086 | Register obj = InputRegisterAt(instruction, 0); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2087 | LocationSummary* locations = instruction->GetLocations(); |
| 2088 | Location index = locations->InAt(1); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2089 | Location out = locations->Out(); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 2090 | uint32_t offset = CodeGenerator::GetArrayDataOffset(instruction); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2091 | |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 2092 | MacroAssembler* masm = GetVIXLAssembler(); |
| 2093 | UseScratchRegisterScope temps(masm); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2094 | // Block pools between `Load` and `MaybeRecordImplicitNullCheck`. |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 2095 | BlockPoolsScope block_pools(masm); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2096 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2097 | if (type == Primitive::kPrimNot && kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 2098 | // Object ArrayGet with Baker's read barrier case. |
| 2099 | Register temp = temps.AcquireW(); |
Roland Levillain | 4a3aa57 | 2016-08-15 13:17:06 +0000 | [diff] [blame] | 2100 | // The read barrier instrumentation does not support the HIntermediateAddress instruction yet. |
| 2101 | DCHECK(!instruction->GetArray()->IsIntermediateAddress()); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2102 | // Note that a potential implicit null check is handled in the |
| 2103 | // CodeGeneratorARM64::GenerateArrayLoadWithBakerReadBarrier call. |
| 2104 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
| 2105 | instruction, out, obj.W(), offset, index, temp, /* needs_null_check */ true); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2106 | } else { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2107 | // General case. |
| 2108 | MemOperand source = HeapOperand(obj); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2109 | if (index.IsConstant()) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2110 | offset += Int64ConstantFrom(index) << Primitive::ComponentSizeShift(type); |
| 2111 | source = HeapOperand(obj, offset); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2112 | } else { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2113 | Register temp = temps.AcquireSameSizeAs(obj); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2114 | if (instruction->GetArray()->IsIntermediateAddress()) { |
Roland Levillain | 4a3aa57 | 2016-08-15 13:17:06 +0000 | [diff] [blame] | 2115 | // The read barrier instrumentation does not support the |
| 2116 | // HIntermediateAddress instruction yet. |
| 2117 | DCHECK(!kEmitCompilerReadBarrier); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2118 | // We do not need to compute the intermediate address from the array: the |
| 2119 | // input instruction has done it already. See the comment in |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2120 | // `TryExtractArrayAccessAddress()`. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2121 | if (kIsDebugBuild) { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2122 | HIntermediateAddress* tmp = instruction->GetArray()->AsIntermediateAddress(); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2123 | DCHECK_EQ(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64(), offset); |
| 2124 | } |
| 2125 | temp = obj; |
| 2126 | } else { |
| 2127 | __ Add(temp, obj, offset); |
| 2128 | } |
| 2129 | source = HeapOperand(temp, XRegisterFrom(index), LSL, Primitive::ComponentSizeShift(type)); |
| 2130 | } |
| 2131 | |
| 2132 | codegen_->Load(type, OutputCPURegister(instruction), source); |
| 2133 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2134 | |
| 2135 | if (type == Primitive::kPrimNot) { |
| 2136 | static_assert( |
| 2137 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 2138 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 2139 | Location obj_loc = locations->InAt(0); |
| 2140 | if (index.IsConstant()) { |
| 2141 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, obj_loc, offset); |
| 2142 | } else { |
| 2143 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, obj_loc, offset, index); |
| 2144 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2145 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2146 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2147 | } |
| 2148 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2149 | void LocationsBuilderARM64::VisitArrayLength(HArrayLength* instruction) { |
| 2150 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 2151 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 2152 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2153 | } |
| 2154 | |
| 2155 | void InstructionCodeGeneratorARM64::VisitArrayLength(HArrayLength* instruction) { |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 2156 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 2157 | BlockPoolsScope block_pools(GetVIXLAssembler()); |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 2158 | __ Ldr(OutputRegister(instruction), HeapOperand(InputRegisterAt(instruction, 0), offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 2159 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2160 | } |
| 2161 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2162 | void LocationsBuilderARM64::VisitArraySet(HArraySet* instruction) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2163 | Primitive::Type value_type = instruction->GetComponentType(); |
| 2164 | |
| 2165 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
| 2166 | bool object_array_set_with_read_barrier = |
| 2167 | kEmitCompilerReadBarrier && (value_type == Primitive::kPrimNot); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2168 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 2169 | instruction, |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2170 | (may_need_runtime_call_for_type_check || object_array_set_with_read_barrier) ? |
| 2171 | LocationSummary::kCallOnSlowPath : |
| 2172 | LocationSummary::kNoCall); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2173 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2174 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2175 | if (Primitive::IsFloatingPointType(value_type)) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2176 | locations->SetInAt(2, Location::RequiresFpuRegister()); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2177 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2178 | locations->SetInAt(2, Location::RequiresRegister()); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2179 | } |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame^] | 2180 | if (object_array_set_with_read_barrier && kUseBakerReadBarrier) { |
| 2181 | // Additional temporary registers for a Baker read barrier. |
| 2182 | locations->AddTemp(Location::RequiresRegister()); |
| 2183 | locations->AddTemp(Location::RequiresRegister()); |
| 2184 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2185 | } |
| 2186 | |
| 2187 | void InstructionCodeGeneratorARM64::VisitArraySet(HArraySet* instruction) { |
| 2188 | Primitive::Type value_type = instruction->GetComponentType(); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2189 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2190 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2191 | bool needs_write_barrier = |
| 2192 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2193 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2194 | Register array = InputRegisterAt(instruction, 0); |
| 2195 | CPURegister value = InputCPURegisterAt(instruction, 2); |
| 2196 | CPURegister source = value; |
| 2197 | Location index = locations->InAt(1); |
| 2198 | size_t offset = mirror::Array::DataOffset(Primitive::ComponentSize(value_type)).Uint32Value(); |
| 2199 | MemOperand destination = HeapOperand(array); |
| 2200 | MacroAssembler* masm = GetVIXLAssembler(); |
| 2201 | BlockPoolsScope block_pools(masm); |
| 2202 | |
| 2203 | if (!needs_write_barrier) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2204 | DCHECK(!may_need_runtime_call_for_type_check); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2205 | if (index.IsConstant()) { |
| 2206 | offset += Int64ConstantFrom(index) << Primitive::ComponentSizeShift(value_type); |
| 2207 | destination = HeapOperand(array, offset); |
| 2208 | } else { |
| 2209 | UseScratchRegisterScope temps(masm); |
| 2210 | Register temp = temps.AcquireSameSizeAs(array); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2211 | if (instruction->GetArray()->IsIntermediateAddress()) { |
Roland Levillain | 4a3aa57 | 2016-08-15 13:17:06 +0000 | [diff] [blame] | 2212 | // The read barrier instrumentation does not support the |
| 2213 | // HIntermediateAddress instruction yet. |
| 2214 | DCHECK(!kEmitCompilerReadBarrier); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2215 | // We do not need to compute the intermediate address from the array: the |
| 2216 | // input instruction has done it already. See the comment in |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2217 | // `TryExtractArrayAccessAddress()`. |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2218 | if (kIsDebugBuild) { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2219 | HIntermediateAddress* tmp = instruction->GetArray()->AsIntermediateAddress(); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2220 | DCHECK(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64() == offset); |
| 2221 | } |
| 2222 | temp = array; |
| 2223 | } else { |
| 2224 | __ Add(temp, array, offset); |
| 2225 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2226 | destination = HeapOperand(temp, |
| 2227 | XRegisterFrom(index), |
| 2228 | LSL, |
| 2229 | Primitive::ComponentSizeShift(value_type)); |
| 2230 | } |
| 2231 | codegen_->Store(value_type, value, destination); |
| 2232 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2233 | } else { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2234 | DCHECK(!instruction->GetArray()->IsIntermediateAddress()); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2235 | vixl::aarch64::Label done; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2236 | SlowPathCodeARM64* slow_path = nullptr; |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2237 | { |
| 2238 | // We use a block to end the scratch scope before the write barrier, thus |
| 2239 | // freeing the temporary registers so they can be used in `MarkGCCard`. |
| 2240 | UseScratchRegisterScope temps(masm); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2241 | Register temp = temps.AcquireSameSizeAs(array); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2242 | if (index.IsConstant()) { |
| 2243 | offset += Int64ConstantFrom(index) << Primitive::ComponentSizeShift(value_type); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2244 | destination = HeapOperand(array, offset); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2245 | } else { |
Alexandre Rames | 82000b0 | 2015-07-07 11:34:16 +0100 | [diff] [blame] | 2246 | destination = HeapOperand(temp, |
| 2247 | XRegisterFrom(index), |
| 2248 | LSL, |
| 2249 | Primitive::ComponentSizeShift(value_type)); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2250 | } |
| 2251 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2252 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2253 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 2254 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 2255 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2256 | if (may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2257 | slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathARM64(instruction); |
| 2258 | codegen_->AddSlowPath(slow_path); |
| 2259 | if (instruction->GetValueCanBeNull()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2260 | vixl::aarch64::Label non_zero; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2261 | __ Cbnz(Register(value), &non_zero); |
| 2262 | if (!index.IsConstant()) { |
| 2263 | __ Add(temp, array, offset); |
| 2264 | } |
| 2265 | __ Str(wzr, destination); |
| 2266 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2267 | __ B(&done); |
| 2268 | __ Bind(&non_zero); |
| 2269 | } |
| 2270 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2271 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame^] | 2272 | if (!kUseBakerReadBarrier) { |
| 2273 | // When (non-Baker) read barriers are enabled, the type |
| 2274 | // checking instrumentation requires two read barriers |
| 2275 | // generated by CodeGeneratorARM64::GenerateReadBarrierSlow: |
| 2276 | // |
| 2277 | // __ Mov(temp2, temp); |
| 2278 | // // /* HeapReference<Class> */ temp = temp->component_type_ |
| 2279 | // __ Ldr(temp, HeapOperand(temp, component_offset)); |
| 2280 | // codegen_->GenerateReadBarrierSlow( |
| 2281 | // instruction, temp_loc, temp_loc, temp2_loc, component_offset); |
| 2282 | // |
| 2283 | // // /* HeapReference<Class> */ temp2 = value->klass_ |
| 2284 | // __ Ldr(temp2, HeapOperand(Register(value), class_offset)); |
| 2285 | // codegen_->GenerateReadBarrierSlow( |
| 2286 | // instruction, temp2_loc, temp2_loc, value_loc, class_offset, temp_loc); |
| 2287 | // |
| 2288 | // __ Cmp(temp, temp2); |
| 2289 | // |
| 2290 | // However, the second read barrier may trash `temp`, as it |
| 2291 | // is a temporary register, and as such would not be saved |
| 2292 | // along with live registers before calling the runtime (nor |
| 2293 | // restored afterwards). So in this case, we bail out and |
| 2294 | // delegate the work to the array set slow path. |
| 2295 | // |
| 2296 | // TODO: Extend the register allocator to support a new |
| 2297 | // "(locally) live temp" location so as to avoid always |
| 2298 | // going into the slow path when read barriers are enabled? |
| 2299 | // |
| 2300 | // There is no such problem with Baker read barriers (see below). |
| 2301 | __ B(slow_path->GetEntryLabel()); |
| 2302 | } else { |
| 2303 | // Note that we cannot use `temps` (instance of VIXL's |
| 2304 | // UseScratchRegisterScope) to allocate `temp2` because |
| 2305 | // the Baker read barriers generated by |
| 2306 | // GenerateFieldLoadWithBakerReadBarrier below also use |
| 2307 | // that facility to allocate a temporary register, thus |
| 2308 | // making VIXL's scratch register pool empty. |
| 2309 | Location temp2_loc = locations->GetTemp(0); |
| 2310 | Register temp2 = WRegisterFrom(temp2_loc); |
| 2311 | |
| 2312 | // Note: Because it is acquired from VIXL's scratch register |
| 2313 | // pool, `temp` might be IP0, and thus cannot be used as |
| 2314 | // `ref` argument of GenerateFieldLoadWithBakerReadBarrier |
| 2315 | // calls below (see ReadBarrierMarkSlowPathARM64 for more |
| 2316 | // details). |
| 2317 | |
| 2318 | // /* HeapReference<Class> */ temp2 = array->klass_ |
| 2319 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 2320 | temp2_loc, |
| 2321 | array, |
| 2322 | class_offset, |
| 2323 | temp, |
| 2324 | /* needs_null_check */ true, |
| 2325 | /* use_load_acquire */ false); |
| 2326 | |
| 2327 | // /* HeapReference<Class> */ temp2 = temp2->component_type_ |
| 2328 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 2329 | temp2_loc, |
| 2330 | temp2, |
| 2331 | component_offset, |
| 2332 | temp, |
| 2333 | /* needs_null_check */ false, |
| 2334 | /* use_load_acquire */ false); |
| 2335 | // For the same reason that we request `temp2` from the |
| 2336 | // register allocator above, we cannot get `temp3` from |
| 2337 | // VIXL's scratch register pool. |
| 2338 | Location temp3_loc = locations->GetTemp(1); |
| 2339 | Register temp3 = WRegisterFrom(temp3_loc); |
| 2340 | // Register `temp2` is not trashed by the read barrier |
| 2341 | // emitted by GenerateFieldLoadWithBakerReadBarrier below, |
| 2342 | // as that method produces a call to a ReadBarrierMarkRegX |
| 2343 | // entry point, which saves all potentially live registers, |
| 2344 | // including temporaries such a `temp2`. |
| 2345 | // /* HeapReference<Class> */ temp3 = register_value->klass_ |
| 2346 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 2347 | temp3_loc, |
| 2348 | value.W(), |
| 2349 | class_offset, |
| 2350 | temp, |
| 2351 | /* needs_null_check */ false, |
| 2352 | /* use_load_acquire */ false); |
| 2353 | // If heap poisoning is enabled, `temp2` and `temp3` have |
| 2354 | // been unpoisoned by the the previous calls to |
| 2355 | // CodeGeneratorARM64::GenerateFieldLoadWithBakerReadBarrier. |
| 2356 | __ Cmp(temp2, temp3); |
| 2357 | |
| 2358 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 2359 | vixl::aarch64::Label do_put; |
| 2360 | __ B(eq, &do_put); |
| 2361 | // We do not need to emit a read barrier for the |
| 2362 | // following heap reference load, as `temp2` is only used |
| 2363 | // in a comparison with null below, and this reference |
| 2364 | // is not kept afterwards. |
| 2365 | // /* HeapReference<Class> */ temp = temp2->super_class_ |
| 2366 | __ Ldr(temp, HeapOperand(temp2, super_offset)); |
| 2367 | // If heap poisoning is enabled, no need to unpoison |
| 2368 | // `temp`, as we are comparing against null below. |
| 2369 | __ Cbnz(temp, slow_path->GetEntryLabel()); |
| 2370 | __ Bind(&do_put); |
| 2371 | } else { |
| 2372 | __ B(ne, slow_path->GetEntryLabel()); |
| 2373 | } |
| 2374 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2375 | } else { |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame^] | 2376 | // Non read barrier code. |
| 2377 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2378 | Register temp2 = temps.AcquireSameSizeAs(array); |
| 2379 | // /* HeapReference<Class> */ temp = array->klass_ |
| 2380 | __ Ldr(temp, HeapOperand(array, class_offset)); |
| 2381 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2382 | GetAssembler()->MaybeUnpoisonHeapReference(temp); |
| 2383 | |
| 2384 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| 2385 | __ Ldr(temp, HeapOperand(temp, component_offset)); |
| 2386 | // /* HeapReference<Class> */ temp2 = value->klass_ |
| 2387 | __ Ldr(temp2, HeapOperand(Register(value), class_offset)); |
| 2388 | // If heap poisoning is enabled, no need to unpoison `temp` |
| 2389 | // nor `temp2`, as we are comparing two poisoned references. |
| 2390 | __ Cmp(temp, temp2); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame^] | 2391 | temps.Release(temp2); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2392 | |
| 2393 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2394 | vixl::aarch64::Label do_put; |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2395 | __ B(eq, &do_put); |
| 2396 | // If heap poisoning is enabled, the `temp` reference has |
| 2397 | // not been unpoisoned yet; unpoison it now. |
| 2398 | GetAssembler()->MaybeUnpoisonHeapReference(temp); |
| 2399 | |
| 2400 | // /* HeapReference<Class> */ temp = temp->super_class_ |
| 2401 | __ Ldr(temp, HeapOperand(temp, super_offset)); |
| 2402 | // If heap poisoning is enabled, no need to unpoison |
| 2403 | // `temp`, as we are comparing against null below. |
| 2404 | __ Cbnz(temp, slow_path->GetEntryLabel()); |
| 2405 | __ Bind(&do_put); |
| 2406 | } else { |
| 2407 | __ B(ne, slow_path->GetEntryLabel()); |
| 2408 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2409 | } |
| 2410 | } |
| 2411 | |
| 2412 | if (kPoisonHeapReferences) { |
Nicolas Geoffray | a8a0fe2 | 2015-10-01 15:50:27 +0100 | [diff] [blame] | 2413 | Register temp2 = temps.AcquireSameSizeAs(array); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2414 | DCHECK(value.IsW()); |
Nicolas Geoffray | a8a0fe2 | 2015-10-01 15:50:27 +0100 | [diff] [blame] | 2415 | __ Mov(temp2, value.W()); |
| 2416 | GetAssembler()->PoisonHeapReference(temp2); |
| 2417 | source = temp2; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2418 | } |
| 2419 | |
| 2420 | if (!index.IsConstant()) { |
| 2421 | __ Add(temp, array, offset); |
| 2422 | } |
Nicolas Geoffray | 61b1dbe | 2015-10-01 10:27:52 +0100 | [diff] [blame] | 2423 | __ Str(source, destination); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2424 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2425 | if (!may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2426 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2427 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2428 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2429 | |
| 2430 | codegen_->MarkGCCard(array, value.W(), instruction->GetValueCanBeNull()); |
| 2431 | |
| 2432 | if (done.IsLinked()) { |
| 2433 | __ Bind(&done); |
| 2434 | } |
| 2435 | |
| 2436 | if (slow_path != nullptr) { |
| 2437 | __ Bind(slow_path->GetExitLabel()); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2438 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2439 | } |
| 2440 | } |
| 2441 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2442 | void LocationsBuilderARM64::VisitBoundsCheck(HBoundsCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2443 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 2444 | ? LocationSummary::kCallOnSlowPath |
| 2445 | : LocationSummary::kNoCall; |
| 2446 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2447 | locations->SetInAt(0, Location::RequiresRegister()); |
Serban Constantinescu | 760d8ef | 2015-03-28 18:09:56 +0000 | [diff] [blame] | 2448 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->InputAt(1), instruction)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2449 | if (instruction->HasUses()) { |
| 2450 | locations->SetOut(Location::SameAsFirstInput()); |
| 2451 | } |
| 2452 | } |
| 2453 | |
| 2454 | void InstructionCodeGeneratorARM64::VisitBoundsCheck(HBoundsCheck* instruction) { |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 2455 | BoundsCheckSlowPathARM64* slow_path = |
| 2456 | new (GetGraph()->GetArena()) BoundsCheckSlowPathARM64(instruction); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2457 | codegen_->AddSlowPath(slow_path); |
| 2458 | |
| 2459 | __ Cmp(InputRegisterAt(instruction, 0), InputOperandAt(instruction, 1)); |
| 2460 | __ B(slow_path->GetEntryLabel(), hs); |
| 2461 | } |
| 2462 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2463 | void LocationsBuilderARM64::VisitClinitCheck(HClinitCheck* check) { |
| 2464 | LocationSummary* locations = |
| 2465 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 2466 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2467 | if (check->HasUses()) { |
| 2468 | locations->SetOut(Location::SameAsFirstInput()); |
| 2469 | } |
| 2470 | } |
| 2471 | |
| 2472 | void InstructionCodeGeneratorARM64::VisitClinitCheck(HClinitCheck* check) { |
| 2473 | // We assume the class is not null. |
| 2474 | SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM64( |
| 2475 | check->GetLoadClass(), check, check->GetDexPc(), true); |
| 2476 | codegen_->AddSlowPath(slow_path); |
| 2477 | GenerateClassInitializationCheck(slow_path, InputRegisterAt(check, 0)); |
| 2478 | } |
| 2479 | |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2480 | static bool IsFloatingPointZeroConstant(HInstruction* inst) { |
| 2481 | return (inst->IsFloatConstant() && (inst->AsFloatConstant()->IsArithmeticZero())) |
| 2482 | || (inst->IsDoubleConstant() && (inst->AsDoubleConstant()->IsArithmeticZero())); |
| 2483 | } |
| 2484 | |
| 2485 | void InstructionCodeGeneratorARM64::GenerateFcmp(HInstruction* instruction) { |
| 2486 | FPRegister lhs_reg = InputFPRegisterAt(instruction, 0); |
| 2487 | Location rhs_loc = instruction->GetLocations()->InAt(1); |
| 2488 | if (rhs_loc.IsConstant()) { |
| 2489 | // 0.0 is the only immediate that can be encoded directly in |
| 2490 | // an FCMP instruction. |
| 2491 | // |
| 2492 | // Both the JLS (section 15.20.1) and the JVMS (section 6.5) |
| 2493 | // specify that in a floating-point comparison, positive zero |
| 2494 | // and negative zero are considered equal, so we can use the |
| 2495 | // literal 0.0 for both cases here. |
| 2496 | // |
| 2497 | // Note however that some methods (Float.equal, Float.compare, |
| 2498 | // Float.compareTo, Double.equal, Double.compare, |
| 2499 | // Double.compareTo, Math.max, Math.min, StrictMath.max, |
| 2500 | // StrictMath.min) consider 0.0 to be (strictly) greater than |
| 2501 | // -0.0. So if we ever translate calls to these methods into a |
| 2502 | // HCompare instruction, we must handle the -0.0 case with |
| 2503 | // care here. |
| 2504 | DCHECK(IsFloatingPointZeroConstant(rhs_loc.GetConstant())); |
| 2505 | __ Fcmp(lhs_reg, 0.0); |
| 2506 | } else { |
| 2507 | __ Fcmp(lhs_reg, InputFPRegisterAt(instruction, 1)); |
| 2508 | } |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2509 | } |
| 2510 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2511 | void LocationsBuilderARM64::VisitCompare(HCompare* compare) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2512 | LocationSummary* locations = |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2513 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
| 2514 | Primitive::Type in_type = compare->InputAt(0)->GetType(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2515 | switch (in_type) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 2516 | case Primitive::kPrimBoolean: |
| 2517 | case Primitive::kPrimByte: |
| 2518 | case Primitive::kPrimShort: |
| 2519 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2520 | case Primitive::kPrimInt: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2521 | case Primitive::kPrimLong: { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2522 | locations->SetInAt(0, Location::RequiresRegister()); |
Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 2523 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(compare->InputAt(1), compare)); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2524 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2525 | break; |
| 2526 | } |
| 2527 | case Primitive::kPrimFloat: |
| 2528 | case Primitive::kPrimDouble: { |
| 2529 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2530 | locations->SetInAt(1, |
| 2531 | IsFloatingPointZeroConstant(compare->InputAt(1)) |
| 2532 | ? Location::ConstantLocation(compare->InputAt(1)->AsConstant()) |
| 2533 | : Location::RequiresFpuRegister()); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2534 | locations->SetOut(Location::RequiresRegister()); |
| 2535 | break; |
| 2536 | } |
| 2537 | default: |
| 2538 | LOG(FATAL) << "Unexpected type for compare operation " << in_type; |
| 2539 | } |
| 2540 | } |
| 2541 | |
| 2542 | void InstructionCodeGeneratorARM64::VisitCompare(HCompare* compare) { |
| 2543 | Primitive::Type in_type = compare->InputAt(0)->GetType(); |
| 2544 | |
| 2545 | // 0 if: left == right |
| 2546 | // 1 if: left > right |
| 2547 | // -1 if: left < right |
| 2548 | switch (in_type) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 2549 | case Primitive::kPrimBoolean: |
| 2550 | case Primitive::kPrimByte: |
| 2551 | case Primitive::kPrimShort: |
| 2552 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2553 | case Primitive::kPrimInt: |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2554 | case Primitive::kPrimLong: { |
| 2555 | Register result = OutputRegister(compare); |
| 2556 | Register left = InputRegisterAt(compare, 0); |
| 2557 | Operand right = InputOperandAt(compare, 1); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2558 | __ Cmp(left, right); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2559 | __ Cset(result, ne); // result == +1 if NE or 0 otherwise |
| 2560 | __ Cneg(result, result, lt); // result == -1 if LT or unchanged otherwise |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2561 | break; |
| 2562 | } |
| 2563 | case Primitive::kPrimFloat: |
| 2564 | case Primitive::kPrimDouble: { |
| 2565 | Register result = OutputRegister(compare); |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2566 | GenerateFcmp(compare); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 2567 | __ Cset(result, ne); |
| 2568 | __ Cneg(result, result, ARM64FPCondition(kCondLT, compare->IsGtBias())); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2569 | break; |
| 2570 | } |
| 2571 | default: |
| 2572 | LOG(FATAL) << "Unimplemented compare type " << in_type; |
| 2573 | } |
| 2574 | } |
| 2575 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2576 | void LocationsBuilderARM64::HandleCondition(HCondition* instruction) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2577 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2578 | |
| 2579 | if (Primitive::IsFloatingPointType(instruction->InputAt(0)->GetType())) { |
| 2580 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2581 | locations->SetInAt(1, |
| 2582 | IsFloatingPointZeroConstant(instruction->InputAt(1)) |
| 2583 | ? Location::ConstantLocation(instruction->InputAt(1)->AsConstant()) |
| 2584 | : Location::RequiresFpuRegister()); |
| 2585 | } else { |
| 2586 | // Integer cases. |
| 2587 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2588 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->InputAt(1), instruction)); |
| 2589 | } |
| 2590 | |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2591 | if (!instruction->IsEmittedAtUseSite()) { |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 2592 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2593 | } |
| 2594 | } |
| 2595 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2596 | void InstructionCodeGeneratorARM64::HandleCondition(HCondition* instruction) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2597 | if (instruction->IsEmittedAtUseSite()) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2598 | return; |
| 2599 | } |
| 2600 | |
| 2601 | LocationSummary* locations = instruction->GetLocations(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2602 | Register res = RegisterFrom(locations->Out(), instruction->GetType()); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2603 | IfCondition if_cond = instruction->GetCondition(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2604 | |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2605 | if (Primitive::IsFloatingPointType(instruction->InputAt(0)->GetType())) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2606 | GenerateFcmp(instruction); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 2607 | __ Cset(res, ARM64FPCondition(if_cond, instruction->IsGtBias())); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2608 | } else { |
| 2609 | // Integer cases. |
| 2610 | Register lhs = InputRegisterAt(instruction, 0); |
| 2611 | Operand rhs = InputOperandAt(instruction, 1); |
| 2612 | __ Cmp(lhs, rhs); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 2613 | __ Cset(res, ARM64Condition(if_cond)); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2614 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2615 | } |
| 2616 | |
| 2617 | #define FOR_EACH_CONDITION_INSTRUCTION(M) \ |
| 2618 | M(Equal) \ |
| 2619 | M(NotEqual) \ |
| 2620 | M(LessThan) \ |
| 2621 | M(LessThanOrEqual) \ |
| 2622 | M(GreaterThan) \ |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2623 | M(GreaterThanOrEqual) \ |
| 2624 | M(Below) \ |
| 2625 | M(BelowOrEqual) \ |
| 2626 | M(Above) \ |
| 2627 | M(AboveOrEqual) |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2628 | #define DEFINE_CONDITION_VISITORS(Name) \ |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2629 | void LocationsBuilderARM64::Visit##Name(H##Name* comp) { HandleCondition(comp); } \ |
| 2630 | void InstructionCodeGeneratorARM64::Visit##Name(H##Name* comp) { HandleCondition(comp); } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2631 | FOR_EACH_CONDITION_INSTRUCTION(DEFINE_CONDITION_VISITORS) |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2632 | #undef DEFINE_CONDITION_VISITORS |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2633 | #undef FOR_EACH_CONDITION_INSTRUCTION |
| 2634 | |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2635 | void InstructionCodeGeneratorARM64::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 2636 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2637 | |
| 2638 | LocationSummary* locations = instruction->GetLocations(); |
| 2639 | Location second = locations->InAt(1); |
| 2640 | DCHECK(second.IsConstant()); |
| 2641 | |
| 2642 | Register out = OutputRegister(instruction); |
| 2643 | Register dividend = InputRegisterAt(instruction, 0); |
| 2644 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 2645 | DCHECK(imm == 1 || imm == -1); |
| 2646 | |
| 2647 | if (instruction->IsRem()) { |
| 2648 | __ Mov(out, 0); |
| 2649 | } else { |
| 2650 | if (imm == 1) { |
| 2651 | __ Mov(out, dividend); |
| 2652 | } else { |
| 2653 | __ Neg(out, dividend); |
| 2654 | } |
| 2655 | } |
| 2656 | } |
| 2657 | |
| 2658 | void InstructionCodeGeneratorARM64::DivRemByPowerOfTwo(HBinaryOperation* instruction) { |
| 2659 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2660 | |
| 2661 | LocationSummary* locations = instruction->GetLocations(); |
| 2662 | Location second = locations->InAt(1); |
| 2663 | DCHECK(second.IsConstant()); |
| 2664 | |
| 2665 | Register out = OutputRegister(instruction); |
| 2666 | Register dividend = InputRegisterAt(instruction, 0); |
| 2667 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 2668 | uint64_t abs_imm = static_cast<uint64_t>(AbsOrMin(imm)); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2669 | int ctz_imm = CTZ(abs_imm); |
| 2670 | |
| 2671 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2672 | Register temp = temps.AcquireSameSizeAs(out); |
| 2673 | |
| 2674 | if (instruction->IsDiv()) { |
| 2675 | __ Add(temp, dividend, abs_imm - 1); |
| 2676 | __ Cmp(dividend, 0); |
| 2677 | __ Csel(out, temp, dividend, lt); |
| 2678 | if (imm > 0) { |
| 2679 | __ Asr(out, out, ctz_imm); |
| 2680 | } else { |
| 2681 | __ Neg(out, Operand(out, ASR, ctz_imm)); |
| 2682 | } |
| 2683 | } else { |
| 2684 | int bits = instruction->GetResultType() == Primitive::kPrimInt ? 32 : 64; |
| 2685 | __ Asr(temp, dividend, bits - 1); |
| 2686 | __ Lsr(temp, temp, bits - ctz_imm); |
| 2687 | __ Add(out, dividend, temp); |
| 2688 | __ And(out, out, abs_imm - 1); |
| 2689 | __ Sub(out, out, temp); |
| 2690 | } |
| 2691 | } |
| 2692 | |
| 2693 | void InstructionCodeGeneratorARM64::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 2694 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2695 | |
| 2696 | LocationSummary* locations = instruction->GetLocations(); |
| 2697 | Location second = locations->InAt(1); |
| 2698 | DCHECK(second.IsConstant()); |
| 2699 | |
| 2700 | Register out = OutputRegister(instruction); |
| 2701 | Register dividend = InputRegisterAt(instruction, 0); |
| 2702 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 2703 | |
| 2704 | Primitive::Type type = instruction->GetResultType(); |
| 2705 | DCHECK(type == Primitive::kPrimInt || type == Primitive::kPrimLong); |
| 2706 | |
| 2707 | int64_t magic; |
| 2708 | int shift; |
| 2709 | CalculateMagicAndShiftForDivRem(imm, type == Primitive::kPrimLong /* is_long */, &magic, &shift); |
| 2710 | |
| 2711 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2712 | Register temp = temps.AcquireSameSizeAs(out); |
| 2713 | |
| 2714 | // temp = get_high(dividend * magic) |
| 2715 | __ Mov(temp, magic); |
| 2716 | if (type == Primitive::kPrimLong) { |
| 2717 | __ Smulh(temp, dividend, temp); |
| 2718 | } else { |
| 2719 | __ Smull(temp.X(), dividend, temp); |
| 2720 | __ Lsr(temp.X(), temp.X(), 32); |
| 2721 | } |
| 2722 | |
| 2723 | if (imm > 0 && magic < 0) { |
| 2724 | __ Add(temp, temp, dividend); |
| 2725 | } else if (imm < 0 && magic > 0) { |
| 2726 | __ Sub(temp, temp, dividend); |
| 2727 | } |
| 2728 | |
| 2729 | if (shift != 0) { |
| 2730 | __ Asr(temp, temp, shift); |
| 2731 | } |
| 2732 | |
| 2733 | if (instruction->IsDiv()) { |
| 2734 | __ Sub(out, temp, Operand(temp, ASR, type == Primitive::kPrimLong ? 63 : 31)); |
| 2735 | } else { |
| 2736 | __ Sub(temp, temp, Operand(temp, ASR, type == Primitive::kPrimLong ? 63 : 31)); |
| 2737 | // TODO: Strength reduction for msub. |
| 2738 | Register temp_imm = temps.AcquireSameSizeAs(out); |
| 2739 | __ Mov(temp_imm, imm); |
| 2740 | __ Msub(out, temp, temp_imm, dividend); |
| 2741 | } |
| 2742 | } |
| 2743 | |
| 2744 | void InstructionCodeGeneratorARM64::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 2745 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2746 | Primitive::Type type = instruction->GetResultType(); |
| 2747 | DCHECK(type == Primitive::kPrimInt || Primitive::kPrimLong); |
| 2748 | |
| 2749 | LocationSummary* locations = instruction->GetLocations(); |
| 2750 | Register out = OutputRegister(instruction); |
| 2751 | Location second = locations->InAt(1); |
| 2752 | |
| 2753 | if (second.IsConstant()) { |
| 2754 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 2755 | |
| 2756 | if (imm == 0) { |
| 2757 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 2758 | } else if (imm == 1 || imm == -1) { |
| 2759 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 2760 | } else if (IsPowerOfTwo(AbsOrMin(imm))) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2761 | DivRemByPowerOfTwo(instruction); |
| 2762 | } else { |
| 2763 | DCHECK(imm <= -2 || imm >= 2); |
| 2764 | GenerateDivRemWithAnyConstant(instruction); |
| 2765 | } |
| 2766 | } else { |
| 2767 | Register dividend = InputRegisterAt(instruction, 0); |
| 2768 | Register divisor = InputRegisterAt(instruction, 1); |
| 2769 | if (instruction->IsDiv()) { |
| 2770 | __ Sdiv(out, dividend, divisor); |
| 2771 | } else { |
| 2772 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2773 | Register temp = temps.AcquireSameSizeAs(out); |
| 2774 | __ Sdiv(temp, dividend, divisor); |
| 2775 | __ Msub(out, temp, divisor, dividend); |
| 2776 | } |
| 2777 | } |
| 2778 | } |
| 2779 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2780 | void LocationsBuilderARM64::VisitDiv(HDiv* div) { |
| 2781 | LocationSummary* locations = |
| 2782 | new (GetGraph()->GetArena()) LocationSummary(div, LocationSummary::kNoCall); |
| 2783 | switch (div->GetResultType()) { |
| 2784 | case Primitive::kPrimInt: |
| 2785 | case Primitive::kPrimLong: |
| 2786 | locations->SetInAt(0, Location::RequiresRegister()); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2787 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2788 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2789 | break; |
| 2790 | |
| 2791 | case Primitive::kPrimFloat: |
| 2792 | case Primitive::kPrimDouble: |
| 2793 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2794 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2795 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 2796 | break; |
| 2797 | |
| 2798 | default: |
| 2799 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 2800 | } |
| 2801 | } |
| 2802 | |
| 2803 | void InstructionCodeGeneratorARM64::VisitDiv(HDiv* div) { |
| 2804 | Primitive::Type type = div->GetResultType(); |
| 2805 | switch (type) { |
| 2806 | case Primitive::kPrimInt: |
| 2807 | case Primitive::kPrimLong: |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2808 | GenerateDivRemIntegral(div); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2809 | break; |
| 2810 | |
| 2811 | case Primitive::kPrimFloat: |
| 2812 | case Primitive::kPrimDouble: |
| 2813 | __ Fdiv(OutputFPRegister(div), InputFPRegisterAt(div, 0), InputFPRegisterAt(div, 1)); |
| 2814 | break; |
| 2815 | |
| 2816 | default: |
| 2817 | LOG(FATAL) << "Unexpected div type " << type; |
| 2818 | } |
| 2819 | } |
| 2820 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2821 | void LocationsBuilderARM64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2822 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 2823 | ? LocationSummary::kCallOnSlowPath |
| 2824 | : LocationSummary::kNoCall; |
| 2825 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2826 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
| 2827 | if (instruction->HasUses()) { |
| 2828 | locations->SetOut(Location::SameAsFirstInput()); |
| 2829 | } |
| 2830 | } |
| 2831 | |
| 2832 | void InstructionCodeGeneratorARM64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 2833 | SlowPathCodeARM64* slow_path = |
| 2834 | new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM64(instruction); |
| 2835 | codegen_->AddSlowPath(slow_path); |
| 2836 | Location value = instruction->GetLocations()->InAt(0); |
| 2837 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 2838 | Primitive::Type type = instruction->GetType(); |
| 2839 | |
Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 2840 | if (!Primitive::IsIntegralType(type)) { |
| 2841 | LOG(FATAL) << "Unexpected type " << type << " for DivZeroCheck."; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 2842 | return; |
| 2843 | } |
| 2844 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2845 | if (value.IsConstant()) { |
| 2846 | int64_t divisor = Int64ConstantFrom(value); |
| 2847 | if (divisor == 0) { |
| 2848 | __ B(slow_path->GetEntryLabel()); |
| 2849 | } else { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 2850 | // A division by a non-null constant is valid. We don't need to perform |
| 2851 | // any check, so simply fall through. |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2852 | } |
| 2853 | } else { |
| 2854 | __ Cbz(InputRegisterAt(instruction, 0), slow_path->GetEntryLabel()); |
| 2855 | } |
| 2856 | } |
| 2857 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2858 | void LocationsBuilderARM64::VisitDoubleConstant(HDoubleConstant* constant) { |
| 2859 | LocationSummary* locations = |
| 2860 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 2861 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2862 | } |
| 2863 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2864 | void InstructionCodeGeneratorARM64::VisitDoubleConstant( |
| 2865 | HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2866 | // Will be generated at use site. |
| 2867 | } |
| 2868 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2869 | void LocationsBuilderARM64::VisitExit(HExit* exit) { |
| 2870 | exit->SetLocations(nullptr); |
| 2871 | } |
| 2872 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2873 | void InstructionCodeGeneratorARM64::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2874 | } |
| 2875 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2876 | void LocationsBuilderARM64::VisitFloatConstant(HFloatConstant* constant) { |
| 2877 | LocationSummary* locations = |
| 2878 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 2879 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2880 | } |
| 2881 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2882 | void InstructionCodeGeneratorARM64::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2883 | // Will be generated at use site. |
| 2884 | } |
| 2885 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2886 | void InstructionCodeGeneratorARM64::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2887 | DCHECK(!successor->IsExitBlock()); |
| 2888 | HBasicBlock* block = got->GetBlock(); |
| 2889 | HInstruction* previous = got->GetPrevious(); |
| 2890 | HLoopInformation* info = block->GetLoopInformation(); |
| 2891 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2892 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2893 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck()); |
| 2894 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 2895 | return; |
| 2896 | } |
| 2897 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 2898 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 2899 | } |
| 2900 | if (!codegen_->GoesToNextBlock(block, successor)) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2901 | __ B(codegen_->GetLabelOf(successor)); |
| 2902 | } |
| 2903 | } |
| 2904 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2905 | void LocationsBuilderARM64::VisitGoto(HGoto* got) { |
| 2906 | got->SetLocations(nullptr); |
| 2907 | } |
| 2908 | |
| 2909 | void InstructionCodeGeneratorARM64::VisitGoto(HGoto* got) { |
| 2910 | HandleGoto(got, got->GetSuccessor()); |
| 2911 | } |
| 2912 | |
| 2913 | void LocationsBuilderARM64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 2914 | try_boundary->SetLocations(nullptr); |
| 2915 | } |
| 2916 | |
| 2917 | void InstructionCodeGeneratorARM64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 2918 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 2919 | if (!successor->IsExitBlock()) { |
| 2920 | HandleGoto(try_boundary, successor); |
| 2921 | } |
| 2922 | } |
| 2923 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2924 | void InstructionCodeGeneratorARM64::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2925 | size_t condition_input_index, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2926 | vixl::aarch64::Label* true_target, |
| 2927 | vixl::aarch64::Label* false_target) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2928 | // FP branching requires both targets to be explicit. If either of the targets |
| 2929 | // is nullptr (fallthrough) use and bind `fallthrough_target` instead. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2930 | vixl::aarch64::Label fallthrough_target; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2931 | HInstruction* cond = instruction->InputAt(condition_input_index); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2932 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2933 | if (true_target == nullptr && false_target == nullptr) { |
| 2934 | // Nothing to do. The code always falls through. |
| 2935 | return; |
| 2936 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2937 | // Constant condition, statically compared against "true" (integer value 1). |
| 2938 | if (cond->AsIntConstant()->IsTrue()) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2939 | if (true_target != nullptr) { |
| 2940 | __ B(true_target); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2941 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2942 | } else { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2943 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2944 | if (false_target != nullptr) { |
| 2945 | __ B(false_target); |
| 2946 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2947 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2948 | return; |
| 2949 | } |
| 2950 | |
| 2951 | // The following code generates these patterns: |
| 2952 | // (1) true_target == nullptr && false_target != nullptr |
| 2953 | // - opposite condition true => branch to false_target |
| 2954 | // (2) true_target != nullptr && false_target == nullptr |
| 2955 | // - condition true => branch to true_target |
| 2956 | // (3) true_target != nullptr && false_target != nullptr |
| 2957 | // - condition true => branch to true_target |
| 2958 | // - branch to false_target |
| 2959 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2960 | // The condition instruction has been materialized, compare the output to 0. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2961 | Location cond_val = instruction->GetLocations()->InAt(condition_input_index); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2962 | DCHECK(cond_val.IsRegister()); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2963 | if (true_target == nullptr) { |
| 2964 | __ Cbz(InputRegisterAt(instruction, condition_input_index), false_target); |
| 2965 | } else { |
| 2966 | __ Cbnz(InputRegisterAt(instruction, condition_input_index), true_target); |
| 2967 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2968 | } else { |
| 2969 | // The condition instruction has not been materialized, use its inputs as |
| 2970 | // the comparison and its condition as the branch condition. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2971 | HCondition* condition = cond->AsCondition(); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2972 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2973 | Primitive::Type type = condition->InputAt(0)->GetType(); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2974 | if (Primitive::IsFloatingPointType(type)) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2975 | GenerateFcmp(condition); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2976 | if (true_target == nullptr) { |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 2977 | IfCondition opposite_condition = condition->GetOppositeCondition(); |
| 2978 | __ B(ARM64FPCondition(opposite_condition, condition->IsGtBias()), false_target); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2979 | } else { |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 2980 | __ B(ARM64FPCondition(condition->GetCondition(), condition->IsGtBias()), true_target); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2981 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2982 | } else { |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2983 | // Integer cases. |
| 2984 | Register lhs = InputRegisterAt(condition, 0); |
| 2985 | Operand rhs = InputOperandAt(condition, 1); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2986 | |
| 2987 | Condition arm64_cond; |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2988 | vixl::aarch64::Label* non_fallthrough_target; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2989 | if (true_target == nullptr) { |
| 2990 | arm64_cond = ARM64Condition(condition->GetOppositeCondition()); |
| 2991 | non_fallthrough_target = false_target; |
| 2992 | } else { |
| 2993 | arm64_cond = ARM64Condition(condition->GetCondition()); |
| 2994 | non_fallthrough_target = true_target; |
| 2995 | } |
| 2996 | |
Aart Bik | 086d27e | 2016-01-20 17:02:00 -0800 | [diff] [blame] | 2997 | if ((arm64_cond == eq || arm64_cond == ne || arm64_cond == lt || arm64_cond == ge) && |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2998 | rhs.IsImmediate() && (rhs.GetImmediate() == 0)) { |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2999 | switch (arm64_cond) { |
| 3000 | case eq: |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3001 | __ Cbz(lhs, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3002 | break; |
| 3003 | case ne: |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3004 | __ Cbnz(lhs, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3005 | break; |
| 3006 | case lt: |
| 3007 | // Test the sign bit and branch accordingly. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3008 | __ Tbnz(lhs, (lhs.IsX() ? kXRegSize : kWRegSize) - 1, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3009 | break; |
| 3010 | case ge: |
| 3011 | // Test the sign bit and branch accordingly. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3012 | __ Tbz(lhs, (lhs.IsX() ? kXRegSize : kWRegSize) - 1, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3013 | break; |
| 3014 | default: |
| 3015 | // Without the `static_cast` the compiler throws an error for |
| 3016 | // `-Werror=sign-promo`. |
| 3017 | LOG(FATAL) << "Unexpected condition: " << static_cast<int>(arm64_cond); |
| 3018 | } |
| 3019 | } else { |
| 3020 | __ Cmp(lhs, rhs); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3021 | __ B(arm64_cond, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3022 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3023 | } |
| 3024 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3025 | |
| 3026 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 3027 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 3028 | if (true_target != nullptr && false_target != nullptr) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3029 | __ B(false_target); |
| 3030 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3031 | |
| 3032 | if (fallthrough_target.IsLinked()) { |
| 3033 | __ Bind(&fallthrough_target); |
| 3034 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3035 | } |
| 3036 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3037 | void LocationsBuilderARM64::VisitIf(HIf* if_instr) { |
| 3038 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3039 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3040 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3041 | } |
| 3042 | } |
| 3043 | |
| 3044 | void InstructionCodeGeneratorARM64::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3045 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 3046 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3047 | vixl::aarch64::Label* true_target = codegen_->GetLabelOf(true_successor); |
| 3048 | if (codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor)) { |
| 3049 | true_target = nullptr; |
| 3050 | } |
| 3051 | vixl::aarch64::Label* false_target = codegen_->GetLabelOf(false_successor); |
| 3052 | if (codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor)) { |
| 3053 | false_target = nullptr; |
| 3054 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3055 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3056 | } |
| 3057 | |
| 3058 | void LocationsBuilderARM64::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 3059 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 3060 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3061 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3062 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3063 | } |
| 3064 | } |
| 3065 | |
| 3066 | void InstructionCodeGeneratorARM64::VisitDeoptimize(HDeoptimize* deoptimize) { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 3067 | SlowPathCodeARM64* slow_path = |
| 3068 | deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathARM64>(deoptimize); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3069 | GenerateTestAndBranch(deoptimize, |
| 3070 | /* condition_input_index */ 0, |
| 3071 | slow_path->GetEntryLabel(), |
| 3072 | /* false_target */ nullptr); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3073 | } |
| 3074 | |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3075 | static inline bool IsConditionOnFloatingPointValues(HInstruction* condition) { |
| 3076 | return condition->IsCondition() && |
| 3077 | Primitive::IsFloatingPointType(condition->InputAt(0)->GetType()); |
| 3078 | } |
| 3079 | |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3080 | static inline Condition GetConditionForSelect(HCondition* condition) { |
| 3081 | IfCondition cond = condition->AsCondition()->GetCondition(); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3082 | return IsConditionOnFloatingPointValues(condition) ? ARM64FPCondition(cond, condition->IsGtBias()) |
| 3083 | : ARM64Condition(cond); |
| 3084 | } |
| 3085 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3086 | void LocationsBuilderARM64::VisitSelect(HSelect* select) { |
| 3087 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(select); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3088 | if (Primitive::IsFloatingPointType(select->GetType())) { |
| 3089 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3090 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3091 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3092 | } else { |
| 3093 | HConstant* cst_true_value = select->GetTrueValue()->AsConstant(); |
| 3094 | HConstant* cst_false_value = select->GetFalseValue()->AsConstant(); |
| 3095 | bool is_true_value_constant = cst_true_value != nullptr; |
| 3096 | bool is_false_value_constant = cst_false_value != nullptr; |
| 3097 | // Ask VIXL whether we should synthesize constants in registers. |
| 3098 | // We give an arbitrary register to VIXL when dealing with non-constant inputs. |
| 3099 | Operand true_op = is_true_value_constant ? |
| 3100 | Operand(Int64FromConstant(cst_true_value)) : Operand(x1); |
| 3101 | Operand false_op = is_false_value_constant ? |
| 3102 | Operand(Int64FromConstant(cst_false_value)) : Operand(x2); |
| 3103 | bool true_value_in_register = false; |
| 3104 | bool false_value_in_register = false; |
| 3105 | MacroAssembler::GetCselSynthesisInformation( |
| 3106 | x0, true_op, false_op, &true_value_in_register, &false_value_in_register); |
| 3107 | true_value_in_register |= !is_true_value_constant; |
| 3108 | false_value_in_register |= !is_false_value_constant; |
| 3109 | |
| 3110 | locations->SetInAt(1, true_value_in_register ? Location::RequiresRegister() |
| 3111 | : Location::ConstantLocation(cst_true_value)); |
| 3112 | locations->SetInAt(0, false_value_in_register ? Location::RequiresRegister() |
| 3113 | : Location::ConstantLocation(cst_false_value)); |
| 3114 | locations->SetOut(Location::RequiresRegister()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3115 | } |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3116 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3117 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
| 3118 | locations->SetInAt(2, Location::RequiresRegister()); |
| 3119 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3120 | } |
| 3121 | |
| 3122 | void InstructionCodeGeneratorARM64::VisitSelect(HSelect* select) { |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3123 | HInstruction* cond = select->GetCondition(); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3124 | Condition csel_cond; |
| 3125 | |
| 3126 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 3127 | if (cond->IsCondition() && cond->GetNext() == select) { |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3128 | // Use the condition flags set by the previous instruction. |
| 3129 | csel_cond = GetConditionForSelect(cond->AsCondition()); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3130 | } else { |
| 3131 | __ Cmp(InputRegisterAt(select, 2), 0); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3132 | csel_cond = ne; |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3133 | } |
| 3134 | } else if (IsConditionOnFloatingPointValues(cond)) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3135 | GenerateFcmp(cond); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3136 | csel_cond = GetConditionForSelect(cond->AsCondition()); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3137 | } else { |
| 3138 | __ Cmp(InputRegisterAt(cond, 0), InputOperandAt(cond, 1)); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3139 | csel_cond = GetConditionForSelect(cond->AsCondition()); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3140 | } |
| 3141 | |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3142 | if (Primitive::IsFloatingPointType(select->GetType())) { |
| 3143 | __ Fcsel(OutputFPRegister(select), |
| 3144 | InputFPRegisterAt(select, 1), |
| 3145 | InputFPRegisterAt(select, 0), |
| 3146 | csel_cond); |
| 3147 | } else { |
| 3148 | __ Csel(OutputRegister(select), |
| 3149 | InputOperandAt(select, 1), |
| 3150 | InputOperandAt(select, 0), |
| 3151 | csel_cond); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3152 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3153 | } |
| 3154 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 3155 | void LocationsBuilderARM64::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| 3156 | new (GetGraph()->GetArena()) LocationSummary(info); |
| 3157 | } |
| 3158 | |
David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 3159 | void InstructionCodeGeneratorARM64::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 3160 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 3161 | } |
| 3162 | |
| 3163 | void CodeGeneratorARM64::GenerateNop() { |
| 3164 | __ Nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 3165 | } |
| 3166 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3167 | void LocationsBuilderARM64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 3168 | HandleFieldGet(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3169 | } |
| 3170 | |
| 3171 | void InstructionCodeGeneratorARM64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 3172 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3173 | } |
| 3174 | |
| 3175 | void LocationsBuilderARM64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 3176 | HandleFieldSet(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3177 | } |
| 3178 | |
| 3179 | void InstructionCodeGeneratorARM64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3180 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3181 | } |
| 3182 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3183 | static bool TypeCheckNeedsATemporary(TypeCheckKind type_check_kind) { |
| 3184 | return kEmitCompilerReadBarrier && |
| 3185 | (kUseBakerReadBarrier || |
| 3186 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 3187 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 3188 | type_check_kind == TypeCheckKind::kArrayObjectCheck); |
| 3189 | } |
| 3190 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3191 | void LocationsBuilderARM64::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3192 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3193 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 3194 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3195 | case TypeCheckKind::kExactCheck: |
| 3196 | case TypeCheckKind::kAbstractClassCheck: |
| 3197 | case TypeCheckKind::kClassHierarchyCheck: |
| 3198 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3199 | call_kind = |
| 3200 | kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3201 | break; |
| 3202 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3203 | case TypeCheckKind::kUnresolvedCheck: |
| 3204 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3205 | call_kind = LocationSummary::kCallOnSlowPath; |
| 3206 | break; |
| 3207 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3208 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3209 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3210 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3211 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3212 | // The "out" register is used as a temporary, so it overlaps with the inputs. |
| 3213 | // Note that TypeCheckSlowPathARM64 uses this register too. |
| 3214 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 3215 | // When read barriers are enabled, we need a temporary register for |
| 3216 | // some cases. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3217 | if (TypeCheckNeedsATemporary(type_check_kind)) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3218 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3219 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3220 | } |
| 3221 | |
| 3222 | void InstructionCodeGeneratorARM64::VisitInstanceOf(HInstanceOf* instruction) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3223 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3224 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3225 | Location obj_loc = locations->InAt(0); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3226 | Register obj = InputRegisterAt(instruction, 0); |
| 3227 | Register cls = InputRegisterAt(instruction, 1); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3228 | Location out_loc = locations->Out(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3229 | Register out = OutputRegister(instruction); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3230 | Location maybe_temp_loc = TypeCheckNeedsATemporary(type_check_kind) ? |
| 3231 | locations->GetTemp(0) : |
| 3232 | Location::NoLocation(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3233 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 3234 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 3235 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 3236 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3237 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3238 | vixl::aarch64::Label done, zero; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3239 | SlowPathCodeARM64* slow_path = nullptr; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3240 | |
| 3241 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 3242 | // Avoid null check if we know `obj` is not null. |
| 3243 | if (instruction->MustDoNullCheck()) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3244 | __ Cbz(obj, &zero); |
| 3245 | } |
| 3246 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3247 | // /* HeapReference<Class> */ out = obj->klass_ |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3248 | GenerateReferenceLoadTwoRegisters(instruction, out_loc, obj_loc, class_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3249 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3250 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3251 | case TypeCheckKind::kExactCheck: { |
| 3252 | __ Cmp(out, cls); |
| 3253 | __ Cset(out, eq); |
| 3254 | if (zero.IsLinked()) { |
| 3255 | __ B(&done); |
| 3256 | } |
| 3257 | break; |
| 3258 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3259 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3260 | case TypeCheckKind::kAbstractClassCheck: { |
| 3261 | // If the class is abstract, we eagerly fetch the super class of the |
| 3262 | // object to avoid doing a comparison we know will fail. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3263 | vixl::aarch64::Label loop, success; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3264 | __ Bind(&loop); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3265 | // /* HeapReference<Class> */ out = out->super_class_ |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3266 | GenerateReferenceLoadOneRegister(instruction, out_loc, super_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3267 | // If `out` is null, we use it for the result, and jump to `done`. |
| 3268 | __ Cbz(out, &done); |
| 3269 | __ Cmp(out, cls); |
| 3270 | __ B(ne, &loop); |
| 3271 | __ Mov(out, 1); |
| 3272 | if (zero.IsLinked()) { |
| 3273 | __ B(&done); |
| 3274 | } |
| 3275 | break; |
| 3276 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3277 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3278 | case TypeCheckKind::kClassHierarchyCheck: { |
| 3279 | // Walk over the class hierarchy to find a match. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3280 | vixl::aarch64::Label loop, success; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3281 | __ Bind(&loop); |
| 3282 | __ Cmp(out, cls); |
| 3283 | __ B(eq, &success); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3284 | // /* HeapReference<Class> */ out = out->super_class_ |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3285 | GenerateReferenceLoadOneRegister(instruction, out_loc, super_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3286 | __ Cbnz(out, &loop); |
| 3287 | // If `out` is null, we use it for the result, and jump to `done`. |
| 3288 | __ B(&done); |
| 3289 | __ Bind(&success); |
| 3290 | __ Mov(out, 1); |
| 3291 | if (zero.IsLinked()) { |
| 3292 | __ B(&done); |
| 3293 | } |
| 3294 | break; |
| 3295 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3296 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3297 | case TypeCheckKind::kArrayObjectCheck: { |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 3298 | // Do an exact check. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3299 | vixl::aarch64::Label exact_check; |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 3300 | __ Cmp(out, cls); |
| 3301 | __ B(eq, &exact_check); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3302 | // Otherwise, we need to check that the object's class is a non-primitive array. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3303 | // /* HeapReference<Class> */ out = out->component_type_ |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3304 | GenerateReferenceLoadOneRegister(instruction, out_loc, component_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3305 | // If `out` is null, we use it for the result, and jump to `done`. |
| 3306 | __ Cbz(out, &done); |
| 3307 | __ Ldrh(out, HeapOperand(out, primitive_offset)); |
| 3308 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
| 3309 | __ Cbnz(out, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 3310 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3311 | __ Mov(out, 1); |
| 3312 | __ B(&done); |
| 3313 | break; |
| 3314 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3315 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3316 | case TypeCheckKind::kArrayCheck: { |
| 3317 | __ Cmp(out, cls); |
| 3318 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3319 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM64(instruction, |
| 3320 | /* is_fatal */ false); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3321 | codegen_->AddSlowPath(slow_path); |
| 3322 | __ B(ne, slow_path->GetEntryLabel()); |
| 3323 | __ Mov(out, 1); |
| 3324 | if (zero.IsLinked()) { |
| 3325 | __ B(&done); |
| 3326 | } |
| 3327 | break; |
| 3328 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3329 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 3330 | case TypeCheckKind::kUnresolvedCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3331 | case TypeCheckKind::kInterfaceCheck: { |
| 3332 | // Note that we indeed only call on slow path, but we always go |
| 3333 | // into the slow path for the unresolved and interface check |
| 3334 | // cases. |
| 3335 | // |
| 3336 | // We cannot directly call the InstanceofNonTrivial runtime |
| 3337 | // entry point without resorting to a type checking slow path |
| 3338 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 3339 | // require to assign fixed registers for the inputs of this |
| 3340 | // HInstanceOf instruction (following the runtime calling |
| 3341 | // convention), which might be cluttered by the potential first |
| 3342 | // read barrier emission at the beginning of this method. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3343 | // |
| 3344 | // TODO: Introduce a new runtime entry point taking the object |
| 3345 | // to test (instead of its class) as argument, and let it deal |
| 3346 | // with the read barrier issues. This will let us refactor this |
| 3347 | // case of the `switch` code as it was previously (with a direct |
| 3348 | // call to the runtime not using a type checking slow path). |
| 3349 | // This should also be beneficial for the other cases above. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3350 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 3351 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM64(instruction, |
| 3352 | /* is_fatal */ false); |
| 3353 | codegen_->AddSlowPath(slow_path); |
| 3354 | __ B(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3355 | if (zero.IsLinked()) { |
| 3356 | __ B(&done); |
| 3357 | } |
| 3358 | break; |
| 3359 | } |
| 3360 | } |
| 3361 | |
| 3362 | if (zero.IsLinked()) { |
| 3363 | __ Bind(&zero); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 3364 | __ Mov(out, 0); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3365 | } |
| 3366 | |
| 3367 | if (done.IsLinked()) { |
| 3368 | __ Bind(&done); |
| 3369 | } |
| 3370 | |
| 3371 | if (slow_path != nullptr) { |
| 3372 | __ Bind(slow_path->GetExitLabel()); |
| 3373 | } |
| 3374 | } |
| 3375 | |
| 3376 | void LocationsBuilderARM64::VisitCheckCast(HCheckCast* instruction) { |
| 3377 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 3378 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
| 3379 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3380 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 3381 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3382 | case TypeCheckKind::kExactCheck: |
| 3383 | case TypeCheckKind::kAbstractClassCheck: |
| 3384 | case TypeCheckKind::kClassHierarchyCheck: |
| 3385 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3386 | call_kind = (throws_into_catch || kEmitCompilerReadBarrier) ? |
| 3387 | LocationSummary::kCallOnSlowPath : |
| 3388 | LocationSummary::kNoCall; // In fact, call on a fatal (non-returning) slow path. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3389 | break; |
| 3390 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3391 | case TypeCheckKind::kUnresolvedCheck: |
| 3392 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3393 | call_kind = LocationSummary::kCallOnSlowPath; |
| 3394 | break; |
| 3395 | } |
| 3396 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3397 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 3398 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3399 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3400 | // Note that TypeCheckSlowPathARM64 uses this "temp" register too. |
| 3401 | locations->AddTemp(Location::RequiresRegister()); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3402 | // When read barriers are enabled, we need an additional temporary |
| 3403 | // register for some cases. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3404 | if (TypeCheckNeedsATemporary(type_check_kind)) { |
| 3405 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3406 | } |
| 3407 | } |
| 3408 | |
| 3409 | void InstructionCodeGeneratorARM64::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3410 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3411 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3412 | Location obj_loc = locations->InAt(0); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3413 | Register obj = InputRegisterAt(instruction, 0); |
| 3414 | Register cls = InputRegisterAt(instruction, 1); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3415 | Location temp_loc = locations->GetTemp(0); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3416 | Location maybe_temp2_loc = TypeCheckNeedsATemporary(type_check_kind) ? |
| 3417 | locations->GetTemp(1) : |
| 3418 | Location::NoLocation(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3419 | Register temp = WRegisterFrom(temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3420 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 3421 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 3422 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 3423 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3424 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3425 | bool is_type_check_slow_path_fatal = |
| 3426 | (type_check_kind == TypeCheckKind::kExactCheck || |
| 3427 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 3428 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 3429 | type_check_kind == TypeCheckKind::kArrayObjectCheck) && |
| 3430 | !instruction->CanThrowIntoCatchBlock(); |
| 3431 | SlowPathCodeARM64* type_check_slow_path = |
| 3432 | new (GetGraph()->GetArena()) TypeCheckSlowPathARM64(instruction, |
| 3433 | is_type_check_slow_path_fatal); |
| 3434 | codegen_->AddSlowPath(type_check_slow_path); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3435 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3436 | vixl::aarch64::Label done; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3437 | // Avoid null check if we know obj is not null. |
| 3438 | if (instruction->MustDoNullCheck()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 3439 | __ Cbz(obj, &done); |
| 3440 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3441 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3442 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3443 | GenerateReferenceLoadTwoRegisters(instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame] | 3444 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3445 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3446 | case TypeCheckKind::kExactCheck: |
| 3447 | case TypeCheckKind::kArrayCheck: { |
| 3448 | __ Cmp(temp, cls); |
| 3449 | // Jump to slow path for throwing the exception or doing a |
| 3450 | // more involved array check. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3451 | __ B(ne, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3452 | break; |
| 3453 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3454 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3455 | case TypeCheckKind::kAbstractClassCheck: { |
| 3456 | // If the class is abstract, we eagerly fetch the super class of the |
| 3457 | // object to avoid doing a comparison we know will fail. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3458 | vixl::aarch64::Label loop, compare_classes; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3459 | __ Bind(&loop); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3460 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3461 | GenerateReferenceLoadOneRegister(instruction, temp_loc, super_offset, maybe_temp2_loc); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3462 | |
| 3463 | // If the class reference currently in `temp` is not null, jump |
| 3464 | // to the `compare_classes` label to compare it with the checked |
| 3465 | // class. |
| 3466 | __ Cbnz(temp, &compare_classes); |
| 3467 | // Otherwise, jump to the slow path to throw the exception. |
| 3468 | // |
| 3469 | // But before, move back the object's class into `temp` before |
| 3470 | // going into the slow path, as it has been overwritten in the |
| 3471 | // meantime. |
| 3472 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3473 | GenerateReferenceLoadTwoRegisters( |
| 3474 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3475 | __ B(type_check_slow_path->GetEntryLabel()); |
| 3476 | |
| 3477 | __ Bind(&compare_classes); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3478 | __ Cmp(temp, cls); |
| 3479 | __ B(ne, &loop); |
| 3480 | break; |
| 3481 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3482 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3483 | case TypeCheckKind::kClassHierarchyCheck: { |
| 3484 | // Walk over the class hierarchy to find a match. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3485 | vixl::aarch64::Label loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3486 | __ Bind(&loop); |
| 3487 | __ Cmp(temp, cls); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 3488 | __ B(eq, &done); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3489 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3490 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3491 | GenerateReferenceLoadOneRegister(instruction, temp_loc, super_offset, maybe_temp2_loc); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3492 | |
| 3493 | // If the class reference currently in `temp` is not null, jump |
| 3494 | // back at the beginning of the loop. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3495 | __ Cbnz(temp, &loop); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3496 | // Otherwise, jump to the slow path to throw the exception. |
| 3497 | // |
| 3498 | // But before, move back the object's class into `temp` before |
| 3499 | // going into the slow path, as it has been overwritten in the |
| 3500 | // meantime. |
| 3501 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3502 | GenerateReferenceLoadTwoRegisters( |
| 3503 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3504 | __ B(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3505 | break; |
| 3506 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3507 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3508 | case TypeCheckKind::kArrayObjectCheck: { |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 3509 | // Do an exact check. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3510 | vixl::aarch64::Label check_non_primitive_component_type; |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 3511 | __ Cmp(temp, cls); |
| 3512 | __ B(eq, &done); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3513 | |
| 3514 | // Otherwise, we need to check that the object's class is a non-primitive array. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3515 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3516 | GenerateReferenceLoadOneRegister(instruction, temp_loc, component_offset, maybe_temp2_loc); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3517 | |
| 3518 | // If the component type is not null (i.e. the object is indeed |
| 3519 | // an array), jump to label `check_non_primitive_component_type` |
| 3520 | // to further check that this component type is not a primitive |
| 3521 | // type. |
| 3522 | __ Cbnz(temp, &check_non_primitive_component_type); |
| 3523 | // Otherwise, jump to the slow path to throw the exception. |
| 3524 | // |
| 3525 | // But before, move back the object's class into `temp` before |
| 3526 | // going into the slow path, as it has been overwritten in the |
| 3527 | // meantime. |
| 3528 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3529 | GenerateReferenceLoadTwoRegisters( |
| 3530 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3531 | __ B(type_check_slow_path->GetEntryLabel()); |
| 3532 | |
| 3533 | __ Bind(&check_non_primitive_component_type); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3534 | __ Ldrh(temp, HeapOperand(temp, primitive_offset)); |
| 3535 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3536 | __ Cbz(temp, &done); |
| 3537 | // Same comment as above regarding `temp` and the slow path. |
| 3538 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3539 | GenerateReferenceLoadTwoRegisters( |
| 3540 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3541 | __ B(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3542 | break; |
| 3543 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3544 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 3545 | case TypeCheckKind::kUnresolvedCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3546 | case TypeCheckKind::kInterfaceCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3547 | // We always go into the type check slow path for the unresolved |
| 3548 | // and interface check cases. |
| 3549 | // |
| 3550 | // We cannot directly call the CheckCast runtime entry point |
| 3551 | // without resorting to a type checking slow path here (i.e. by |
| 3552 | // calling InvokeRuntime directly), as it would require to |
| 3553 | // assign fixed registers for the inputs of this HInstanceOf |
| 3554 | // instruction (following the runtime calling convention), which |
| 3555 | // might be cluttered by the potential first read barrier |
| 3556 | // emission at the beginning of this method. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3557 | // |
| 3558 | // TODO: Introduce a new runtime entry point taking the object |
| 3559 | // to test (instead of its class) as argument, and let it deal |
| 3560 | // with the read barrier issues. This will let us refactor this |
| 3561 | // case of the `switch` code as it was previously (with a direct |
| 3562 | // call to the runtime not using a type checking slow path). |
| 3563 | // This should also be beneficial for the other cases above. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3564 | __ B(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3565 | break; |
| 3566 | } |
Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame] | 3567 | __ Bind(&done); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3568 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3569 | __ Bind(type_check_slow_path->GetExitLabel()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3570 | } |
| 3571 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3572 | void LocationsBuilderARM64::VisitIntConstant(HIntConstant* constant) { |
| 3573 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant); |
| 3574 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3575 | } |
| 3576 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3577 | void InstructionCodeGeneratorARM64::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3578 | // Will be generated at use site. |
| 3579 | } |
| 3580 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 3581 | void LocationsBuilderARM64::VisitNullConstant(HNullConstant* constant) { |
| 3582 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant); |
| 3583 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3584 | } |
| 3585 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3586 | void InstructionCodeGeneratorARM64::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 3587 | // Will be generated at use site. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 3588 | } |
| 3589 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 3590 | void LocationsBuilderARM64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 3591 | // The trampoline uses the same calling convention as dex calling conventions, |
| 3592 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 3593 | // the method_idx. |
| 3594 | HandleInvoke(invoke); |
| 3595 | } |
| 3596 | |
| 3597 | void InstructionCodeGeneratorARM64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 3598 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 3599 | } |
| 3600 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3601 | void LocationsBuilderARM64::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 3602 | InvokeDexCallingConventionVisitorARM64 calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 3603 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3604 | } |
| 3605 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3606 | void LocationsBuilderARM64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 3607 | HandleInvoke(invoke); |
| 3608 | } |
| 3609 | |
| 3610 | void InstructionCodeGeneratorARM64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 3611 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3612 | LocationSummary* locations = invoke->GetLocations(); |
| 3613 | Register temp = XRegisterFrom(locations->GetTemp(0)); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3614 | Location receiver = locations->InAt(0); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3615 | Offset class_offset = mirror::Object::ClassOffset(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 3616 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64PointerSize); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3617 | |
| 3618 | // The register ip1 is required to be used for the hidden argument in |
| 3619 | // art_quick_imt_conflict_trampoline, so prevent VIXL from using it. |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 3620 | MacroAssembler* masm = GetVIXLAssembler(); |
| 3621 | UseScratchRegisterScope scratch_scope(masm); |
| 3622 | BlockPoolsScope block_pools(masm); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3623 | scratch_scope.Exclude(ip1); |
| 3624 | __ Mov(ip1, invoke->GetDexMethodIndex()); |
| 3625 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3626 | if (receiver.IsStackSlot()) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 3627 | __ Ldr(temp.W(), StackOperandFrom(receiver)); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3628 | // /* HeapReference<Class> */ temp = temp->klass_ |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 3629 | __ Ldr(temp.W(), HeapOperand(temp.W(), class_offset)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3630 | } else { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3631 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 3632 | __ Ldr(temp.W(), HeapOperandFrom(receiver, class_offset)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3633 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3634 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3635 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 3636 | // emit a read barrier for the previous class reference load. |
| 3637 | // However this is not required in practice, as this is an |
| 3638 | // intermediate/temporary reference and because the current |
| 3639 | // concurrent copying collector keeps the from-space memory |
| 3640 | // intact/accessible until the end of the marking phase (the |
| 3641 | // concurrent copying collector may not in the future). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3642 | GetAssembler()->MaybeUnpoisonHeapReference(temp.W()); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 3643 | __ Ldr(temp, |
| 3644 | MemOperand(temp, mirror::Class::ImtPtrOffset(kArm64PointerSize).Uint32Value())); |
| 3645 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 3646 | invoke->GetImtIndex(), kArm64PointerSize)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3647 | // temp = temp->GetImtEntryAt(method_offset); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 3648 | __ Ldr(temp, MemOperand(temp, method_offset)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3649 | // lr = temp->GetEntryPoint(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 3650 | __ Ldr(lr, MemOperand(temp, entry_point.Int32Value())); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3651 | // lr(); |
| 3652 | __ Blr(lr); |
| 3653 | DCHECK(!codegen_->IsLeafMethod()); |
| 3654 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 3655 | } |
| 3656 | |
| 3657 | void LocationsBuilderARM64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 3658 | IntrinsicLocationsBuilderARM64 intrinsic(GetGraph()->GetArena()); |
| 3659 | if (intrinsic.TryDispatch(invoke)) { |
| 3660 | return; |
| 3661 | } |
| 3662 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3663 | HandleInvoke(invoke); |
| 3664 | } |
| 3665 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 3666 | void LocationsBuilderARM64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 3667 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 3668 | // art::PrepareForRegisterAllocation. |
| 3669 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3670 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 3671 | IntrinsicLocationsBuilderARM64 intrinsic(GetGraph()->GetArena()); |
| 3672 | if (intrinsic.TryDispatch(invoke)) { |
| 3673 | return; |
| 3674 | } |
| 3675 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3676 | HandleInvoke(invoke); |
| 3677 | } |
| 3678 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 3679 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARM64* codegen) { |
| 3680 | if (invoke->GetLocations()->Intrinsified()) { |
| 3681 | IntrinsicCodeGeneratorARM64 intrinsic(codegen); |
| 3682 | intrinsic.Dispatch(invoke); |
| 3683 | return true; |
| 3684 | } |
| 3685 | return false; |
| 3686 | } |
| 3687 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3688 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorARM64::GetSupportedInvokeStaticOrDirectDispatch( |
| 3689 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
| 3690 | MethodReference target_method ATTRIBUTE_UNUSED) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3691 | // On ARM64 we support all dispatch types. |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3692 | return desired_dispatch_info; |
| 3693 | } |
| 3694 | |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 3695 | void CodeGeneratorARM64::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3696 | // For better instruction scheduling we load the direct code pointer before the method pointer. |
| 3697 | bool direct_code_loaded = false; |
| 3698 | switch (invoke->GetCodePtrLocation()) { |
| 3699 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 3700 | // LR = code address from literal pool with link-time patch. |
| 3701 | __ Ldr(lr, DeduplicateMethodCodeLiteral(invoke->GetTargetMethod())); |
| 3702 | direct_code_loaded = true; |
| 3703 | break; |
| 3704 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
| 3705 | // LR = invoke->GetDirectCodePtr(); |
| 3706 | __ Ldr(lr, DeduplicateUint64Literal(invoke->GetDirectCodePtr())); |
| 3707 | direct_code_loaded = true; |
| 3708 | break; |
| 3709 | default: |
| 3710 | break; |
| 3711 | } |
| 3712 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 3713 | // 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] | 3714 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 3715 | switch (invoke->GetMethodLoadKind()) { |
| 3716 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: |
| 3717 | // temp = thread->string_init_entrypoint |
Alexandre Rames | 6dc0174 | 2015-11-12 14:44:19 +0000 | [diff] [blame] | 3718 | __ Ldr(XRegisterFrom(temp), MemOperand(tr, invoke->GetStringInitOffset())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3719 | break; |
| 3720 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3721 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3722 | break; |
| 3723 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 3724 | // Load method address from literal pool. |
Alexandre Rames | 6dc0174 | 2015-11-12 14:44:19 +0000 | [diff] [blame] | 3725 | __ Ldr(XRegisterFrom(temp), DeduplicateUint64Literal(invoke->GetMethodAddress())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3726 | break; |
| 3727 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup: |
| 3728 | // Load method address from literal pool with a link-time patch. |
Alexandre Rames | 6dc0174 | 2015-11-12 14:44:19 +0000 | [diff] [blame] | 3729 | __ Ldr(XRegisterFrom(temp), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3730 | DeduplicateMethodAddressLiteral(invoke->GetTargetMethod())); |
| 3731 | break; |
| 3732 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: { |
| 3733 | // Add ADRP with its PC-relative DexCache access patch. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 3734 | const DexFile& dex_file = *invoke->GetTargetMethod().dex_file; |
| 3735 | uint32_t element_offset = invoke->GetDexCacheArrayOffset(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3736 | vixl::aarch64::Label* adrp_label = NewPcRelativeDexCacheArrayPatch(dex_file, element_offset); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3737 | { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3738 | SingleEmissionCheckScope guard(GetVIXLAssembler()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 3739 | __ Bind(adrp_label); |
| 3740 | __ adrp(XRegisterFrom(temp), /* offset placeholder */ 0); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3741 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3742 | // Add LDR with its PC-relative DexCache access patch. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3743 | vixl::aarch64::Label* ldr_label = |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 3744 | NewPcRelativeDexCacheArrayPatch(dex_file, element_offset, adrp_label); |
Alexandre Rames | 6dc0174 | 2015-11-12 14:44:19 +0000 | [diff] [blame] | 3745 | { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3746 | SingleEmissionCheckScope guard(GetVIXLAssembler()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 3747 | __ Bind(ldr_label); |
| 3748 | __ ldr(XRegisterFrom(temp), MemOperand(XRegisterFrom(temp), /* offset placeholder */ 0)); |
Alexandre Rames | 6dc0174 | 2015-11-12 14:44:19 +0000 | [diff] [blame] | 3749 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3750 | break; |
Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 3751 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3752 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3753 | Location current_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3754 | Register reg = XRegisterFrom(temp); |
| 3755 | Register method_reg; |
| 3756 | if (current_method.IsRegister()) { |
| 3757 | method_reg = XRegisterFrom(current_method); |
| 3758 | } else { |
| 3759 | DCHECK(invoke->GetLocations()->Intrinsified()); |
| 3760 | DCHECK(!current_method.IsValid()); |
| 3761 | method_reg = reg; |
| 3762 | __ Ldr(reg.X(), MemOperand(sp, kCurrentMethodStackOffset)); |
| 3763 | } |
Vladimir Marko | b2c431e | 2015-08-19 12:45:42 +0000 | [diff] [blame] | 3764 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3765 | // /* ArtMethod*[] */ temp = temp.ptr_sized_fields_->dex_cache_resolved_methods_; |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 3766 | __ Ldr(reg.X(), |
| 3767 | MemOperand(method_reg.X(), |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 3768 | ArtMethod::DexCacheResolvedMethodsOffset(kArm64PointerSize).Int32Value())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3769 | // temp = temp[index_in_cache]; |
Vladimir Marko | 40ecb12 | 2016-04-06 17:33:41 +0100 | [diff] [blame] | 3770 | // Note: Don't use invoke->GetTargetMethod() as it may point to a different dex file. |
| 3771 | uint32_t index_in_cache = invoke->GetDexMethodIndex(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3772 | __ Ldr(reg.X(), MemOperand(reg.X(), GetCachePointerOffset(index_in_cache))); |
| 3773 | break; |
| 3774 | } |
| 3775 | } |
| 3776 | |
| 3777 | switch (invoke->GetCodePtrLocation()) { |
| 3778 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 3779 | __ Bl(&frame_entry_label_); |
| 3780 | break; |
| 3781 | case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative: { |
| 3782 | relative_call_patches_.emplace_back(invoke->GetTargetMethod()); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3783 | vixl::aarch64::Label* label = &relative_call_patches_.back().label; |
| 3784 | SingleEmissionCheckScope guard(GetVIXLAssembler()); |
Alexandre Rames | 6dc0174 | 2015-11-12 14:44:19 +0000 | [diff] [blame] | 3785 | __ Bind(label); |
| 3786 | __ 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] | 3787 | break; |
| 3788 | } |
| 3789 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 3790 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
| 3791 | // LR prepared above for better instruction scheduling. |
| 3792 | DCHECK(direct_code_loaded); |
| 3793 | // lr() |
| 3794 | __ Blr(lr); |
| 3795 | break; |
| 3796 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 3797 | // LR = callee_method->entry_point_from_quick_compiled_code_; |
| 3798 | __ Ldr(lr, MemOperand( |
Alexandre Rames | 6dc0174 | 2015-11-12 14:44:19 +0000 | [diff] [blame] | 3799 | XRegisterFrom(callee_method), |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 3800 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64PointerSize).Int32Value())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3801 | // lr() |
| 3802 | __ Blr(lr); |
| 3803 | break; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 3804 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3805 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 3806 | DCHECK(!IsLeafMethod()); |
| 3807 | } |
| 3808 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 3809 | void CodeGeneratorARM64::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_in) { |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 3810 | // Use the calling convention instead of the location of the receiver, as |
| 3811 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 3812 | // slow path, the arguments have been moved to the right place, so here we are |
| 3813 | // guaranteed that the receiver is the first register of the calling convention. |
| 3814 | InvokeDexCallingConvention calling_convention; |
| 3815 | Register receiver = calling_convention.GetRegisterAt(0); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 3816 | Register temp = XRegisterFrom(temp_in); |
| 3817 | size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 3818 | invoke->GetVTableIndex(), kArm64PointerSize).SizeValue(); |
| 3819 | Offset class_offset = mirror::Object::ClassOffset(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 3820 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64PointerSize); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 3821 | |
| 3822 | BlockPoolsScope block_pools(GetVIXLAssembler()); |
| 3823 | |
| 3824 | DCHECK(receiver.IsRegister()); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3825 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 3826 | __ Ldr(temp.W(), HeapOperandFrom(LocationFrom(receiver), class_offset)); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 3827 | MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3828 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 3829 | // emit a read barrier for the previous class reference load. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3830 | // intermediate/temporary reference and because the current |
| 3831 | // concurrent copying collector keeps the from-space memory |
| 3832 | // intact/accessible until the end of the marking phase (the |
| 3833 | // concurrent copying collector may not in the future). |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 3834 | GetAssembler()->MaybeUnpoisonHeapReference(temp.W()); |
| 3835 | // temp = temp->GetMethodAt(method_offset); |
| 3836 | __ Ldr(temp, MemOperand(temp, method_offset)); |
| 3837 | // lr = temp->GetEntryPoint(); |
| 3838 | __ Ldr(lr, MemOperand(temp, entry_point.SizeValue())); |
| 3839 | // lr(); |
| 3840 | __ Blr(lr); |
| 3841 | } |
| 3842 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3843 | vixl::aarch64::Label* CodeGeneratorARM64::NewPcRelativeStringPatch( |
| 3844 | const DexFile& dex_file, |
| 3845 | uint32_t string_index, |
| 3846 | vixl::aarch64::Label* adrp_label) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 3847 | return NewPcRelativePatch(dex_file, string_index, adrp_label, &pc_relative_string_patches_); |
| 3848 | } |
| 3849 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3850 | vixl::aarch64::Label* CodeGeneratorARM64::NewPcRelativeTypePatch( |
| 3851 | const DexFile& dex_file, |
| 3852 | uint32_t type_index, |
| 3853 | vixl::aarch64::Label* adrp_label) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 3854 | return NewPcRelativePatch(dex_file, type_index, adrp_label, &pc_relative_type_patches_); |
| 3855 | } |
| 3856 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3857 | vixl::aarch64::Label* CodeGeneratorARM64::NewPcRelativeDexCacheArrayPatch( |
| 3858 | const DexFile& dex_file, |
| 3859 | uint32_t element_offset, |
| 3860 | vixl::aarch64::Label* adrp_label) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 3861 | return NewPcRelativePatch(dex_file, element_offset, adrp_label, &pc_relative_dex_cache_patches_); |
| 3862 | } |
| 3863 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3864 | vixl::aarch64::Label* CodeGeneratorARM64::NewPcRelativePatch( |
| 3865 | const DexFile& dex_file, |
| 3866 | uint32_t offset_or_index, |
| 3867 | vixl::aarch64::Label* adrp_label, |
| 3868 | ArenaDeque<PcRelativePatchInfo>* patches) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 3869 | // Add a patch entry and return the label. |
| 3870 | patches->emplace_back(dex_file, offset_or_index); |
| 3871 | PcRelativePatchInfo* info = &patches->back(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3872 | vixl::aarch64::Label* label = &info->label; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 3873 | // If adrp_label is null, this is the ADRP patch and needs to point to its own label. |
| 3874 | info->pc_insn_label = (adrp_label != nullptr) ? adrp_label : label; |
| 3875 | return label; |
| 3876 | } |
| 3877 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3878 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateBootImageStringLiteral( |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 3879 | const DexFile& dex_file, uint32_t string_index) { |
| 3880 | return boot_image_string_patches_.GetOrCreate( |
| 3881 | StringReference(&dex_file, string_index), |
| 3882 | [this]() { return __ CreateLiteralDestroyedWithPool<uint32_t>(/* placeholder */ 0u); }); |
| 3883 | } |
| 3884 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3885 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateBootImageTypeLiteral( |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 3886 | const DexFile& dex_file, uint32_t type_index) { |
| 3887 | return boot_image_type_patches_.GetOrCreate( |
| 3888 | TypeReference(&dex_file, type_index), |
| 3889 | [this]() { return __ CreateLiteralDestroyedWithPool<uint32_t>(/* placeholder */ 0u); }); |
| 3890 | } |
| 3891 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3892 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateBootImageAddressLiteral( |
| 3893 | uint64_t address) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 3894 | bool needs_patch = GetCompilerOptions().GetIncludePatchInformation(); |
| 3895 | Uint32ToLiteralMap* map = needs_patch ? &boot_image_address_patches_ : &uint32_literals_; |
| 3896 | return DeduplicateUint32Literal(dchecked_integral_cast<uint32_t>(address), map); |
| 3897 | } |
| 3898 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3899 | vixl::aarch64::Literal<uint64_t>* CodeGeneratorARM64::DeduplicateDexCacheAddressLiteral( |
| 3900 | uint64_t address) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 3901 | return DeduplicateUint64Literal(address); |
| 3902 | } |
| 3903 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3904 | void CodeGeneratorARM64::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) { |
| 3905 | DCHECK(linker_patches->empty()); |
| 3906 | size_t size = |
| 3907 | method_patches_.size() + |
| 3908 | call_patches_.size() + |
| 3909 | relative_call_patches_.size() + |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 3910 | pc_relative_dex_cache_patches_.size() + |
| 3911 | boot_image_string_patches_.size() + |
| 3912 | pc_relative_string_patches_.size() + |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 3913 | boot_image_type_patches_.size() + |
| 3914 | pc_relative_type_patches_.size() + |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 3915 | boot_image_address_patches_.size(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3916 | linker_patches->reserve(size); |
| 3917 | for (const auto& entry : method_patches_) { |
| 3918 | const MethodReference& target_method = entry.first; |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3919 | vixl::aarch64::Literal<uint64_t>* literal = entry.second; |
| 3920 | linker_patches->push_back(LinkerPatch::MethodPatch(literal->GetOffset(), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3921 | target_method.dex_file, |
| 3922 | target_method.dex_method_index)); |
| 3923 | } |
| 3924 | for (const auto& entry : call_patches_) { |
| 3925 | const MethodReference& target_method = entry.first; |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3926 | vixl::aarch64::Literal<uint64_t>* literal = entry.second; |
| 3927 | linker_patches->push_back(LinkerPatch::CodePatch(literal->GetOffset(), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3928 | target_method.dex_file, |
| 3929 | target_method.dex_method_index)); |
| 3930 | } |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3931 | for (const MethodPatchInfo<vixl::aarch64::Label>& info : relative_call_patches_) { |
| 3932 | linker_patches->push_back(LinkerPatch::RelativeCodePatch(info.label.GetLocation(), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3933 | info.target_method.dex_file, |
| 3934 | info.target_method.dex_method_index)); |
| 3935 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 3936 | for (const PcRelativePatchInfo& info : pc_relative_dex_cache_patches_) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3937 | linker_patches->push_back(LinkerPatch::DexCacheArrayPatch(info.label.GetLocation(), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3938 | &info.target_dex_file, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3939 | info.pc_insn_label->GetLocation(), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 3940 | info.offset_or_index)); |
| 3941 | } |
| 3942 | for (const auto& entry : boot_image_string_patches_) { |
| 3943 | const StringReference& target_string = entry.first; |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3944 | vixl::aarch64::Literal<uint32_t>* literal = entry.second; |
| 3945 | linker_patches->push_back(LinkerPatch::StringPatch(literal->GetOffset(), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 3946 | target_string.dex_file, |
| 3947 | target_string.string_index)); |
| 3948 | } |
| 3949 | for (const PcRelativePatchInfo& info : pc_relative_string_patches_) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3950 | linker_patches->push_back(LinkerPatch::RelativeStringPatch(info.label.GetLocation(), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 3951 | &info.target_dex_file, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3952 | info.pc_insn_label->GetLocation(), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 3953 | info.offset_or_index)); |
| 3954 | } |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 3955 | for (const auto& entry : boot_image_type_patches_) { |
| 3956 | const TypeReference& target_type = entry.first; |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3957 | vixl::aarch64::Literal<uint32_t>* literal = entry.second; |
| 3958 | linker_patches->push_back(LinkerPatch::TypePatch(literal->GetOffset(), |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 3959 | target_type.dex_file, |
| 3960 | target_type.type_index)); |
| 3961 | } |
| 3962 | for (const PcRelativePatchInfo& info : pc_relative_type_patches_) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3963 | linker_patches->push_back(LinkerPatch::RelativeTypePatch(info.label.GetLocation(), |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 3964 | &info.target_dex_file, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3965 | info.pc_insn_label->GetLocation(), |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 3966 | info.offset_or_index)); |
| 3967 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 3968 | for (const auto& entry : boot_image_address_patches_) { |
| 3969 | DCHECK(GetCompilerOptions().GetIncludePatchInformation()); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3970 | vixl::aarch64::Literal<uint32_t>* literal = entry.second; |
| 3971 | linker_patches->push_back(LinkerPatch::RecordPosition(literal->GetOffset())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3972 | } |
| 3973 | } |
| 3974 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3975 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateUint32Literal(uint32_t value, |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 3976 | Uint32ToLiteralMap* map) { |
| 3977 | return map->GetOrCreate( |
| 3978 | value, |
| 3979 | [this, value]() { return __ CreateLiteralDestroyedWithPool<uint32_t>(value); }); |
| 3980 | } |
| 3981 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3982 | vixl::aarch64::Literal<uint64_t>* CodeGeneratorARM64::DeduplicateUint64Literal(uint64_t value) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 3983 | return uint64_literals_.GetOrCreate( |
| 3984 | value, |
| 3985 | [this, value]() { return __ CreateLiteralDestroyedWithPool<uint64_t>(value); }); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3986 | } |
| 3987 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3988 | vixl::aarch64::Literal<uint64_t>* CodeGeneratorARM64::DeduplicateMethodLiteral( |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3989 | MethodReference target_method, |
| 3990 | MethodToLiteralMap* map) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 3991 | return map->GetOrCreate( |
| 3992 | target_method, |
| 3993 | [this]() { return __ CreateLiteralDestroyedWithPool<uint64_t>(/* placeholder */ 0u); }); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3994 | } |
| 3995 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3996 | vixl::aarch64::Literal<uint64_t>* CodeGeneratorARM64::DeduplicateMethodAddressLiteral( |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3997 | MethodReference target_method) { |
| 3998 | return DeduplicateMethodLiteral(target_method, &method_patches_); |
| 3999 | } |
| 4000 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4001 | vixl::aarch64::Literal<uint64_t>* CodeGeneratorARM64::DeduplicateMethodCodeLiteral( |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4002 | MethodReference target_method) { |
| 4003 | return DeduplicateMethodLiteral(target_method, &call_patches_); |
| 4004 | } |
| 4005 | |
| 4006 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4007 | void InstructionCodeGeneratorARM64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 4008 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 4009 | // art::PrepareForRegisterAllocation. |
| 4010 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4011 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4012 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 4013 | return; |
| 4014 | } |
| 4015 | |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 4016 | BlockPoolsScope block_pools(GetVIXLAssembler()); |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 4017 | LocationSummary* locations = invoke->GetLocations(); |
| 4018 | codegen_->GenerateStaticOrDirectCall( |
| 4019 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 4020 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4021 | } |
| 4022 | |
| 4023 | void InstructionCodeGeneratorARM64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4024 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 4025 | return; |
| 4026 | } |
| 4027 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4028 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4029 | DCHECK(!codegen_->IsLeafMethod()); |
| 4030 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 4031 | } |
| 4032 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4033 | HLoadClass::LoadKind CodeGeneratorARM64::GetSupportedLoadClassKind( |
| 4034 | HLoadClass::LoadKind desired_class_load_kind) { |
| 4035 | if (kEmitCompilerReadBarrier) { |
| 4036 | switch (desired_class_load_kind) { |
| 4037 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: |
| 4038 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
| 4039 | case HLoadClass::LoadKind::kBootImageAddress: |
| 4040 | // TODO: Implement for read barrier. |
| 4041 | return HLoadClass::LoadKind::kDexCacheViaMethod; |
| 4042 | default: |
| 4043 | break; |
| 4044 | } |
| 4045 | } |
| 4046 | switch (desired_class_load_kind) { |
| 4047 | case HLoadClass::LoadKind::kReferrersClass: |
| 4048 | break; |
| 4049 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: |
| 4050 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 4051 | break; |
| 4052 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
| 4053 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 4054 | break; |
| 4055 | case HLoadClass::LoadKind::kBootImageAddress: |
| 4056 | break; |
| 4057 | case HLoadClass::LoadKind::kDexCacheAddress: |
| 4058 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 4059 | break; |
| 4060 | case HLoadClass::LoadKind::kDexCachePcRelative: |
| 4061 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| 4062 | break; |
| 4063 | case HLoadClass::LoadKind::kDexCacheViaMethod: |
| 4064 | break; |
| 4065 | } |
| 4066 | return desired_class_load_kind; |
| 4067 | } |
| 4068 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4069 | void LocationsBuilderARM64::VisitLoadClass(HLoadClass* cls) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4070 | if (cls->NeedsAccessCheck()) { |
| 4071 | InvokeRuntimeCallingConvention calling_convention; |
| 4072 | CodeGenerator::CreateLoadClassLocationSummary( |
| 4073 | cls, |
| 4074 | LocationFrom(calling_convention.GetRegisterAt(0)), |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4075 | LocationFrom(vixl::aarch64::x0), |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4076 | /* code_generator_supports_read_barrier */ true); |
| 4077 | return; |
| 4078 | } |
| 4079 | |
| 4080 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || kEmitCompilerReadBarrier) |
| 4081 | ? LocationSummary::kCallOnSlowPath |
| 4082 | : LocationSummary::kNoCall; |
| 4083 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(cls, call_kind); |
| 4084 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
| 4085 | if (load_kind == HLoadClass::LoadKind::kReferrersClass || |
| 4086 | load_kind == HLoadClass::LoadKind::kDexCacheViaMethod) { |
| 4087 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4088 | } |
| 4089 | locations->SetOut(Location::RequiresRegister()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4090 | } |
| 4091 | |
| 4092 | void InstructionCodeGeneratorARM64::VisitLoadClass(HLoadClass* cls) { |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 4093 | if (cls->NeedsAccessCheck()) { |
| 4094 | codegen_->MoveConstant(cls->GetLocations()->GetTemp(0), cls->GetTypeIndex()); |
| 4095 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pInitializeTypeAndVerifyAccess), |
| 4096 | cls, |
| 4097 | cls->GetDexPc(), |
| 4098 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 4099 | CheckEntrypointTypes<kQuickInitializeTypeAndVerifyAccess, void*, uint32_t>(); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 4100 | return; |
| 4101 | } |
| 4102 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4103 | Location out_loc = cls->GetLocations()->Out(); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 4104 | Register out = OutputRegister(cls); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4105 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4106 | bool generate_null_check = false; |
| 4107 | switch (cls->GetLoadKind()) { |
| 4108 | case HLoadClass::LoadKind::kReferrersClass: { |
| 4109 | DCHECK(!cls->CanCallRuntime()); |
| 4110 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 4111 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 4112 | Register current_method = InputRegisterAt(cls, 0); |
| 4113 | GenerateGcRootFieldLoad( |
| 4114 | cls, out_loc, current_method, ArtMethod::DeclaringClassOffset().Int32Value()); |
| 4115 | break; |
| 4116 | } |
| 4117 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: |
| 4118 | DCHECK(!kEmitCompilerReadBarrier); |
| 4119 | __ Ldr(out, codegen_->DeduplicateBootImageTypeLiteral(cls->GetDexFile(), |
| 4120 | cls->GetTypeIndex())); |
| 4121 | break; |
| 4122 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { |
| 4123 | DCHECK(!kEmitCompilerReadBarrier); |
| 4124 | // Add ADRP with its PC-relative type patch. |
| 4125 | const DexFile& dex_file = cls->GetDexFile(); |
| 4126 | uint32_t type_index = cls->GetTypeIndex(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4127 | vixl::aarch64::Label* adrp_label = codegen_->NewPcRelativeTypePatch(dex_file, type_index); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4128 | { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4129 | SingleEmissionCheckScope guard(GetVIXLAssembler()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4130 | __ Bind(adrp_label); |
| 4131 | __ adrp(out.X(), /* offset placeholder */ 0); |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 4132 | } |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4133 | // Add ADD with its PC-relative type patch. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4134 | vixl::aarch64::Label* add_label = |
| 4135 | codegen_->NewPcRelativeTypePatch(dex_file, type_index, adrp_label); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4136 | { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4137 | SingleEmissionCheckScope guard(GetVIXLAssembler()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4138 | __ Bind(add_label); |
| 4139 | __ add(out.X(), out.X(), Operand(/* offset placeholder */ 0)); |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 4140 | } |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4141 | break; |
| 4142 | } |
| 4143 | case HLoadClass::LoadKind::kBootImageAddress: { |
| 4144 | DCHECK(!kEmitCompilerReadBarrier); |
| 4145 | DCHECK(cls->GetAddress() != 0u && IsUint<32>(cls->GetAddress())); |
| 4146 | __ Ldr(out.W(), codegen_->DeduplicateBootImageAddressLiteral(cls->GetAddress())); |
| 4147 | break; |
| 4148 | } |
| 4149 | case HLoadClass::LoadKind::kDexCacheAddress: { |
| 4150 | DCHECK_NE(cls->GetAddress(), 0u); |
| 4151 | // LDR immediate has a 12-bit offset multiplied by the size and for 32-bit loads |
| 4152 | // that gives a 16KiB range. To try and reduce the number of literals if we load |
| 4153 | // multiple types, simply split the dex cache address to a 16KiB aligned base |
| 4154 | // loaded from a literal and the remaining offset embedded in the load. |
| 4155 | static_assert(sizeof(GcRoot<mirror::Class>) == 4u, "Expected GC root to be 4 bytes."); |
| 4156 | DCHECK_ALIGNED(cls->GetAddress(), 4u); |
| 4157 | constexpr size_t offset_bits = /* encoded bits */ 12 + /* scale */ 2; |
| 4158 | uint64_t base_address = cls->GetAddress() & ~MaxInt<uint64_t>(offset_bits); |
| 4159 | uint32_t offset = cls->GetAddress() & MaxInt<uint64_t>(offset_bits); |
| 4160 | __ Ldr(out.X(), codegen_->DeduplicateDexCacheAddressLiteral(base_address)); |
| 4161 | // /* GcRoot<mirror::Class> */ out = *(base_address + offset) |
| 4162 | GenerateGcRootFieldLoad(cls, out_loc, out.X(), offset); |
| 4163 | generate_null_check = !cls->IsInDexCache(); |
| 4164 | break; |
| 4165 | } |
| 4166 | case HLoadClass::LoadKind::kDexCachePcRelative: { |
| 4167 | // Add ADRP with its PC-relative DexCache access patch. |
| 4168 | const DexFile& dex_file = cls->GetDexFile(); |
| 4169 | uint32_t element_offset = cls->GetDexCacheElementOffset(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4170 | vixl::aarch64::Label* adrp_label = |
| 4171 | codegen_->NewPcRelativeDexCacheArrayPatch(dex_file, element_offset); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4172 | { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4173 | SingleEmissionCheckScope guard(GetVIXLAssembler()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4174 | __ Bind(adrp_label); |
| 4175 | __ adrp(out.X(), /* offset placeholder */ 0); |
| 4176 | } |
| 4177 | // Add LDR with its PC-relative DexCache access patch. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4178 | vixl::aarch64::Label* ldr_label = |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4179 | codegen_->NewPcRelativeDexCacheArrayPatch(dex_file, element_offset, adrp_label); |
| 4180 | // /* GcRoot<mirror::Class> */ out = *(base_address + offset) /* PC-relative */ |
| 4181 | GenerateGcRootFieldLoad(cls, out_loc, out.X(), /* offset placeholder */ 0, ldr_label); |
| 4182 | generate_null_check = !cls->IsInDexCache(); |
| 4183 | break; |
| 4184 | } |
| 4185 | case HLoadClass::LoadKind::kDexCacheViaMethod: { |
| 4186 | MemberOffset resolved_types_offset = |
| 4187 | ArtMethod::DexCacheResolvedTypesOffset(kArm64PointerSize); |
| 4188 | // /* GcRoot<mirror::Class>[] */ out = |
| 4189 | // current_method.ptr_sized_fields_->dex_cache_resolved_types_ |
| 4190 | Register current_method = InputRegisterAt(cls, 0); |
| 4191 | __ Ldr(out.X(), MemOperand(current_method, resolved_types_offset.Int32Value())); |
| 4192 | // /* GcRoot<mirror::Class> */ out = out[type_index] |
| 4193 | GenerateGcRootFieldLoad( |
| 4194 | cls, out_loc, out.X(), CodeGenerator::GetCacheOffset(cls->GetTypeIndex())); |
| 4195 | generate_null_check = !cls->IsInDexCache(); |
| 4196 | break; |
| 4197 | } |
| 4198 | } |
| 4199 | |
| 4200 | if (generate_null_check || cls->MustGenerateClinitCheck()) { |
| 4201 | DCHECK(cls->CanCallRuntime()); |
| 4202 | SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM64( |
| 4203 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 4204 | codegen_->AddSlowPath(slow_path); |
| 4205 | if (generate_null_check) { |
| 4206 | __ Cbz(out, slow_path->GetEntryLabel()); |
| 4207 | } |
| 4208 | if (cls->MustGenerateClinitCheck()) { |
| 4209 | GenerateClassInitializationCheck(slow_path, out); |
| 4210 | } else { |
| 4211 | __ Bind(slow_path->GetExitLabel()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4212 | } |
| 4213 | } |
| 4214 | } |
| 4215 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 4216 | static MemOperand GetExceptionTlsAddress() { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4217 | return MemOperand(tr, Thread::ExceptionOffset<kArm64PointerSize>().Int32Value()); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 4218 | } |
| 4219 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4220 | void LocationsBuilderARM64::VisitLoadException(HLoadException* load) { |
| 4221 | LocationSummary* locations = |
| 4222 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 4223 | locations->SetOut(Location::RequiresRegister()); |
| 4224 | } |
| 4225 | |
| 4226 | void InstructionCodeGeneratorARM64::VisitLoadException(HLoadException* instruction) { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 4227 | __ Ldr(OutputRegister(instruction), GetExceptionTlsAddress()); |
| 4228 | } |
| 4229 | |
| 4230 | void LocationsBuilderARM64::VisitClearException(HClearException* clear) { |
| 4231 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 4232 | } |
| 4233 | |
| 4234 | void InstructionCodeGeneratorARM64::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 4235 | __ Str(wzr, GetExceptionTlsAddress()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4236 | } |
| 4237 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4238 | HLoadString::LoadKind CodeGeneratorARM64::GetSupportedLoadStringKind( |
| 4239 | HLoadString::LoadKind desired_string_load_kind) { |
| 4240 | if (kEmitCompilerReadBarrier) { |
| 4241 | switch (desired_string_load_kind) { |
| 4242 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: |
| 4243 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
| 4244 | case HLoadString::LoadKind::kBootImageAddress: |
| 4245 | // TODO: Implement for read barrier. |
| 4246 | return HLoadString::LoadKind::kDexCacheViaMethod; |
| 4247 | default: |
| 4248 | break; |
| 4249 | } |
| 4250 | } |
| 4251 | switch (desired_string_load_kind) { |
| 4252 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: |
| 4253 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 4254 | break; |
| 4255 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
| 4256 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 4257 | break; |
| 4258 | case HLoadString::LoadKind::kBootImageAddress: |
| 4259 | break; |
| 4260 | case HLoadString::LoadKind::kDexCacheAddress: |
Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 4261 | DCHECK(Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4262 | break; |
| 4263 | case HLoadString::LoadKind::kDexCachePcRelative: |
Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 4264 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4265 | break; |
| 4266 | case HLoadString::LoadKind::kDexCacheViaMethod: |
| 4267 | break; |
| 4268 | } |
| 4269 | return desired_string_load_kind; |
| 4270 | } |
| 4271 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4272 | void LocationsBuilderARM64::VisitLoadString(HLoadString* load) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4273 | LocationSummary::CallKind call_kind = (load->NeedsEnvironment() || kEmitCompilerReadBarrier) |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 4274 | ? LocationSummary::kCallOnSlowPath |
| 4275 | : LocationSummary::kNoCall; |
| 4276 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4277 | if (load->GetLoadKind() == HLoadString::LoadKind::kDexCacheViaMethod) { |
| 4278 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4279 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4280 | locations->SetOut(Location::RequiresRegister()); |
| 4281 | } |
| 4282 | |
| 4283 | void InstructionCodeGeneratorARM64::VisitLoadString(HLoadString* load) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4284 | Register out = OutputRegister(load); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4285 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4286 | switch (load->GetLoadKind()) { |
| 4287 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: |
| 4288 | DCHECK(!kEmitCompilerReadBarrier); |
| 4289 | __ Ldr(out, codegen_->DeduplicateBootImageStringLiteral(load->GetDexFile(), |
| 4290 | load->GetStringIndex())); |
| 4291 | return; // No dex cache slow path. |
| 4292 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
| 4293 | DCHECK(!kEmitCompilerReadBarrier); |
| 4294 | // Add ADRP with its PC-relative String patch. |
| 4295 | const DexFile& dex_file = load->GetDexFile(); |
| 4296 | uint32_t string_index = load->GetStringIndex(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4297 | vixl::aarch64::Label* adrp_label = codegen_->NewPcRelativeStringPatch(dex_file, string_index); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4298 | { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4299 | SingleEmissionCheckScope guard(GetVIXLAssembler()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4300 | __ Bind(adrp_label); |
| 4301 | __ adrp(out.X(), /* offset placeholder */ 0); |
| 4302 | } |
| 4303 | // Add ADD with its PC-relative String patch. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4304 | vixl::aarch64::Label* add_label = |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4305 | codegen_->NewPcRelativeStringPatch(dex_file, string_index, adrp_label); |
| 4306 | { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4307 | SingleEmissionCheckScope guard(GetVIXLAssembler()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4308 | __ Bind(add_label); |
| 4309 | __ add(out.X(), out.X(), Operand(/* offset placeholder */ 0)); |
| 4310 | } |
| 4311 | return; // No dex cache slow path. |
| 4312 | } |
| 4313 | case HLoadString::LoadKind::kBootImageAddress: { |
| 4314 | DCHECK(!kEmitCompilerReadBarrier); |
| 4315 | DCHECK(load->GetAddress() != 0u && IsUint<32>(load->GetAddress())); |
| 4316 | __ Ldr(out.W(), codegen_->DeduplicateBootImageAddressLiteral(load->GetAddress())); |
| 4317 | return; // No dex cache slow path. |
| 4318 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4319 | default: |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 4320 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4321 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4322 | |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 4323 | // TODO: Re-add the compiler code to do string dex cache lookup again. |
| 4324 | SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathARM64(load); |
| 4325 | codegen_->AddSlowPath(slow_path); |
| 4326 | __ B(slow_path->GetEntryLabel()); |
| 4327 | __ Bind(slow_path->GetExitLabel()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4328 | } |
| 4329 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4330 | void LocationsBuilderARM64::VisitLongConstant(HLongConstant* constant) { |
| 4331 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant); |
| 4332 | locations->SetOut(Location::ConstantLocation(constant)); |
| 4333 | } |
| 4334 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4335 | void InstructionCodeGeneratorARM64::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4336 | // Will be generated at use site. |
| 4337 | } |
| 4338 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4339 | void LocationsBuilderARM64::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 4340 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4341 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4342 | InvokeRuntimeCallingConvention calling_convention; |
| 4343 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 4344 | } |
| 4345 | |
| 4346 | void InstructionCodeGeneratorARM64::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 4347 | codegen_->InvokeRuntime(instruction->IsEnter() |
| 4348 | ? QUICK_ENTRY_POINT(pLockObject) : QUICK_ENTRY_POINT(pUnlockObject), |
| 4349 | instruction, |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 4350 | instruction->GetDexPc(), |
| 4351 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 4352 | if (instruction->IsEnter()) { |
| 4353 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 4354 | } else { |
| 4355 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 4356 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4357 | } |
| 4358 | |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 4359 | void LocationsBuilderARM64::VisitMul(HMul* mul) { |
| 4360 | LocationSummary* locations = |
| 4361 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 4362 | switch (mul->GetResultType()) { |
| 4363 | case Primitive::kPrimInt: |
| 4364 | case Primitive::kPrimLong: |
| 4365 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4366 | locations->SetInAt(1, Location::RequiresRegister()); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 4367 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 4368 | break; |
| 4369 | |
| 4370 | case Primitive::kPrimFloat: |
| 4371 | case Primitive::kPrimDouble: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 4372 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4373 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4374 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 4375 | break; |
| 4376 | |
| 4377 | default: |
| 4378 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 4379 | } |
| 4380 | } |
| 4381 | |
| 4382 | void InstructionCodeGeneratorARM64::VisitMul(HMul* mul) { |
| 4383 | switch (mul->GetResultType()) { |
| 4384 | case Primitive::kPrimInt: |
| 4385 | case Primitive::kPrimLong: |
| 4386 | __ Mul(OutputRegister(mul), InputRegisterAt(mul, 0), InputRegisterAt(mul, 1)); |
| 4387 | break; |
| 4388 | |
| 4389 | case Primitive::kPrimFloat: |
| 4390 | case Primitive::kPrimDouble: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 4391 | __ Fmul(OutputFPRegister(mul), InputFPRegisterAt(mul, 0), InputFPRegisterAt(mul, 1)); |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 4392 | break; |
| 4393 | |
| 4394 | default: |
| 4395 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 4396 | } |
| 4397 | } |
| 4398 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 4399 | void LocationsBuilderARM64::VisitNeg(HNeg* neg) { |
| 4400 | LocationSummary* locations = |
| 4401 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 4402 | switch (neg->GetResultType()) { |
| 4403 | case Primitive::kPrimInt: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4404 | case Primitive::kPrimLong: |
Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 4405 | locations->SetInAt(0, ARM64EncodableConstantOrRegister(neg->InputAt(0), neg)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4406 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 4407 | break; |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 4408 | |
| 4409 | case Primitive::kPrimFloat: |
| 4410 | case Primitive::kPrimDouble: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4411 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4412 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 4413 | break; |
| 4414 | |
| 4415 | default: |
| 4416 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 4417 | } |
| 4418 | } |
| 4419 | |
| 4420 | void InstructionCodeGeneratorARM64::VisitNeg(HNeg* neg) { |
| 4421 | switch (neg->GetResultType()) { |
| 4422 | case Primitive::kPrimInt: |
| 4423 | case Primitive::kPrimLong: |
| 4424 | __ Neg(OutputRegister(neg), InputOperandAt(neg, 0)); |
| 4425 | break; |
| 4426 | |
| 4427 | case Primitive::kPrimFloat: |
| 4428 | case Primitive::kPrimDouble: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4429 | __ Fneg(OutputFPRegister(neg), InputFPRegisterAt(neg, 0)); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 4430 | break; |
| 4431 | |
| 4432 | default: |
| 4433 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 4434 | } |
| 4435 | } |
| 4436 | |
| 4437 | void LocationsBuilderARM64::VisitNewArray(HNewArray* instruction) { |
| 4438 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4439 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 4440 | InvokeRuntimeCallingConvention calling_convention; |
| 4441 | locations->AddTemp(LocationFrom(calling_convention.GetRegisterAt(0))); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 4442 | locations->SetOut(LocationFrom(x0)); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 4443 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 4444 | locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(2))); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 4445 | } |
| 4446 | |
| 4447 | void InstructionCodeGeneratorARM64::VisitNewArray(HNewArray* instruction) { |
| 4448 | LocationSummary* locations = instruction->GetLocations(); |
| 4449 | InvokeRuntimeCallingConvention calling_convention; |
| 4450 | Register type_index = RegisterFrom(locations->GetTemp(0), Primitive::kPrimInt); |
| 4451 | DCHECK(type_index.Is(w0)); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 4452 | __ Mov(type_index, instruction->GetTypeIndex()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4453 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 4454 | // of poisoning the reference. |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4455 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), |
| 4456 | instruction, |
| 4457 | instruction->GetDexPc(), |
| 4458 | nullptr); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4459 | CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck, void*, uint32_t, int32_t, ArtMethod*>(); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 4460 | } |
| 4461 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4462 | void LocationsBuilderARM64::VisitNewInstance(HNewInstance* instruction) { |
| 4463 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4464 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4465 | InvokeRuntimeCallingConvention calling_convention; |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4466 | if (instruction->IsStringAlloc()) { |
| 4467 | locations->AddTemp(LocationFrom(kArtMethodRegister)); |
| 4468 | } else { |
| 4469 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 4470 | locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(1))); |
| 4471 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4472 | locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimNot)); |
| 4473 | } |
| 4474 | |
| 4475 | void InstructionCodeGeneratorARM64::VisitNewInstance(HNewInstance* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4476 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 4477 | // of poisoning the reference. |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4478 | if (instruction->IsStringAlloc()) { |
| 4479 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 4480 | Location temp = instruction->GetLocations()->GetTemp(0); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4481 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64PointerSize); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4482 | __ Ldr(XRegisterFrom(temp), MemOperand(tr, QUICK_ENTRY_POINT(pNewEmptyString))); |
| 4483 | __ Ldr(lr, MemOperand(XRegisterFrom(temp), code_offset.Int32Value())); |
| 4484 | __ Blr(lr); |
| 4485 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 4486 | } else { |
| 4487 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), |
| 4488 | instruction, |
| 4489 | instruction->GetDexPc(), |
| 4490 | nullptr); |
| 4491 | CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, ArtMethod*>(); |
| 4492 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4493 | } |
| 4494 | |
| 4495 | void LocationsBuilderARM64::VisitNot(HNot* instruction) { |
| 4496 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Alexandre Rames | 4e59651 | 2014-11-07 15:56:50 +0000 | [diff] [blame] | 4497 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 4498 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4499 | } |
| 4500 | |
| 4501 | void InstructionCodeGeneratorARM64::VisitNot(HNot* instruction) { |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 4502 | switch (instruction->GetResultType()) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4503 | case Primitive::kPrimInt: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4504 | case Primitive::kPrimLong: |
Roland Levillain | 55dcfb5 | 2014-10-24 18:09:09 +0100 | [diff] [blame] | 4505 | __ Mvn(OutputRegister(instruction), InputOperandAt(instruction, 0)); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4506 | break; |
| 4507 | |
| 4508 | default: |
| 4509 | LOG(FATAL) << "Unexpected type for not operation " << instruction->GetResultType(); |
| 4510 | } |
| 4511 | } |
| 4512 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4513 | void LocationsBuilderARM64::VisitBooleanNot(HBooleanNot* instruction) { |
| 4514 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 4515 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4516 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4517 | } |
| 4518 | |
| 4519 | void InstructionCodeGeneratorARM64::VisitBooleanNot(HBooleanNot* instruction) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4520 | __ Eor(OutputRegister(instruction), InputRegisterAt(instruction, 0), vixl::aarch64::Operand(1)); |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4521 | } |
| 4522 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4523 | void LocationsBuilderARM64::VisitNullCheck(HNullCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4524 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 4525 | ? LocationSummary::kCallOnSlowPath |
| 4526 | : LocationSummary::kNoCall; |
| 4527 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4528 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4529 | if (instruction->HasUses()) { |
| 4530 | locations->SetOut(Location::SameAsFirstInput()); |
| 4531 | } |
| 4532 | } |
| 4533 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4534 | void CodeGeneratorARM64::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 4535 | if (CanMoveNullCheckToUser(instruction)) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4536 | return; |
| 4537 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4538 | |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 4539 | BlockPoolsScope block_pools(GetVIXLAssembler()); |
| 4540 | Location obj = instruction->GetLocations()->InAt(0); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4541 | __ Ldr(wzr, HeapOperandFrom(obj, Offset(0))); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4542 | RecordPcInfo(instruction, instruction->GetDexPc()); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4543 | } |
| 4544 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4545 | void CodeGeneratorARM64::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4546 | SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM64(instruction); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4547 | AddSlowPath(slow_path); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4548 | |
| 4549 | LocationSummary* locations = instruction->GetLocations(); |
| 4550 | Location obj = locations->InAt(0); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4551 | |
| 4552 | __ Cbz(RegisterFrom(obj, instruction->InputAt(0)->GetType()), slow_path->GetEntryLabel()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4553 | } |
| 4554 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4555 | void InstructionCodeGeneratorARM64::VisitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4556 | codegen_->GenerateNullCheck(instruction); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4557 | } |
| 4558 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4559 | void LocationsBuilderARM64::VisitOr(HOr* instruction) { |
| 4560 | HandleBinaryOp(instruction); |
| 4561 | } |
| 4562 | |
| 4563 | void InstructionCodeGeneratorARM64::VisitOr(HOr* instruction) { |
| 4564 | HandleBinaryOp(instruction); |
| 4565 | } |
| 4566 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 4567 | void LocationsBuilderARM64::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
| 4568 | LOG(FATAL) << "Unreachable"; |
| 4569 | } |
| 4570 | |
| 4571 | void InstructionCodeGeneratorARM64::VisitParallelMove(HParallelMove* instruction) { |
| 4572 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 4573 | } |
| 4574 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4575 | void LocationsBuilderARM64::VisitParameterValue(HParameterValue* instruction) { |
| 4576 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 4577 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 4578 | if (location.IsStackSlot()) { |
| 4579 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 4580 | } else if (location.IsDoubleStackSlot()) { |
| 4581 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 4582 | } |
| 4583 | locations->SetOut(location); |
| 4584 | } |
| 4585 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4586 | void InstructionCodeGeneratorARM64::VisitParameterValue( |
| 4587 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4588 | // Nothing to do, the parameter is already at its location. |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4589 | } |
| 4590 | |
| 4591 | void LocationsBuilderARM64::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 4592 | LocationSummary* locations = |
| 4593 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 4594 | locations->SetOut(LocationFrom(kArtMethodRegister)); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4595 | } |
| 4596 | |
| 4597 | void InstructionCodeGeneratorARM64::VisitCurrentMethod( |
| 4598 | HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
| 4599 | // Nothing to do, the method is already at its location. |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4600 | } |
| 4601 | |
| 4602 | void LocationsBuilderARM64::VisitPhi(HPhi* instruction) { |
| 4603 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4604 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4605 | locations->SetInAt(i, Location::Any()); |
| 4606 | } |
| 4607 | locations->SetOut(Location::Any()); |
| 4608 | } |
| 4609 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4610 | void InstructionCodeGeneratorARM64::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4611 | LOG(FATAL) << "Unreachable"; |
| 4612 | } |
| 4613 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4614 | void LocationsBuilderARM64::VisitRem(HRem* rem) { |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 4615 | Primitive::Type type = rem->GetResultType(); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 4616 | LocationSummary::CallKind call_kind = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4617 | Primitive::IsFloatingPointType(type) ? LocationSummary::kCallOnMainOnly |
| 4618 | : LocationSummary::kNoCall; |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 4619 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind); |
| 4620 | |
| 4621 | switch (type) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4622 | case Primitive::kPrimInt: |
| 4623 | case Primitive::kPrimLong: |
| 4624 | locations->SetInAt(0, Location::RequiresRegister()); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 4625 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4626 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4627 | break; |
| 4628 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 4629 | case Primitive::kPrimFloat: |
| 4630 | case Primitive::kPrimDouble: { |
| 4631 | InvokeRuntimeCallingConvention calling_convention; |
| 4632 | locations->SetInAt(0, LocationFrom(calling_convention.GetFpuRegisterAt(0))); |
| 4633 | locations->SetInAt(1, LocationFrom(calling_convention.GetFpuRegisterAt(1))); |
| 4634 | locations->SetOut(calling_convention.GetReturnLocation(type)); |
| 4635 | |
| 4636 | break; |
| 4637 | } |
| 4638 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4639 | default: |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 4640 | LOG(FATAL) << "Unexpected rem type " << type; |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4641 | } |
| 4642 | } |
| 4643 | |
| 4644 | void InstructionCodeGeneratorARM64::VisitRem(HRem* rem) { |
| 4645 | Primitive::Type type = rem->GetResultType(); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 4646 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4647 | switch (type) { |
| 4648 | case Primitive::kPrimInt: |
| 4649 | case Primitive::kPrimLong: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 4650 | GenerateDivRemIntegral(rem); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4651 | break; |
| 4652 | } |
| 4653 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 4654 | case Primitive::kPrimFloat: |
| 4655 | case Primitive::kPrimDouble: { |
| 4656 | int32_t entry_offset = (type == Primitive::kPrimFloat) ? QUICK_ENTRY_POINT(pFmodf) |
| 4657 | : QUICK_ENTRY_POINT(pFmod); |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 4658 | codegen_->InvokeRuntime(entry_offset, rem, rem->GetDexPc(), nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 4659 | if (type == Primitive::kPrimFloat) { |
| 4660 | CheckEntrypointTypes<kQuickFmodf, float, float, float>(); |
| 4661 | } else { |
| 4662 | CheckEntrypointTypes<kQuickFmod, double, double, double>(); |
| 4663 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 4664 | break; |
| 4665 | } |
| 4666 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4667 | default: |
| 4668 | LOG(FATAL) << "Unexpected rem type " << type; |
Vladimir Marko | 351dddf | 2015-12-11 16:34:46 +0000 | [diff] [blame] | 4669 | UNREACHABLE(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4670 | } |
| 4671 | } |
| 4672 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 4673 | void LocationsBuilderARM64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 4674 | memory_barrier->SetLocations(nullptr); |
| 4675 | } |
| 4676 | |
| 4677 | void InstructionCodeGeneratorARM64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 4678 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 4679 | } |
| 4680 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4681 | void LocationsBuilderARM64::VisitReturn(HReturn* instruction) { |
| 4682 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 4683 | Primitive::Type return_type = instruction->InputAt(0)->GetType(); |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 4684 | locations->SetInAt(0, ARM64ReturnLocation(return_type)); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4685 | } |
| 4686 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4687 | void InstructionCodeGeneratorARM64::VisitReturn(HReturn* instruction ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4688 | codegen_->GenerateFrameExit(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4689 | } |
| 4690 | |
| 4691 | void LocationsBuilderARM64::VisitReturnVoid(HReturnVoid* instruction) { |
| 4692 | instruction->SetLocations(nullptr); |
| 4693 | } |
| 4694 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4695 | void InstructionCodeGeneratorARM64::VisitReturnVoid(HReturnVoid* instruction ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4696 | codegen_->GenerateFrameExit(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4697 | } |
| 4698 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4699 | void LocationsBuilderARM64::VisitRor(HRor* ror) { |
| 4700 | HandleBinaryOp(ror); |
| 4701 | } |
| 4702 | |
| 4703 | void InstructionCodeGeneratorARM64::VisitRor(HRor* ror) { |
| 4704 | HandleBinaryOp(ror); |
| 4705 | } |
| 4706 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4707 | void LocationsBuilderARM64::VisitShl(HShl* shl) { |
| 4708 | HandleShift(shl); |
| 4709 | } |
| 4710 | |
| 4711 | void InstructionCodeGeneratorARM64::VisitShl(HShl* shl) { |
| 4712 | HandleShift(shl); |
| 4713 | } |
| 4714 | |
| 4715 | void LocationsBuilderARM64::VisitShr(HShr* shr) { |
| 4716 | HandleShift(shr); |
| 4717 | } |
| 4718 | |
| 4719 | void InstructionCodeGeneratorARM64::VisitShr(HShr* shr) { |
| 4720 | HandleShift(shr); |
| 4721 | } |
| 4722 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4723 | void LocationsBuilderARM64::VisitSub(HSub* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4724 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4725 | } |
| 4726 | |
| 4727 | void InstructionCodeGeneratorARM64::VisitSub(HSub* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4728 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4729 | } |
| 4730 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4731 | void LocationsBuilderARM64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 4732 | HandleFieldGet(instruction); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4733 | } |
| 4734 | |
| 4735 | void InstructionCodeGeneratorARM64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 4736 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4737 | } |
| 4738 | |
| 4739 | void LocationsBuilderARM64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 4740 | HandleFieldSet(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4741 | } |
| 4742 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4743 | void InstructionCodeGeneratorARM64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4744 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4745 | } |
| 4746 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 4747 | void LocationsBuilderARM64::VisitUnresolvedInstanceFieldGet( |
| 4748 | HUnresolvedInstanceFieldGet* instruction) { |
| 4749 | FieldAccessCallingConventionARM64 calling_convention; |
| 4750 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4751 | instruction, instruction->GetFieldType(), calling_convention); |
| 4752 | } |
| 4753 | |
| 4754 | void InstructionCodeGeneratorARM64::VisitUnresolvedInstanceFieldGet( |
| 4755 | HUnresolvedInstanceFieldGet* instruction) { |
| 4756 | FieldAccessCallingConventionARM64 calling_convention; |
| 4757 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4758 | instruction->GetFieldType(), |
| 4759 | instruction->GetFieldIndex(), |
| 4760 | instruction->GetDexPc(), |
| 4761 | calling_convention); |
| 4762 | } |
| 4763 | |
| 4764 | void LocationsBuilderARM64::VisitUnresolvedInstanceFieldSet( |
| 4765 | HUnresolvedInstanceFieldSet* instruction) { |
| 4766 | FieldAccessCallingConventionARM64 calling_convention; |
| 4767 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4768 | instruction, instruction->GetFieldType(), calling_convention); |
| 4769 | } |
| 4770 | |
| 4771 | void InstructionCodeGeneratorARM64::VisitUnresolvedInstanceFieldSet( |
| 4772 | HUnresolvedInstanceFieldSet* instruction) { |
| 4773 | FieldAccessCallingConventionARM64 calling_convention; |
| 4774 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4775 | instruction->GetFieldType(), |
| 4776 | instruction->GetFieldIndex(), |
| 4777 | instruction->GetDexPc(), |
| 4778 | calling_convention); |
| 4779 | } |
| 4780 | |
| 4781 | void LocationsBuilderARM64::VisitUnresolvedStaticFieldGet( |
| 4782 | HUnresolvedStaticFieldGet* instruction) { |
| 4783 | FieldAccessCallingConventionARM64 calling_convention; |
| 4784 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4785 | instruction, instruction->GetFieldType(), calling_convention); |
| 4786 | } |
| 4787 | |
| 4788 | void InstructionCodeGeneratorARM64::VisitUnresolvedStaticFieldGet( |
| 4789 | HUnresolvedStaticFieldGet* instruction) { |
| 4790 | FieldAccessCallingConventionARM64 calling_convention; |
| 4791 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4792 | instruction->GetFieldType(), |
| 4793 | instruction->GetFieldIndex(), |
| 4794 | instruction->GetDexPc(), |
| 4795 | calling_convention); |
| 4796 | } |
| 4797 | |
| 4798 | void LocationsBuilderARM64::VisitUnresolvedStaticFieldSet( |
| 4799 | HUnresolvedStaticFieldSet* instruction) { |
| 4800 | FieldAccessCallingConventionARM64 calling_convention; |
| 4801 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4802 | instruction, instruction->GetFieldType(), calling_convention); |
| 4803 | } |
| 4804 | |
| 4805 | void InstructionCodeGeneratorARM64::VisitUnresolvedStaticFieldSet( |
| 4806 | HUnresolvedStaticFieldSet* instruction) { |
| 4807 | FieldAccessCallingConventionARM64 calling_convention; |
| 4808 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4809 | instruction->GetFieldType(), |
| 4810 | instruction->GetFieldIndex(), |
| 4811 | instruction->GetDexPc(), |
| 4812 | calling_convention); |
| 4813 | } |
| 4814 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4815 | void LocationsBuilderARM64::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 4816 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
| 4817 | } |
| 4818 | |
| 4819 | void InstructionCodeGeneratorARM64::VisitSuspendCheck(HSuspendCheck* instruction) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4820 | HBasicBlock* block = instruction->GetBlock(); |
| 4821 | if (block->GetLoopInformation() != nullptr) { |
| 4822 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 4823 | // The back edge will generate the suspend check. |
| 4824 | return; |
| 4825 | } |
| 4826 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 4827 | // The goto will generate the suspend check. |
| 4828 | return; |
| 4829 | } |
| 4830 | GenerateSuspendCheck(instruction, nullptr); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4831 | } |
| 4832 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4833 | void LocationsBuilderARM64::VisitThrow(HThrow* instruction) { |
| 4834 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4835 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4836 | InvokeRuntimeCallingConvention calling_convention; |
| 4837 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 4838 | } |
| 4839 | |
| 4840 | void InstructionCodeGeneratorARM64::VisitThrow(HThrow* instruction) { |
| 4841 | codegen_->InvokeRuntime( |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 4842 | QUICK_ENTRY_POINT(pDeliverException), instruction, instruction->GetDexPc(), nullptr); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 4843 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4844 | } |
| 4845 | |
| 4846 | void LocationsBuilderARM64::VisitTypeConversion(HTypeConversion* conversion) { |
| 4847 | LocationSummary* locations = |
| 4848 | new (GetGraph()->GetArena()) LocationSummary(conversion, LocationSummary::kNoCall); |
| 4849 | Primitive::Type input_type = conversion->GetInputType(); |
| 4850 | Primitive::Type result_type = conversion->GetResultType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 4851 | DCHECK_NE(input_type, result_type); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4852 | if ((input_type == Primitive::kPrimNot) || (input_type == Primitive::kPrimVoid) || |
| 4853 | (result_type == Primitive::kPrimNot) || (result_type == Primitive::kPrimVoid)) { |
| 4854 | LOG(FATAL) << "Unexpected type conversion from " << input_type << " to " << result_type; |
| 4855 | } |
| 4856 | |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 4857 | if (Primitive::IsFloatingPointType(input_type)) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4858 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4859 | } else { |
| 4860 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4861 | } |
| 4862 | |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 4863 | if (Primitive::IsFloatingPointType(result_type)) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4864 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4865 | } else { |
| 4866 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4867 | } |
| 4868 | } |
| 4869 | |
| 4870 | void InstructionCodeGeneratorARM64::VisitTypeConversion(HTypeConversion* conversion) { |
| 4871 | Primitive::Type result_type = conversion->GetResultType(); |
| 4872 | Primitive::Type input_type = conversion->GetInputType(); |
| 4873 | |
| 4874 | DCHECK_NE(input_type, result_type); |
| 4875 | |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 4876 | if (Primitive::IsIntegralType(result_type) && Primitive::IsIntegralType(input_type)) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4877 | int result_size = Primitive::ComponentSize(result_type); |
| 4878 | int input_size = Primitive::ComponentSize(input_type); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 4879 | int min_size = std::min(result_size, input_size); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4880 | Register output = OutputRegister(conversion); |
| 4881 | Register source = InputRegisterAt(conversion, 0); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 4882 | if (result_type == Primitive::kPrimInt && input_type == Primitive::kPrimLong) { |
Alexandre Rames | 4dff2fd | 2015-08-20 13:36:35 +0100 | [diff] [blame] | 4883 | // 'int' values are used directly as W registers, discarding the top |
| 4884 | // bits, so we don't need to sign-extend and can just perform a move. |
| 4885 | // We do not pass the `kDiscardForSameWReg` argument to force clearing the |
| 4886 | // top 32 bits of the target register. We theoretically could leave those |
| 4887 | // bits unchanged, but we would have to make sure that no code uses a |
| 4888 | // 32bit input value as a 64bit value assuming that the top 32 bits are |
| 4889 | // zero. |
| 4890 | __ Mov(output.W(), source.W()); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 4891 | } else if (result_type == Primitive::kPrimChar || |
| 4892 | (input_type == Primitive::kPrimChar && input_size < result_size)) { |
| 4893 | __ Ubfx(output, |
| 4894 | output.IsX() ? source.X() : source.W(), |
| 4895 | 0, Primitive::ComponentSize(Primitive::kPrimChar) * kBitsPerByte); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4896 | } else { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 4897 | __ Sbfx(output, output.IsX() ? source.X() : source.W(), 0, min_size * kBitsPerByte); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4898 | } |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 4899 | } else if (Primitive::IsFloatingPointType(result_type) && Primitive::IsIntegralType(input_type)) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4900 | __ Scvtf(OutputFPRegister(conversion), InputRegisterAt(conversion, 0)); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 4901 | } else if (Primitive::IsIntegralType(result_type) && Primitive::IsFloatingPointType(input_type)) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4902 | CHECK(result_type == Primitive::kPrimInt || result_type == Primitive::kPrimLong); |
| 4903 | __ Fcvtzs(OutputRegister(conversion), InputFPRegisterAt(conversion, 0)); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 4904 | } else if (Primitive::IsFloatingPointType(result_type) && |
| 4905 | Primitive::IsFloatingPointType(input_type)) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4906 | __ Fcvt(OutputFPRegister(conversion), InputFPRegisterAt(conversion, 0)); |
| 4907 | } else { |
| 4908 | LOG(FATAL) << "Unexpected or unimplemented type conversion from " << input_type |
| 4909 | << " to " << result_type; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4910 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4911 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4912 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4913 | void LocationsBuilderARM64::VisitUShr(HUShr* ushr) { |
| 4914 | HandleShift(ushr); |
| 4915 | } |
| 4916 | |
| 4917 | void InstructionCodeGeneratorARM64::VisitUShr(HUShr* ushr) { |
| 4918 | HandleShift(ushr); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4919 | } |
| 4920 | |
| 4921 | void LocationsBuilderARM64::VisitXor(HXor* instruction) { |
| 4922 | HandleBinaryOp(instruction); |
| 4923 | } |
| 4924 | |
| 4925 | void InstructionCodeGeneratorARM64::VisitXor(HXor* instruction) { |
| 4926 | HandleBinaryOp(instruction); |
| 4927 | } |
| 4928 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4929 | void LocationsBuilderARM64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 4930 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 4931 | LOG(FATAL) << "Unreachable"; |
| 4932 | } |
| 4933 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4934 | void InstructionCodeGeneratorARM64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 4935 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 4936 | LOG(FATAL) << "Unreachable"; |
| 4937 | } |
| 4938 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 4939 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 4940 | void LocationsBuilderARM64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 4941 | LocationSummary* locations = |
| 4942 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 4943 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4944 | } |
| 4945 | |
| 4946 | void InstructionCodeGeneratorARM64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 4947 | int32_t lower_bound = switch_instr->GetStartValue(); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 4948 | uint32_t num_entries = switch_instr->GetNumEntries(); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 4949 | Register value_reg = InputRegisterAt(switch_instr, 0); |
| 4950 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 4951 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 4952 | // Roughly set 16 as max average assemblies generated per HIR in a graph. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4953 | static constexpr int32_t kMaxExpectedSizePerHInstruction = 16 * kInstructionSize; |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 4954 | // ADR has a limited range(+/-1MB), so we set a threshold for the number of HIRs in the graph to |
| 4955 | // make sure we don't emit it if the target may run out of range. |
| 4956 | // TODO: Instead of emitting all jump tables at the end of the code, we could keep track of ADR |
| 4957 | // ranges and emit the tables only as required. |
| 4958 | static constexpr int32_t kJumpTableInstructionThreshold = 1* MB / kMaxExpectedSizePerHInstruction; |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 4959 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 4960 | if (num_entries <= kPackedSwitchCompareJumpThreshold || |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 4961 | // Current instruction id is an upper bound of the number of HIRs in the graph. |
| 4962 | GetGraph()->GetCurrentInstructionId() > kJumpTableInstructionThreshold) { |
| 4963 | // Create a series of compare/jumps. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 4964 | UseScratchRegisterScope temps(codegen_->GetVIXLAssembler()); |
| 4965 | Register temp = temps.AcquireW(); |
| 4966 | __ Subs(temp, value_reg, Operand(lower_bound)); |
| 4967 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 4968 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 4969 | // Jump to successors[0] if value == lower_bound. |
| 4970 | __ B(eq, codegen_->GetLabelOf(successors[0])); |
| 4971 | int32_t last_index = 0; |
| 4972 | for (; num_entries - last_index > 2; last_index += 2) { |
| 4973 | __ Subs(temp, temp, Operand(2)); |
| 4974 | // Jump to successors[last_index + 1] if value < case_value[last_index + 2]. |
| 4975 | __ B(lo, codegen_->GetLabelOf(successors[last_index + 1])); |
| 4976 | // Jump to successors[last_index + 2] if value == case_value[last_index + 2]. |
| 4977 | __ B(eq, codegen_->GetLabelOf(successors[last_index + 2])); |
| 4978 | } |
| 4979 | if (num_entries - last_index == 2) { |
| 4980 | // The last missing case_value. |
| 4981 | __ Cmp(temp, Operand(1)); |
| 4982 | __ B(eq, codegen_->GetLabelOf(successors[last_index + 1])); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 4983 | } |
| 4984 | |
| 4985 | // And the default for any other value. |
| 4986 | if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) { |
| 4987 | __ B(codegen_->GetLabelOf(default_block)); |
| 4988 | } |
| 4989 | } else { |
Alexandre Rames | c01a664 | 2016-04-15 11:54:06 +0100 | [diff] [blame] | 4990 | JumpTableARM64* jump_table = codegen_->CreateJumpTable(switch_instr); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 4991 | |
| 4992 | UseScratchRegisterScope temps(codegen_->GetVIXLAssembler()); |
| 4993 | |
| 4994 | // Below instructions should use at most one blocked register. Since there are two blocked |
| 4995 | // registers, we are free to block one. |
| 4996 | Register temp_w = temps.AcquireW(); |
| 4997 | Register index; |
| 4998 | // Remove the bias. |
| 4999 | if (lower_bound != 0) { |
| 5000 | index = temp_w; |
| 5001 | __ Sub(index, value_reg, Operand(lower_bound)); |
| 5002 | } else { |
| 5003 | index = value_reg; |
| 5004 | } |
| 5005 | |
| 5006 | // Jump to default block if index is out of the range. |
| 5007 | __ Cmp(index, Operand(num_entries)); |
| 5008 | __ B(hs, codegen_->GetLabelOf(default_block)); |
| 5009 | |
| 5010 | // In current VIXL implementation, it won't require any blocked registers to encode the |
| 5011 | // immediate value for Adr. So we are free to use both VIXL blocked registers to reduce the |
| 5012 | // register pressure. |
| 5013 | Register table_base = temps.AcquireX(); |
| 5014 | // Load jump offset from the table. |
| 5015 | __ Adr(table_base, jump_table->GetTableStartLabel()); |
| 5016 | Register jump_offset = temp_w; |
| 5017 | __ Ldr(jump_offset, MemOperand(table_base, index, UXTW, 2)); |
| 5018 | |
| 5019 | // Jump to target block by branching to table_base(pc related) + offset. |
| 5020 | Register target_address = table_base; |
| 5021 | __ Add(target_address, table_base, Operand(jump_offset, SXTW)); |
| 5022 | __ Br(target_address); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 5023 | } |
| 5024 | } |
| 5025 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5026 | void InstructionCodeGeneratorARM64::GenerateReferenceLoadOneRegister(HInstruction* instruction, |
| 5027 | Location out, |
| 5028 | uint32_t offset, |
| 5029 | Location maybe_temp) { |
| 5030 | Primitive::Type type = Primitive::kPrimNot; |
| 5031 | Register out_reg = RegisterFrom(out, type); |
| 5032 | if (kEmitCompilerReadBarrier) { |
| 5033 | Register temp_reg = RegisterFrom(maybe_temp, type); |
| 5034 | if (kUseBakerReadBarrier) { |
| 5035 | // Load with fast path based Baker's read barrier. |
| 5036 | // /* HeapReference<Object> */ out = *(out + offset) |
| 5037 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 5038 | out, |
| 5039 | out_reg, |
| 5040 | offset, |
| 5041 | temp_reg, |
| 5042 | /* needs_null_check */ false, |
| 5043 | /* use_load_acquire */ false); |
| 5044 | } else { |
| 5045 | // Load with slow path based read barrier. |
| 5046 | // Save the value of `out` into `maybe_temp` before overwriting it |
| 5047 | // in the following move operation, as we will need it for the |
| 5048 | // read barrier below. |
| 5049 | __ Mov(temp_reg, out_reg); |
| 5050 | // /* HeapReference<Object> */ out = *(out + offset) |
| 5051 | __ Ldr(out_reg, HeapOperand(out_reg, offset)); |
| 5052 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
| 5053 | } |
| 5054 | } else { |
| 5055 | // Plain load with no read barrier. |
| 5056 | // /* HeapReference<Object> */ out = *(out + offset) |
| 5057 | __ Ldr(out_reg, HeapOperand(out_reg, offset)); |
| 5058 | GetAssembler()->MaybeUnpoisonHeapReference(out_reg); |
| 5059 | } |
| 5060 | } |
| 5061 | |
| 5062 | void InstructionCodeGeneratorARM64::GenerateReferenceLoadTwoRegisters(HInstruction* instruction, |
| 5063 | Location out, |
| 5064 | Location obj, |
| 5065 | uint32_t offset, |
| 5066 | Location maybe_temp) { |
| 5067 | Primitive::Type type = Primitive::kPrimNot; |
| 5068 | Register out_reg = RegisterFrom(out, type); |
| 5069 | Register obj_reg = RegisterFrom(obj, type); |
| 5070 | if (kEmitCompilerReadBarrier) { |
| 5071 | if (kUseBakerReadBarrier) { |
| 5072 | // Load with fast path based Baker's read barrier. |
| 5073 | Register temp_reg = RegisterFrom(maybe_temp, type); |
| 5074 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 5075 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 5076 | out, |
| 5077 | obj_reg, |
| 5078 | offset, |
| 5079 | temp_reg, |
| 5080 | /* needs_null_check */ false, |
| 5081 | /* use_load_acquire */ false); |
| 5082 | } else { |
| 5083 | // Load with slow path based read barrier. |
| 5084 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 5085 | __ Ldr(out_reg, HeapOperand(obj_reg, offset)); |
| 5086 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 5087 | } |
| 5088 | } else { |
| 5089 | // Plain load with no read barrier. |
| 5090 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 5091 | __ Ldr(out_reg, HeapOperand(obj_reg, offset)); |
| 5092 | GetAssembler()->MaybeUnpoisonHeapReference(out_reg); |
| 5093 | } |
| 5094 | } |
| 5095 | |
| 5096 | void InstructionCodeGeneratorARM64::GenerateGcRootFieldLoad(HInstruction* instruction, |
| 5097 | Location root, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5098 | Register obj, |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5099 | uint32_t offset, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5100 | vixl::aarch64::Label* fixup_label) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5101 | Register root_reg = RegisterFrom(root, Primitive::kPrimNot); |
| 5102 | if (kEmitCompilerReadBarrier) { |
| 5103 | if (kUseBakerReadBarrier) { |
| 5104 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
| 5105 | // Baker's read barrier are used: |
| 5106 | // |
| 5107 | // root = obj.field; |
| 5108 | // if (Thread::Current()->GetIsGcMarking()) { |
| 5109 | // root = ReadBarrier::Mark(root) |
| 5110 | // } |
| 5111 | |
| 5112 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5113 | if (fixup_label == nullptr) { |
| 5114 | __ Ldr(root_reg, MemOperand(obj, offset)); |
| 5115 | } else { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5116 | SingleEmissionCheckScope guard(GetVIXLAssembler()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5117 | __ Bind(fixup_label); |
| 5118 | __ ldr(root_reg, MemOperand(obj, offset)); |
| 5119 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5120 | static_assert( |
| 5121 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 5122 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 5123 | "have different sizes."); |
| 5124 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 5125 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 5126 | "have different sizes."); |
| 5127 | |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 5128 | // Slow path marking the GC root `root`. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5129 | SlowPathCodeARM64* slow_path = |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 5130 | new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathARM64(instruction, root); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5131 | codegen_->AddSlowPath(slow_path); |
| 5132 | |
| 5133 | MacroAssembler* masm = GetVIXLAssembler(); |
| 5134 | UseScratchRegisterScope temps(masm); |
| 5135 | Register temp = temps.AcquireW(); |
| 5136 | // temp = Thread::Current()->GetIsGcMarking() |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5137 | __ Ldr(temp, MemOperand(tr, Thread::IsGcMarkingOffset<kArm64PointerSize>().Int32Value())); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5138 | __ Cbnz(temp, slow_path->GetEntryLabel()); |
| 5139 | __ Bind(slow_path->GetExitLabel()); |
| 5140 | } else { |
| 5141 | // GC root loaded through a slow path for read barriers other |
| 5142 | // than Baker's. |
| 5143 | // /* GcRoot<mirror::Object>* */ root = obj + offset |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5144 | if (fixup_label == nullptr) { |
| 5145 | __ Add(root_reg.X(), obj.X(), offset); |
| 5146 | } else { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5147 | SingleEmissionCheckScope guard(GetVIXLAssembler()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5148 | __ Bind(fixup_label); |
| 5149 | __ add(root_reg.X(), obj.X(), offset); |
| 5150 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5151 | // /* mirror::Object* */ root = root->Read() |
| 5152 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 5153 | } |
| 5154 | } else { |
| 5155 | // Plain GC root load with no read barrier. |
| 5156 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5157 | if (fixup_label == nullptr) { |
| 5158 | __ Ldr(root_reg, MemOperand(obj, offset)); |
| 5159 | } else { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5160 | SingleEmissionCheckScope guard(GetVIXLAssembler()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5161 | __ Bind(fixup_label); |
| 5162 | __ ldr(root_reg, MemOperand(obj, offset)); |
| 5163 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5164 | // Note that GC roots are not affected by heap poisoning, thus we |
| 5165 | // do not have to unpoison `root_reg` here. |
| 5166 | } |
| 5167 | } |
| 5168 | |
| 5169 | void CodeGeneratorARM64::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 5170 | Location ref, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5171 | Register obj, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5172 | uint32_t offset, |
| 5173 | Register temp, |
| 5174 | bool needs_null_check, |
| 5175 | bool use_load_acquire) { |
| 5176 | DCHECK(kEmitCompilerReadBarrier); |
| 5177 | DCHECK(kUseBakerReadBarrier); |
| 5178 | |
| 5179 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 5180 | Location no_index = Location::NoLocation(); |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 5181 | size_t no_scale_factor = 0U; |
| 5182 | GenerateReferenceLoadWithBakerReadBarrier(instruction, |
| 5183 | ref, |
| 5184 | obj, |
| 5185 | offset, |
| 5186 | no_index, |
| 5187 | no_scale_factor, |
| 5188 | temp, |
| 5189 | needs_null_check, |
| 5190 | use_load_acquire); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5191 | } |
| 5192 | |
| 5193 | void CodeGeneratorARM64::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 5194 | Location ref, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5195 | Register obj, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5196 | uint32_t data_offset, |
| 5197 | Location index, |
| 5198 | Register temp, |
| 5199 | bool needs_null_check) { |
| 5200 | DCHECK(kEmitCompilerReadBarrier); |
| 5201 | DCHECK(kUseBakerReadBarrier); |
| 5202 | |
| 5203 | // Array cells are never volatile variables, therefore array loads |
| 5204 | // never use Load-Acquire instructions on ARM64. |
| 5205 | const bool use_load_acquire = false; |
| 5206 | |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 5207 | static_assert( |
| 5208 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 5209 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5210 | // /* HeapReference<Object> */ ref = |
| 5211 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 5212 | size_t scale_factor = Primitive::ComponentSizeShift(Primitive::kPrimNot); |
| 5213 | GenerateReferenceLoadWithBakerReadBarrier(instruction, |
| 5214 | ref, |
| 5215 | obj, |
| 5216 | data_offset, |
| 5217 | index, |
| 5218 | scale_factor, |
| 5219 | temp, |
| 5220 | needs_null_check, |
| 5221 | use_load_acquire); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5222 | } |
| 5223 | |
| 5224 | void CodeGeneratorARM64::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 5225 | Location ref, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5226 | Register obj, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5227 | uint32_t offset, |
| 5228 | Location index, |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 5229 | size_t scale_factor, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5230 | Register temp, |
| 5231 | bool needs_null_check, |
| 5232 | bool use_load_acquire) { |
| 5233 | DCHECK(kEmitCompilerReadBarrier); |
| 5234 | DCHECK(kUseBakerReadBarrier); |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 5235 | // If we are emitting an array load, we should not be using a |
| 5236 | // Load Acquire instruction. In other words: |
| 5237 | // `instruction->IsArrayGet()` => `!use_load_acquire`. |
| 5238 | DCHECK(!instruction->IsArrayGet() || !use_load_acquire); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5239 | |
| 5240 | MacroAssembler* masm = GetVIXLAssembler(); |
| 5241 | UseScratchRegisterScope temps(masm); |
| 5242 | |
| 5243 | // In slow path based read barriers, the read barrier call is |
| 5244 | // inserted after the original load. However, in fast path based |
| 5245 | // Baker's read barriers, we need to perform the load of |
| 5246 | // mirror::Object::monitor_ *before* the original reference load. |
| 5247 | // This load-load ordering is required by the read barrier. |
| 5248 | // The fast path/slow path (for Baker's algorithm) should look like: |
| 5249 | // |
| 5250 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 5251 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 5252 | // HeapReference<Object> ref = *src; // Original reference load. |
| 5253 | // bool is_gray = (rb_state == ReadBarrier::gray_ptr_); |
| 5254 | // if (is_gray) { |
| 5255 | // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path. |
| 5256 | // } |
| 5257 | // |
| 5258 | // Note: the original implementation in ReadBarrier::Barrier is |
| 5259 | // slightly more complex as it performs additional checks that we do |
| 5260 | // not do here for performance reasons. |
| 5261 | |
| 5262 | Primitive::Type type = Primitive::kPrimNot; |
| 5263 | Register ref_reg = RegisterFrom(ref, type); |
| 5264 | DCHECK(obj.IsW()); |
| 5265 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 5266 | |
| 5267 | // /* int32_t */ monitor = obj->monitor_ |
| 5268 | __ Ldr(temp, HeapOperand(obj, monitor_offset)); |
| 5269 | if (needs_null_check) { |
| 5270 | MaybeRecordImplicitNullCheck(instruction); |
| 5271 | } |
| 5272 | // /* LockWord */ lock_word = LockWord(monitor) |
| 5273 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 5274 | "art::LockWord and int32_t have different sizes."); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5275 | |
Vladimir Marko | 877a033 | 2016-07-11 19:30:56 +0100 | [diff] [blame] | 5276 | // Introduce a dependency on the lock_word including rb_state, |
| 5277 | // to prevent load-load reordering, and without using |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5278 | // a memory barrier (which would be more expensive). |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 5279 | // `obj` is unchanged by this operation, but its value now depends |
| 5280 | // on `temp`. |
Vladimir Marko | 877a033 | 2016-07-11 19:30:56 +0100 | [diff] [blame] | 5281 | __ Add(obj.X(), obj.X(), Operand(temp.X(), LSR, 32)); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5282 | |
| 5283 | // The actual reference load. |
| 5284 | if (index.IsValid()) { |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 5285 | // Load types involving an "index". |
| 5286 | if (use_load_acquire) { |
| 5287 | // UnsafeGetObjectVolatile intrinsic case. |
| 5288 | // Register `index` is not an index in an object array, but an |
| 5289 | // offset to an object reference field within object `obj`. |
| 5290 | DCHECK(instruction->IsInvoke()) << instruction->DebugName(); |
| 5291 | DCHECK(instruction->GetLocations()->Intrinsified()); |
| 5292 | DCHECK(instruction->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile) |
| 5293 | << instruction->AsInvoke()->GetIntrinsic(); |
| 5294 | DCHECK_EQ(offset, 0U); |
| 5295 | DCHECK_EQ(scale_factor, 0U); |
| 5296 | DCHECK_EQ(needs_null_check, 0U); |
| 5297 | // /* HeapReference<Object> */ ref = *(obj + index) |
| 5298 | MemOperand field = HeapOperand(obj, XRegisterFrom(index)); |
| 5299 | LoadAcquire(instruction, ref_reg, field, /* needs_null_check */ false); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5300 | } else { |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 5301 | // ArrayGet and UnsafeGetObject intrinsics cases. |
| 5302 | // /* HeapReference<Object> */ ref = *(obj + offset + (index << scale_factor)) |
| 5303 | if (index.IsConstant()) { |
| 5304 | uint32_t computed_offset = offset + (Int64ConstantFrom(index) << scale_factor); |
| 5305 | Load(type, ref_reg, HeapOperand(obj, computed_offset)); |
| 5306 | } else { |
Vladimir Marko | 877a033 | 2016-07-11 19:30:56 +0100 | [diff] [blame] | 5307 | Register temp2 = temps.AcquireW(); |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 5308 | __ Add(temp2, obj, offset); |
| 5309 | Load(type, ref_reg, HeapOperand(temp2, XRegisterFrom(index), LSL, scale_factor)); |
| 5310 | temps.Release(temp2); |
| 5311 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5312 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5313 | } else { |
| 5314 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 5315 | MemOperand field = HeapOperand(obj, offset); |
| 5316 | if (use_load_acquire) { |
| 5317 | LoadAcquire(instruction, ref_reg, field, /* needs_null_check */ false); |
| 5318 | } else { |
| 5319 | Load(type, ref_reg, field); |
| 5320 | } |
| 5321 | } |
| 5322 | |
| 5323 | // Object* ref = ref_addr->AsMirrorPtr() |
| 5324 | GetAssembler()->MaybeUnpoisonHeapReference(ref_reg); |
| 5325 | |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 5326 | // Slow path marking the object `ref` when it is gray. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5327 | SlowPathCodeARM64* slow_path = |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 5328 | new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathARM64(instruction, ref); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5329 | AddSlowPath(slow_path); |
| 5330 | |
| 5331 | // if (rb_state == ReadBarrier::gray_ptr_) |
| 5332 | // ref = ReadBarrier::Mark(ref); |
Vladimir Marko | 877a033 | 2016-07-11 19:30:56 +0100 | [diff] [blame] | 5333 | // Given the numeric representation, it's enough to check the low bit of the rb_state. |
| 5334 | static_assert(ReadBarrier::white_ptr_ == 0, "Expecting white to have value 0"); |
| 5335 | static_assert(ReadBarrier::gray_ptr_ == 1, "Expecting gray to have value 1"); |
| 5336 | static_assert(ReadBarrier::black_ptr_ == 2, "Expecting black to have value 2"); |
| 5337 | __ Tbnz(temp, LockWord::kReadBarrierStateShift, slow_path->GetEntryLabel()); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5338 | __ Bind(slow_path->GetExitLabel()); |
| 5339 | } |
| 5340 | |
| 5341 | void CodeGeneratorARM64::GenerateReadBarrierSlow(HInstruction* instruction, |
| 5342 | Location out, |
| 5343 | Location ref, |
| 5344 | Location obj, |
| 5345 | uint32_t offset, |
| 5346 | Location index) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5347 | DCHECK(kEmitCompilerReadBarrier); |
| 5348 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5349 | // Insert a slow path based read barrier *after* the reference load. |
| 5350 | // |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5351 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 5352 | // reference will be carried out by the runtime within the slow |
| 5353 | // path. |
| 5354 | // |
| 5355 | // Note that `ref` currently does not get unpoisoned (when heap |
| 5356 | // poisoning is enabled), which is alright as the `ref` argument is |
| 5357 | // not used by the artReadBarrierSlow entry point. |
| 5358 | // |
| 5359 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
| 5360 | SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) |
| 5361 | ReadBarrierForHeapReferenceSlowPathARM64(instruction, out, ref, obj, offset, index); |
| 5362 | AddSlowPath(slow_path); |
| 5363 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5364 | __ B(slow_path->GetEntryLabel()); |
| 5365 | __ Bind(slow_path->GetExitLabel()); |
| 5366 | } |
| 5367 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5368 | void CodeGeneratorARM64::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 5369 | Location out, |
| 5370 | Location ref, |
| 5371 | Location obj, |
| 5372 | uint32_t offset, |
| 5373 | Location index) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5374 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5375 | // Baker's read barriers shall be handled by the fast path |
| 5376 | // (CodeGeneratorARM64::GenerateReferenceLoadWithBakerReadBarrier). |
| 5377 | DCHECK(!kUseBakerReadBarrier); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5378 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 5379 | // by the runtime within the slow path. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5380 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5381 | } else if (kPoisonHeapReferences) { |
| 5382 | GetAssembler()->UnpoisonHeapReference(WRegisterFrom(out)); |
| 5383 | } |
| 5384 | } |
| 5385 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5386 | void CodeGeneratorARM64::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 5387 | Location out, |
| 5388 | Location root) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5389 | DCHECK(kEmitCompilerReadBarrier); |
| 5390 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5391 | // Insert a slow path based read barrier *after* the GC root load. |
| 5392 | // |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5393 | // Note that GC roots are not affected by heap poisoning, so we do |
| 5394 | // not need to do anything special for this here. |
| 5395 | SlowPathCodeARM64* slow_path = |
| 5396 | new (GetGraph()->GetArena()) ReadBarrierForRootSlowPathARM64(instruction, out, root); |
| 5397 | AddSlowPath(slow_path); |
| 5398 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5399 | __ B(slow_path->GetEntryLabel()); |
| 5400 | __ Bind(slow_path->GetExitLabel()); |
| 5401 | } |
| 5402 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 5403 | void LocationsBuilderARM64::VisitClassTableGet(HClassTableGet* instruction) { |
| 5404 | LocationSummary* locations = |
| 5405 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 5406 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5407 | locations->SetOut(Location::RequiresRegister()); |
| 5408 | } |
| 5409 | |
| 5410 | void InstructionCodeGeneratorARM64::VisitClassTableGet(HClassTableGet* instruction) { |
| 5411 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5412 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 5413 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 5414 | instruction->GetIndex(), kArm64PointerSize).SizeValue(); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 5415 | __ Ldr(XRegisterFrom(locations->Out()), |
| 5416 | MemOperand(XRegisterFrom(locations->InAt(0)), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 5417 | } else { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 5418 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 5419 | instruction->GetIndex(), kArm64PointerSize)); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 5420 | __ Ldr(XRegisterFrom(locations->Out()), MemOperand(XRegisterFrom(locations->InAt(0)), |
| 5421 | mirror::Class::ImtPtrOffset(kArm64PointerSize).Uint32Value())); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 5422 | __ Ldr(XRegisterFrom(locations->Out()), |
| 5423 | MemOperand(XRegisterFrom(locations->Out()), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 5424 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 5425 | } |
| 5426 | |
| 5427 | |
| 5428 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5429 | #undef __ |
| 5430 | #undef QUICK_ENTRY_POINT |
| 5431 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5432 | } // namespace arm64 |
| 5433 | } // namespace art |