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