Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "code_generator_arm64.h" |
| 18 | |
Serban Constantinescu | 579885a | 2015-02-22 20:51:33 +0000 | [diff] [blame] | 19 | #include "arch/arm64/instruction_set_features_arm64.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 20 | #include "art_method.h" |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 21 | #include "code_generator_utils.h" |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 22 | #include "compiled_method.h" |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 23 | #include "entrypoints/quick/quick_entrypoints.h" |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 24 | #include "entrypoints/quick/quick_entrypoints_enum.h" |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 25 | #include "gc/accounting/card_table.h" |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 26 | #include "intrinsics.h" |
| 27 | #include "intrinsics_arm64.h" |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 28 | #include "mirror/array-inl.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 29 | #include "mirror/class-inl.h" |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 30 | #include "offsets.h" |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 31 | #include "thread.h" |
| 32 | #include "utils/arm64/assembler_arm64.h" |
| 33 | #include "utils/assembler.h" |
| 34 | #include "utils/stack_checks.h" |
| 35 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 36 | using namespace vixl::aarch64; // NOLINT(build/namespaces) |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 37 | |
| 38 | #ifdef __ |
| 39 | #error "ARM64 Codegen VIXL macro-assembler macro already defined." |
| 40 | #endif |
| 41 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 42 | namespace art { |
| 43 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 44 | template<class MirrorType> |
| 45 | class GcRoot; |
| 46 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 47 | namespace arm64 { |
| 48 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 49 | using helpers::CPURegisterFrom; |
| 50 | using helpers::DRegisterFrom; |
| 51 | using helpers::FPRegisterFrom; |
| 52 | using helpers::HeapOperand; |
| 53 | using helpers::HeapOperandFrom; |
| 54 | using helpers::InputCPURegisterAt; |
| 55 | using helpers::InputFPRegisterAt; |
| 56 | using helpers::InputRegisterAt; |
| 57 | using helpers::InputOperandAt; |
| 58 | using helpers::Int64ConstantFrom; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 59 | using helpers::LocationFrom; |
| 60 | using helpers::OperandFromMemOperand; |
| 61 | using helpers::OutputCPURegister; |
| 62 | using helpers::OutputFPRegister; |
| 63 | using helpers::OutputRegister; |
| 64 | using helpers::RegisterFrom; |
| 65 | using helpers::StackOperandFrom; |
| 66 | using helpers::VIXLRegCodeFromART; |
| 67 | using helpers::WRegisterFrom; |
| 68 | using helpers::XRegisterFrom; |
Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 69 | using helpers::ARM64EncodableConstantOrRegister; |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 70 | using helpers::ArtVixlRegCodeCoherentForRegSet; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 71 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 72 | static constexpr int kCurrentMethodStackOffset = 0; |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 73 | // The compare/jump sequence will generate about (1.5 * num_entries + 3) instructions. While jump |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 74 | // table version generates 7 instructions and num_entries literals. Compare/jump sequence will |
| 75 | // generates less code/data with a small num_entries. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 76 | static constexpr uint32_t kPackedSwitchCompareJumpThreshold = 7; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 77 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 78 | inline Condition ARM64Condition(IfCondition cond) { |
| 79 | switch (cond) { |
| 80 | case kCondEQ: return eq; |
| 81 | case kCondNE: return ne; |
| 82 | case kCondLT: return lt; |
| 83 | case kCondLE: return le; |
| 84 | case kCondGT: return gt; |
| 85 | case kCondGE: return ge; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 86 | case kCondB: return lo; |
| 87 | case kCondBE: return ls; |
| 88 | case kCondA: return hi; |
| 89 | case kCondAE: return hs; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 90 | } |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 91 | LOG(FATAL) << "Unreachable"; |
| 92 | UNREACHABLE(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 93 | } |
| 94 | |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 95 | inline Condition ARM64FPCondition(IfCondition cond, bool gt_bias) { |
| 96 | // The ARM64 condition codes can express all the necessary branches, see the |
| 97 | // "Meaning (floating-point)" column in the table C1-1 in the ARMv8 reference manual. |
| 98 | // There is no dex instruction or HIR that would need the missing conditions |
| 99 | // "equal or unordered" or "not equal". |
| 100 | switch (cond) { |
| 101 | case kCondEQ: return eq; |
| 102 | case kCondNE: return ne /* unordered */; |
| 103 | case kCondLT: return gt_bias ? cc : lt /* unordered */; |
| 104 | case kCondLE: return gt_bias ? ls : le /* unordered */; |
| 105 | case kCondGT: return gt_bias ? hi /* unordered */ : gt; |
| 106 | case kCondGE: return gt_bias ? cs /* unordered */ : ge; |
| 107 | default: |
| 108 | LOG(FATAL) << "UNREACHABLE"; |
| 109 | UNREACHABLE(); |
| 110 | } |
| 111 | } |
| 112 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 113 | Location ARM64ReturnLocation(Primitive::Type return_type) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 114 | // Note that in practice, `LocationFrom(x0)` and `LocationFrom(w0)` create the |
| 115 | // same Location object, and so do `LocationFrom(d0)` and `LocationFrom(s0)`, |
| 116 | // but we use the exact registers for clarity. |
| 117 | if (return_type == Primitive::kPrimFloat) { |
| 118 | return LocationFrom(s0); |
| 119 | } else if (return_type == Primitive::kPrimDouble) { |
| 120 | return LocationFrom(d0); |
| 121 | } else if (return_type == Primitive::kPrimLong) { |
| 122 | return LocationFrom(x0); |
Nicolas Geoffray | 925e562 | 2015-06-03 12:23:32 +0100 | [diff] [blame] | 123 | } else if (return_type == Primitive::kPrimVoid) { |
| 124 | return Location::NoLocation(); |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 125 | } else { |
| 126 | return LocationFrom(w0); |
| 127 | } |
| 128 | } |
| 129 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 130 | Location InvokeRuntimeCallingConvention::GetReturnLocation(Primitive::Type return_type) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 131 | return ARM64ReturnLocation(return_type); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 132 | } |
| 133 | |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 134 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 135 | #define __ down_cast<CodeGeneratorARM64*>(codegen)->GetVIXLAssembler()-> // NOLINT |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 136 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kArm64PointerSize, x).Int32Value() |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 137 | |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 138 | // Calculate memory accessing operand for save/restore live registers. |
| 139 | static void SaveRestoreLiveRegistersHelper(CodeGenerator* codegen, |
| 140 | RegisterSet* register_set, |
| 141 | int64_t spill_offset, |
| 142 | bool is_save) { |
| 143 | DCHECK(ArtVixlRegCodeCoherentForRegSet(register_set->GetCoreRegisters(), |
| 144 | codegen->GetNumberOfCoreRegisters(), |
| 145 | register_set->GetFloatingPointRegisters(), |
| 146 | codegen->GetNumberOfFloatingPointRegisters())); |
| 147 | |
| 148 | CPURegList core_list = CPURegList(CPURegister::kRegister, kXRegSize, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 149 | register_set->GetCoreRegisters() & (~callee_saved_core_registers.GetList())); |
Nicolas Geoffray | 75d5b9b | 2015-10-05 07:40:35 +0000 | [diff] [blame] | 150 | CPURegList fp_list = CPURegList(CPURegister::kFPRegister, kDRegSize, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 151 | register_set->GetFloatingPointRegisters() & (~callee_saved_fp_registers.GetList())); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 152 | |
| 153 | MacroAssembler* masm = down_cast<CodeGeneratorARM64*>(codegen)->GetVIXLAssembler(); |
| 154 | UseScratchRegisterScope temps(masm); |
| 155 | |
| 156 | Register base = masm->StackPointer(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 157 | int64_t core_spill_size = core_list.GetTotalSizeInBytes(); |
| 158 | int64_t fp_spill_size = fp_list.GetTotalSizeInBytes(); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 159 | int64_t reg_size = kXRegSizeInBytes; |
| 160 | int64_t max_ls_pair_offset = spill_offset + core_spill_size + fp_spill_size - 2 * reg_size; |
| 161 | uint32_t ls_access_size = WhichPowerOf2(reg_size); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 162 | if (((core_list.GetCount() > 1) || (fp_list.GetCount() > 1)) && |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 163 | !masm->IsImmLSPair(max_ls_pair_offset, ls_access_size)) { |
| 164 | // If the offset does not fit in the instruction's immediate field, use an alternate register |
| 165 | // to compute the base address(float point registers spill base address). |
| 166 | Register new_base = temps.AcquireSameSizeAs(base); |
| 167 | __ Add(new_base, base, Operand(spill_offset + core_spill_size)); |
| 168 | base = new_base; |
| 169 | spill_offset = -core_spill_size; |
| 170 | int64_t new_max_ls_pair_offset = fp_spill_size - 2 * reg_size; |
| 171 | DCHECK(masm->IsImmLSPair(spill_offset, ls_access_size)); |
| 172 | DCHECK(masm->IsImmLSPair(new_max_ls_pair_offset, ls_access_size)); |
| 173 | } |
| 174 | |
| 175 | if (is_save) { |
| 176 | __ StoreCPURegList(core_list, MemOperand(base, spill_offset)); |
| 177 | __ StoreCPURegList(fp_list, MemOperand(base, spill_offset + core_spill_size)); |
| 178 | } else { |
| 179 | __ LoadCPURegList(core_list, MemOperand(base, spill_offset)); |
| 180 | __ LoadCPURegList(fp_list, MemOperand(base, spill_offset + core_spill_size)); |
| 181 | } |
| 182 | } |
| 183 | |
| 184 | void SlowPathCodeARM64::SaveLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) { |
| 185 | RegisterSet* register_set = locations->GetLiveRegisters(); |
| 186 | size_t stack_offset = codegen->GetFirstRegisterSlotInSlowPath(); |
| 187 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 188 | if (!codegen->IsCoreCalleeSaveRegister(i) && register_set->ContainsCoreRegister(i)) { |
| 189 | // If the register holds an object, update the stack mask. |
| 190 | if (locations->RegisterContainsObject(i)) { |
| 191 | locations->SetStackBit(stack_offset / kVRegSize); |
| 192 | } |
| 193 | DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 194 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 195 | saved_core_stack_offsets_[i] = stack_offset; |
| 196 | stack_offset += kXRegSizeInBytes; |
| 197 | } |
| 198 | } |
| 199 | |
| 200 | for (size_t i = 0, e = codegen->GetNumberOfFloatingPointRegisters(); i < e; ++i) { |
| 201 | if (!codegen->IsFloatingPointCalleeSaveRegister(i) && |
| 202 | register_set->ContainsFloatingPointRegister(i)) { |
| 203 | DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 204 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 205 | saved_fpu_stack_offsets_[i] = stack_offset; |
| 206 | stack_offset += kDRegSizeInBytes; |
| 207 | } |
| 208 | } |
| 209 | |
| 210 | SaveRestoreLiveRegistersHelper(codegen, register_set, |
| 211 | codegen->GetFirstRegisterSlotInSlowPath(), true /* is_save */); |
| 212 | } |
| 213 | |
| 214 | void SlowPathCodeARM64::RestoreLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) { |
| 215 | RegisterSet* register_set = locations->GetLiveRegisters(); |
| 216 | SaveRestoreLiveRegistersHelper(codegen, register_set, |
| 217 | codegen->GetFirstRegisterSlotInSlowPath(), false /* is_save */); |
| 218 | } |
| 219 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 220 | class BoundsCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 221 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 222 | explicit BoundsCheckSlowPathARM64(HBoundsCheck* instruction) : SlowPathCodeARM64(instruction) {} |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 223 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 224 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 225 | LocationSummary* locations = instruction_->GetLocations(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 226 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 227 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 228 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 229 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 230 | // Live registers will be restored in the catch block if caught. |
| 231 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 232 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 233 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 234 | // move resolver. |
| 235 | InvokeRuntimeCallingConvention calling_convention; |
| 236 | codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 237 | locations->InAt(0), LocationFrom(calling_convention.GetRegisterAt(0)), Primitive::kPrimInt, |
| 238 | locations->InAt(1), LocationFrom(calling_convention.GetRegisterAt(1)), Primitive::kPrimInt); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 239 | uint32_t entry_point_offset = instruction_->AsBoundsCheck()->IsStringCharAt() |
| 240 | ? QUICK_ENTRY_POINT(pThrowStringBounds) |
| 241 | : QUICK_ENTRY_POINT(pThrowArrayBounds); |
| 242 | arm64_codegen->InvokeRuntime(entry_point_offset, instruction_, instruction_->GetDexPc(), this); |
| 243 | CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>(); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 244 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 245 | } |
| 246 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 247 | bool IsFatal() const OVERRIDE { return true; } |
| 248 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 249 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathARM64"; } |
| 250 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 251 | private: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 252 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathARM64); |
| 253 | }; |
| 254 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 255 | class DivZeroCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 256 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 257 | explicit DivZeroCheckSlowPathARM64(HDivZeroCheck* instruction) : SlowPathCodeARM64(instruction) {} |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 258 | |
| 259 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 260 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 261 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 262 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 263 | // Live registers will be restored in the catch block if caught. |
| 264 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 265 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 266 | arm64_codegen->InvokeRuntime( |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 267 | QUICK_ENTRY_POINT(pThrowDivZero), instruction_, instruction_->GetDexPc(), this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 268 | CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 269 | } |
| 270 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 271 | bool IsFatal() const OVERRIDE { return true; } |
| 272 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 273 | const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathARM64"; } |
| 274 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 275 | private: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 276 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathARM64); |
| 277 | }; |
| 278 | |
| 279 | class LoadClassSlowPathARM64 : public SlowPathCodeARM64 { |
| 280 | public: |
| 281 | LoadClassSlowPathARM64(HLoadClass* cls, |
| 282 | HInstruction* at, |
| 283 | uint32_t dex_pc, |
| 284 | bool do_clinit) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 285 | : SlowPathCodeARM64(at), cls_(cls), at_(at), dex_pc_(dex_pc), do_clinit_(do_clinit) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 286 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 287 | } |
| 288 | |
| 289 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 290 | LocationSummary* locations = at_->GetLocations(); |
| 291 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 292 | |
| 293 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 294 | SaveLiveRegisters(codegen, locations); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 295 | |
| 296 | InvokeRuntimeCallingConvention calling_convention; |
| 297 | __ Mov(calling_convention.GetRegisterAt(0).W(), cls_->GetTypeIndex()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 298 | int32_t entry_point_offset = do_clinit_ ? QUICK_ENTRY_POINT(pInitializeStaticStorage) |
| 299 | : QUICK_ENTRY_POINT(pInitializeType); |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 300 | arm64_codegen->InvokeRuntime(entry_point_offset, at_, dex_pc_, this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 301 | if (do_clinit_) { |
Vladimir Marko | 5ea536a | 2015-04-20 20:11:30 +0100 | [diff] [blame] | 302 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>(); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 303 | } else { |
Vladimir Marko | 5ea536a | 2015-04-20 20:11:30 +0100 | [diff] [blame] | 304 | CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>(); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 305 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 306 | |
| 307 | // Move the class to the desired location. |
| 308 | Location out = locations->Out(); |
| 309 | if (out.IsValid()) { |
| 310 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
| 311 | Primitive::Type type = at_->GetType(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 312 | arm64_codegen->MoveLocation(out, calling_convention.GetReturnLocation(type), type); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 313 | } |
| 314 | |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 315 | RestoreLiveRegisters(codegen, locations); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 316 | __ B(GetExitLabel()); |
| 317 | } |
| 318 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 319 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathARM64"; } |
| 320 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 321 | private: |
| 322 | // The class this slow path will load. |
| 323 | HLoadClass* const cls_; |
| 324 | |
| 325 | // The instruction where this slow path is happening. |
| 326 | // (Might be the load class or an initialization check). |
| 327 | HInstruction* const at_; |
| 328 | |
| 329 | // The dex PC of `at_`. |
| 330 | const uint32_t dex_pc_; |
| 331 | |
| 332 | // Whether to initialize the class. |
| 333 | const bool do_clinit_; |
| 334 | |
| 335 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathARM64); |
| 336 | }; |
| 337 | |
| 338 | class LoadStringSlowPathARM64 : public SlowPathCodeARM64 { |
| 339 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 340 | explicit LoadStringSlowPathARM64(HLoadString* instruction) : SlowPathCodeARM64(instruction) {} |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 341 | |
| 342 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 343 | LocationSummary* locations = instruction_->GetLocations(); |
| 344 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 345 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 346 | |
| 347 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 348 | SaveLiveRegisters(codegen, locations); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 349 | |
| 350 | InvokeRuntimeCallingConvention calling_convention; |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 351 | const uint32_t string_index = instruction_->AsLoadString()->GetStringIndex(); |
| 352 | __ Mov(calling_convention.GetRegisterAt(0).W(), string_index); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 353 | arm64_codegen->InvokeRuntime( |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 354 | QUICK_ENTRY_POINT(pResolveString), instruction_, instruction_->GetDexPc(), this); |
Vladimir Marko | 5ea536a | 2015-04-20 20:11:30 +0100 | [diff] [blame] | 355 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 356 | Primitive::Type type = instruction_->GetType(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 357 | arm64_codegen->MoveLocation(locations->Out(), calling_convention.GetReturnLocation(type), type); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 358 | |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 359 | RestoreLiveRegisters(codegen, locations); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 360 | __ B(GetExitLabel()); |
| 361 | } |
| 362 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 363 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathARM64"; } |
| 364 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 365 | private: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 366 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathARM64); |
| 367 | }; |
| 368 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 369 | class NullCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 370 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 371 | explicit NullCheckSlowPathARM64(HNullCheck* instr) : SlowPathCodeARM64(instr) {} |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 372 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 373 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 374 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 375 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 376 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 377 | // Live registers will be restored in the catch block if caught. |
| 378 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 379 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 380 | arm64_codegen->InvokeRuntime( |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 381 | QUICK_ENTRY_POINT(pThrowNullPointer), instruction_, instruction_->GetDexPc(), this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 382 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 383 | } |
| 384 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 385 | bool IsFatal() const OVERRIDE { return true; } |
| 386 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 387 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathARM64"; } |
| 388 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 389 | private: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 390 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathARM64); |
| 391 | }; |
| 392 | |
| 393 | class SuspendCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 394 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 395 | SuspendCheckSlowPathARM64(HSuspendCheck* instruction, HBasicBlock* successor) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 396 | : SlowPathCodeARM64(instruction), successor_(successor) {} |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 397 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 398 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 399 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 400 | __ Bind(GetEntryLabel()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 401 | arm64_codegen->InvokeRuntime( |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 402 | QUICK_ENTRY_POINT(pTestSuspend), instruction_, instruction_->GetDexPc(), this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 403 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 404 | if (successor_ == nullptr) { |
| 405 | __ B(GetReturnLabel()); |
| 406 | } else { |
| 407 | __ B(arm64_codegen->GetLabelOf(successor_)); |
| 408 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 409 | } |
| 410 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 411 | vixl::aarch64::Label* GetReturnLabel() { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 412 | DCHECK(successor_ == nullptr); |
| 413 | return &return_label_; |
| 414 | } |
| 415 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 416 | HBasicBlock* GetSuccessor() const { |
| 417 | return successor_; |
| 418 | } |
| 419 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 420 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathARM64"; } |
| 421 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 422 | private: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 423 | // If not null, the block to branch to after the suspend check. |
| 424 | HBasicBlock* const successor_; |
| 425 | |
| 426 | // If `successor_` is null, the label to branch to after the suspend check. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 427 | vixl::aarch64::Label return_label_; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 428 | |
| 429 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathARM64); |
| 430 | }; |
| 431 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 432 | class TypeCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 433 | public: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 434 | TypeCheckSlowPathARM64(HInstruction* instruction, bool is_fatal) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 435 | : SlowPathCodeARM64(instruction), is_fatal_(is_fatal) {} |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 436 | |
| 437 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 438 | LocationSummary* locations = instruction_->GetLocations(); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 439 | Location class_to_check = locations->InAt(1); |
| 440 | Location object_class = instruction_->IsCheckCast() ? locations->GetTemp(0) |
| 441 | : locations->Out(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 442 | DCHECK(instruction_->IsCheckCast() |
| 443 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 444 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 445 | uint32_t dex_pc = instruction_->GetDexPc(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 446 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 447 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 448 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 449 | if (!is_fatal_) { |
| 450 | SaveLiveRegisters(codegen, locations); |
| 451 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 452 | |
| 453 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 454 | // move resolver. |
| 455 | InvokeRuntimeCallingConvention calling_convention; |
| 456 | codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 457 | class_to_check, LocationFrom(calling_convention.GetRegisterAt(0)), Primitive::kPrimNot, |
| 458 | object_class, LocationFrom(calling_convention.GetRegisterAt(1)), Primitive::kPrimNot); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 459 | |
| 460 | if (instruction_->IsInstanceOf()) { |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 461 | arm64_codegen->InvokeRuntime( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 462 | QUICK_ENTRY_POINT(pInstanceofNonTrivial), instruction_, dex_pc, this); |
Andreas Gampe | 6740997 | 2016-07-19 22:34:53 -0700 | [diff] [blame] | 463 | CheckEntrypointTypes<kQuickInstanceofNonTrivial, size_t, |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 464 | const mirror::Class*, const mirror::Class*>(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 465 | Primitive::Type ret_type = instruction_->GetType(); |
| 466 | Location ret_loc = calling_convention.GetReturnLocation(ret_type); |
| 467 | arm64_codegen->MoveLocation(locations->Out(), ret_loc, ret_type); |
| 468 | } else { |
| 469 | DCHECK(instruction_->IsCheckCast()); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 470 | arm64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pCheckCast), instruction_, dex_pc, this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 471 | CheckEntrypointTypes<kQuickCheckCast, void, const mirror::Class*, const mirror::Class*>(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 472 | } |
| 473 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 474 | if (!is_fatal_) { |
| 475 | RestoreLiveRegisters(codegen, locations); |
| 476 | __ B(GetExitLabel()); |
| 477 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 478 | } |
| 479 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 480 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathARM64"; } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 481 | bool IsFatal() const { return is_fatal_; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 482 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 483 | private: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 484 | const bool is_fatal_; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 485 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 486 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathARM64); |
| 487 | }; |
| 488 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 489 | class DeoptimizationSlowPathARM64 : public SlowPathCodeARM64 { |
| 490 | public: |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 491 | explicit DeoptimizationSlowPathARM64(HDeoptimize* instruction) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 492 | : SlowPathCodeARM64(instruction) {} |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 493 | |
| 494 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 495 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 496 | __ Bind(GetEntryLabel()); |
| 497 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 498 | arm64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pDeoptimize), |
| 499 | instruction_, |
| 500 | instruction_->GetDexPc(), |
| 501 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 502 | CheckEntrypointTypes<kQuickDeoptimize, void, void>(); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 503 | } |
| 504 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 505 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathARM64"; } |
| 506 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 507 | private: |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 508 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathARM64); |
| 509 | }; |
| 510 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 511 | class ArraySetSlowPathARM64 : public SlowPathCodeARM64 { |
| 512 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 513 | explicit ArraySetSlowPathARM64(HInstruction* instruction) : SlowPathCodeARM64(instruction) {} |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 514 | |
| 515 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 516 | LocationSummary* locations = instruction_->GetLocations(); |
| 517 | __ Bind(GetEntryLabel()); |
| 518 | SaveLiveRegisters(codegen, locations); |
| 519 | |
| 520 | InvokeRuntimeCallingConvention calling_convention; |
| 521 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 522 | parallel_move.AddMove( |
| 523 | locations->InAt(0), |
| 524 | LocationFrom(calling_convention.GetRegisterAt(0)), |
| 525 | Primitive::kPrimNot, |
| 526 | nullptr); |
| 527 | parallel_move.AddMove( |
| 528 | locations->InAt(1), |
| 529 | LocationFrom(calling_convention.GetRegisterAt(1)), |
| 530 | Primitive::kPrimInt, |
| 531 | nullptr); |
| 532 | parallel_move.AddMove( |
| 533 | locations->InAt(2), |
| 534 | LocationFrom(calling_convention.GetRegisterAt(2)), |
| 535 | Primitive::kPrimNot, |
| 536 | nullptr); |
| 537 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 538 | |
| 539 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 540 | arm64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject), |
| 541 | instruction_, |
| 542 | instruction_->GetDexPc(), |
| 543 | this); |
| 544 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
| 545 | RestoreLiveRegisters(codegen, locations); |
| 546 | __ B(GetExitLabel()); |
| 547 | } |
| 548 | |
| 549 | const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathARM64"; } |
| 550 | |
| 551 | private: |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 552 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathARM64); |
| 553 | }; |
| 554 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 555 | void JumpTableARM64::EmitTable(CodeGeneratorARM64* codegen) { |
| 556 | uint32_t num_entries = switch_instr_->GetNumEntries(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 557 | DCHECK_GE(num_entries, kPackedSwitchCompareJumpThreshold); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 558 | |
| 559 | // We are about to use the assembler to place literals directly. Make sure we have enough |
| 560 | // underlying code buffer and we have generated the jump table with right size. |
| 561 | CodeBufferCheckScope scope(codegen->GetVIXLAssembler(), num_entries * sizeof(int32_t), |
| 562 | CodeBufferCheckScope::kCheck, CodeBufferCheckScope::kExactSize); |
| 563 | |
| 564 | __ Bind(&table_start_); |
| 565 | const ArenaVector<HBasicBlock*>& successors = switch_instr_->GetBlock()->GetSuccessors(); |
| 566 | for (uint32_t i = 0; i < num_entries; i++) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 567 | vixl::aarch64::Label* target_label = codegen->GetLabelOf(successors[i]); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 568 | DCHECK(target_label->IsBound()); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 569 | ptrdiff_t jump_offset = target_label->GetLocation() - table_start_.GetLocation(); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 570 | DCHECK_GT(jump_offset, std::numeric_limits<int32_t>::min()); |
| 571 | DCHECK_LE(jump_offset, std::numeric_limits<int32_t>::max()); |
| 572 | Literal<int32_t> literal(jump_offset); |
| 573 | __ place(&literal); |
| 574 | } |
| 575 | } |
| 576 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 577 | // Slow path marking an object during a read barrier. |
| 578 | class ReadBarrierMarkSlowPathARM64 : public SlowPathCodeARM64 { |
| 579 | public: |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 580 | ReadBarrierMarkSlowPathARM64(HInstruction* instruction, Location obj) |
| 581 | : SlowPathCodeARM64(instruction), obj_(obj) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 582 | DCHECK(kEmitCompilerReadBarrier); |
| 583 | } |
| 584 | |
| 585 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathARM64"; } |
| 586 | |
| 587 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 588 | LocationSummary* locations = instruction_->GetLocations(); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 589 | DCHECK(locations->CanCall()); |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 590 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(obj_.reg())); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 591 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 592 | instruction_->IsStaticFieldGet() || |
| 593 | instruction_->IsArrayGet() || |
| 594 | instruction_->IsLoadClass() || |
| 595 | instruction_->IsLoadString() || |
| 596 | instruction_->IsInstanceOf() || |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 597 | instruction_->IsCheckCast() || |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 598 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()) || |
| 599 | (instruction_->IsInvokeStaticOrDirect() && instruction_->GetLocations()->Intrinsified())) |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 600 | << "Unexpected instruction in read barrier marking slow path: " |
| 601 | << instruction_->DebugName(); |
| 602 | |
| 603 | __ Bind(GetEntryLabel()); |
Roland Levillain | 4359e61 | 2016-07-20 11:32:19 +0100 | [diff] [blame] | 604 | // No need to save live registers; it's taken care of by the |
| 605 | // entrypoint. Also, there is no need to update the stack mask, |
| 606 | // as this runtime call will not trigger a garbage collection. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 607 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 608 | DCHECK_NE(obj_.reg(), LR); |
| 609 | DCHECK_NE(obj_.reg(), WSP); |
| 610 | DCHECK_NE(obj_.reg(), WZR); |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 611 | // IP0 is used internally by the ReadBarrierMarkRegX entry point |
| 612 | // as a temporary, it cannot be the entry point's input/output. |
Mathieu Chartier | 36a270a | 2016-07-28 18:08:51 -0700 | [diff] [blame] | 613 | DCHECK_NE(obj_.reg(), IP0); |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 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 = |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 630 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArm64PointerSize>(obj_.reg()); |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 631 | // This runtime call does not require a stack map. |
| 632 | arm64_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 633 | __ B(GetExitLabel()); |
| 634 | } |
| 635 | |
| 636 | private: |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 637 | const Location obj_; |
| 638 | |
| 639 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathARM64); |
| 640 | }; |
| 641 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 642 | // Slow path generating a read barrier for a heap reference. |
| 643 | class ReadBarrierForHeapReferenceSlowPathARM64 : public SlowPathCodeARM64 { |
| 644 | public: |
| 645 | ReadBarrierForHeapReferenceSlowPathARM64(HInstruction* instruction, |
| 646 | Location out, |
| 647 | Location ref, |
| 648 | Location obj, |
| 649 | uint32_t offset, |
| 650 | Location index) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 651 | : SlowPathCodeARM64(instruction), |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 652 | out_(out), |
| 653 | ref_(ref), |
| 654 | obj_(obj), |
| 655 | offset_(offset), |
| 656 | index_(index) { |
| 657 | DCHECK(kEmitCompilerReadBarrier); |
| 658 | // If `obj` is equal to `out` or `ref`, it means the initial object |
| 659 | // has been overwritten by (or after) the heap object reference load |
| 660 | // to be instrumented, e.g.: |
| 661 | // |
| 662 | // __ Ldr(out, HeapOperand(out, class_offset); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 663 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 664 | // |
| 665 | // In that case, we have lost the information about the original |
| 666 | // object, and the emitted read barrier cannot work properly. |
| 667 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 668 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 669 | } |
| 670 | |
| 671 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 672 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 673 | LocationSummary* locations = instruction_->GetLocations(); |
| 674 | Primitive::Type type = Primitive::kPrimNot; |
| 675 | DCHECK(locations->CanCall()); |
| 676 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(out_.reg())); |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 677 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 678 | instruction_->IsStaticFieldGet() || |
| 679 | instruction_->IsArrayGet() || |
| 680 | instruction_->IsInstanceOf() || |
| 681 | instruction_->IsCheckCast() || |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 682 | (instruction_->IsInvokeVirtual()) && instruction_->GetLocations()->Intrinsified()) |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 683 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 684 | << instruction_->DebugName(); |
Roland Levillain | 4a3aa57 | 2016-08-15 13:17:06 +0000 | [diff] [blame] | 685 | // The read barrier instrumentation does not support the HIntermediateAddress instruction yet. |
Roland Levillain | cd3d0fb | 2016-01-15 19:26:48 +0000 | [diff] [blame] | 686 | DCHECK(!(instruction_->IsArrayGet() && |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 687 | instruction_->AsArrayGet()->GetArray()->IsIntermediateAddress())); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 688 | |
| 689 | __ Bind(GetEntryLabel()); |
| 690 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 691 | SaveLiveRegisters(codegen, locations); |
| 692 | |
| 693 | // We may have to change the index's value, but as `index_` is a |
| 694 | // constant member (like other "inputs" of this slow path), |
| 695 | // introduce a copy of it, `index`. |
| 696 | Location index = index_; |
| 697 | if (index_.IsValid()) { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 698 | // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 699 | if (instruction_->IsArrayGet()) { |
| 700 | // Compute the actual memory offset and store it in `index`. |
| 701 | Register index_reg = RegisterFrom(index_, Primitive::kPrimInt); |
| 702 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_.reg())); |
| 703 | if (codegen->IsCoreCalleeSaveRegister(index_.reg())) { |
| 704 | // We are about to change the value of `index_reg` (see the |
| 705 | // calls to vixl::MacroAssembler::Lsl and |
| 706 | // vixl::MacroAssembler::Mov below), but it has |
| 707 | // not been saved by the previous call to |
| 708 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 709 | // callee-save register -- |
| 710 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 711 | // callee-save registers, as it has been designed with the |
| 712 | // assumption that callee-save registers are supposed to be |
| 713 | // handled by the called function. So, as a callee-save |
| 714 | // register, `index_reg` _would_ eventually be saved onto |
| 715 | // the stack, but it would be too late: we would have |
| 716 | // changed its value earlier. Therefore, we manually save |
| 717 | // it here into another freely available register, |
| 718 | // `free_reg`, chosen of course among the caller-save |
| 719 | // registers (as a callee-save `free_reg` register would |
| 720 | // exhibit the same problem). |
| 721 | // |
| 722 | // Note we could have requested a temporary register from |
| 723 | // the register allocator instead; but we prefer not to, as |
| 724 | // this is a slow path, and we know we can find a |
| 725 | // caller-save register that is available. |
| 726 | Register free_reg = FindAvailableCallerSaveRegister(codegen); |
| 727 | __ Mov(free_reg.W(), index_reg); |
| 728 | index_reg = free_reg; |
| 729 | index = LocationFrom(index_reg); |
| 730 | } else { |
| 731 | // The initial register stored in `index_` has already been |
| 732 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 733 | // (as it is not a callee-save register), so we can freely |
| 734 | // use it. |
| 735 | } |
| 736 | // Shifting the index value contained in `index_reg` by the scale |
| 737 | // factor (2) cannot overflow in practice, as the runtime is |
| 738 | // unable to allocate object arrays with a size larger than |
| 739 | // 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 740 | __ Lsl(index_reg, index_reg, Primitive::ComponentSizeShift(type)); |
| 741 | static_assert( |
| 742 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 743 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 744 | __ Add(index_reg, index_reg, Operand(offset_)); |
| 745 | } else { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 746 | // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile |
| 747 | // intrinsics, `index_` is not shifted by a scale factor of 2 |
| 748 | // (as in the case of ArrayGet), as it is actually an offset |
| 749 | // to an object field within an object. |
| 750 | DCHECK(instruction_->IsInvoke()) << instruction_->DebugName(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 751 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 752 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 753 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 754 | << instruction_->AsInvoke()->GetIntrinsic(); |
| 755 | DCHECK_EQ(offset_, 0U); |
Roland Levillain | a7426c6 | 2016-08-03 15:02:10 +0100 | [diff] [blame] | 756 | DCHECK(index_.IsRegister()); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 757 | } |
| 758 | } |
| 759 | |
| 760 | // We're moving two or three locations to locations that could |
| 761 | // overlap, so we need a parallel move resolver. |
| 762 | InvokeRuntimeCallingConvention calling_convention; |
| 763 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 764 | parallel_move.AddMove(ref_, |
| 765 | LocationFrom(calling_convention.GetRegisterAt(0)), |
| 766 | type, |
| 767 | nullptr); |
| 768 | parallel_move.AddMove(obj_, |
| 769 | LocationFrom(calling_convention.GetRegisterAt(1)), |
| 770 | type, |
| 771 | nullptr); |
| 772 | if (index.IsValid()) { |
| 773 | parallel_move.AddMove(index, |
| 774 | LocationFrom(calling_convention.GetRegisterAt(2)), |
| 775 | Primitive::kPrimInt, |
| 776 | nullptr); |
| 777 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 778 | } else { |
| 779 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 780 | arm64_codegen->MoveConstant(LocationFrom(calling_convention.GetRegisterAt(2)), offset_); |
| 781 | } |
| 782 | arm64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pReadBarrierSlow), |
| 783 | instruction_, |
| 784 | instruction_->GetDexPc(), |
| 785 | this); |
| 786 | CheckEntrypointTypes< |
| 787 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 788 | arm64_codegen->MoveLocation(out_, calling_convention.GetReturnLocation(type), type); |
| 789 | |
| 790 | RestoreLiveRegisters(codegen, locations); |
| 791 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 792 | __ B(GetExitLabel()); |
| 793 | } |
| 794 | |
| 795 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForHeapReferenceSlowPathARM64"; } |
| 796 | |
| 797 | private: |
| 798 | Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 799 | size_t ref = static_cast<int>(XRegisterFrom(ref_).GetCode()); |
| 800 | size_t obj = static_cast<int>(XRegisterFrom(obj_).GetCode()); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 801 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 802 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 803 | return Register(VIXLRegCodeFromART(i), kXRegSize); |
| 804 | } |
| 805 | } |
| 806 | // We shall never fail to find a free caller-save register, as |
| 807 | // there are more than two core caller-save registers on ARM64 |
| 808 | // (meaning it is possible to find one which is different from |
| 809 | // `ref` and `obj`). |
| 810 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 811 | LOG(FATAL) << "Could not find a free register"; |
| 812 | UNREACHABLE(); |
| 813 | } |
| 814 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 815 | const Location out_; |
| 816 | const Location ref_; |
| 817 | const Location obj_; |
| 818 | const uint32_t offset_; |
| 819 | // An additional location containing an index to an array. |
| 820 | // Only used for HArrayGet and the UnsafeGetObject & |
| 821 | // UnsafeGetObjectVolatile intrinsics. |
| 822 | const Location index_; |
| 823 | |
| 824 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathARM64); |
| 825 | }; |
| 826 | |
| 827 | // Slow path generating a read barrier for a GC root. |
| 828 | class ReadBarrierForRootSlowPathARM64 : public SlowPathCodeARM64 { |
| 829 | public: |
| 830 | ReadBarrierForRootSlowPathARM64(HInstruction* instruction, Location out, Location root) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 831 | : SlowPathCodeARM64(instruction), out_(out), root_(root) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 832 | DCHECK(kEmitCompilerReadBarrier); |
| 833 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 834 | |
| 835 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 836 | LocationSummary* locations = instruction_->GetLocations(); |
| 837 | Primitive::Type type = Primitive::kPrimNot; |
| 838 | DCHECK(locations->CanCall()); |
| 839 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(out_.reg())); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 840 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 841 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 842 | << instruction_->DebugName(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 843 | |
| 844 | __ Bind(GetEntryLabel()); |
| 845 | SaveLiveRegisters(codegen, locations); |
| 846 | |
| 847 | InvokeRuntimeCallingConvention calling_convention; |
| 848 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 849 | // The argument of the ReadBarrierForRootSlow is not a managed |
| 850 | // reference (`mirror::Object*`), but a `GcRoot<mirror::Object>*`; |
| 851 | // thus we need a 64-bit move here, and we cannot use |
| 852 | // |
| 853 | // arm64_codegen->MoveLocation( |
| 854 | // LocationFrom(calling_convention.GetRegisterAt(0)), |
| 855 | // root_, |
| 856 | // type); |
| 857 | // |
| 858 | // which would emit a 32-bit move, as `type` is a (32-bit wide) |
| 859 | // reference type (`Primitive::kPrimNot`). |
| 860 | __ Mov(calling_convention.GetRegisterAt(0), XRegisterFrom(out_)); |
| 861 | arm64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pReadBarrierForRootSlow), |
| 862 | instruction_, |
| 863 | instruction_->GetDexPc(), |
| 864 | this); |
| 865 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 866 | arm64_codegen->MoveLocation(out_, calling_convention.GetReturnLocation(type), type); |
| 867 | |
| 868 | RestoreLiveRegisters(codegen, locations); |
| 869 | __ B(GetExitLabel()); |
| 870 | } |
| 871 | |
| 872 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathARM64"; } |
| 873 | |
| 874 | private: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 875 | const Location out_; |
| 876 | const Location root_; |
| 877 | |
| 878 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathARM64); |
| 879 | }; |
| 880 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 881 | #undef __ |
| 882 | |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 883 | Location InvokeDexCallingConventionVisitorARM64::GetNextLocation(Primitive::Type type) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 884 | Location next_location; |
| 885 | if (type == Primitive::kPrimVoid) { |
| 886 | LOG(FATAL) << "Unreachable type " << type; |
| 887 | } |
| 888 | |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 889 | if (Primitive::IsFloatingPointType(type) && |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 890 | (float_index_ < calling_convention.GetNumberOfFpuRegisters())) { |
| 891 | next_location = LocationFrom(calling_convention.GetFpuRegisterAt(float_index_++)); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 892 | } else if (!Primitive::IsFloatingPointType(type) && |
| 893 | (gp_index_ < calling_convention.GetNumberOfRegisters())) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 894 | next_location = LocationFrom(calling_convention.GetRegisterAt(gp_index_++)); |
| 895 | } else { |
| 896 | size_t stack_offset = calling_convention.GetStackOffsetOf(stack_index_); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 897 | next_location = Primitive::Is64BitType(type) ? Location::DoubleStackSlot(stack_offset) |
| 898 | : Location::StackSlot(stack_offset); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 899 | } |
| 900 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 901 | // Space on the stack is reserved for all arguments. |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 902 | stack_index_ += Primitive::Is64BitType(type) ? 2 : 1; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 903 | return next_location; |
| 904 | } |
| 905 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 906 | Location InvokeDexCallingConventionVisitorARM64::GetMethodLocation() const { |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 907 | return LocationFrom(kArtMethodRegister); |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 908 | } |
| 909 | |
Serban Constantinescu | 579885a | 2015-02-22 20:51:33 +0000 | [diff] [blame] | 910 | CodeGeneratorARM64::CodeGeneratorARM64(HGraph* graph, |
| 911 | const Arm64InstructionSetFeatures& isa_features, |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 912 | const CompilerOptions& compiler_options, |
| 913 | OptimizingCompilerStats* stats) |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 914 | : CodeGenerator(graph, |
| 915 | kNumberOfAllocatableRegisters, |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 916 | kNumberOfAllocatableFPRegisters, |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 917 | kNumberOfAllocatableRegisterPairs, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 918 | callee_saved_core_registers.GetList(), |
| 919 | callee_saved_fp_registers.GetList(), |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 920 | compiler_options, |
| 921 | stats), |
Alexandre Rames | c01a664 | 2016-04-15 11:54:06 +0100 | [diff] [blame] | 922 | block_labels_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 923 | jump_tables_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 924 | location_builder_(graph, this), |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 925 | instruction_visitor_(graph, this), |
Serban Constantinescu | 579885a | 2015-02-22 20:51:33 +0000 | [diff] [blame] | 926 | move_resolver_(graph->GetArena(), this), |
Vladimir Marko | 93205e3 | 2016-04-13 11:59:46 +0100 | [diff] [blame] | 927 | assembler_(graph->GetArena()), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 928 | isa_features_(isa_features), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 929 | uint32_literals_(std::less<uint32_t>(), |
| 930 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 931 | uint64_literals_(std::less<uint64_t>(), |
| 932 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 933 | method_patches_(MethodReferenceComparator(), |
| 934 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 935 | call_patches_(MethodReferenceComparator(), |
| 936 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 937 | relative_call_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 938 | pc_relative_dex_cache_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 939 | boot_image_string_patches_(StringReferenceValueComparator(), |
| 940 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 941 | pc_relative_string_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 942 | boot_image_type_patches_(TypeReferenceValueComparator(), |
| 943 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 944 | pc_relative_type_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 945 | boot_image_address_patches_(std::less<uint32_t>(), |
| 946 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 947 | // Save the link register (containing the return address) to mimic Quick. |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 948 | AddAllocatedRegister(LocationFrom(lr)); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 949 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 950 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 951 | #define __ GetVIXLAssembler()-> |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 952 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 953 | void CodeGeneratorARM64::EmitJumpTables() { |
Alexandre Rames | c01a664 | 2016-04-15 11:54:06 +0100 | [diff] [blame] | 954 | for (auto&& jump_table : jump_tables_) { |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 955 | jump_table->EmitTable(this); |
| 956 | } |
| 957 | } |
| 958 | |
Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 959 | void CodeGeneratorARM64::Finalize(CodeAllocator* allocator) { |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 960 | EmitJumpTables(); |
Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 961 | // Ensure we emit the literal pool. |
| 962 | __ FinalizeCode(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 963 | |
Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 964 | CodeGenerator::Finalize(allocator); |
| 965 | } |
| 966 | |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 967 | void ParallelMoveResolverARM64::PrepareForEmitNativeCode() { |
| 968 | // Note: There are 6 kinds of moves: |
| 969 | // 1. constant -> GPR/FPR (non-cycle) |
| 970 | // 2. constant -> stack (non-cycle) |
| 971 | // 3. GPR/FPR -> GPR/FPR |
| 972 | // 4. GPR/FPR -> stack |
| 973 | // 5. stack -> GPR/FPR |
| 974 | // 6. stack -> stack (non-cycle) |
| 975 | // Case 1, 2 and 6 should never be included in a dependency cycle on ARM64. For case 3, 4, and 5 |
| 976 | // VIXL uses at most 1 GPR. VIXL has 2 GPR and 1 FPR temps, and there should be no intersecting |
| 977 | // cycles on ARM64, so we always have 1 GPR and 1 FPR available VIXL temps to resolve the |
| 978 | // dependency. |
| 979 | vixl_temps_.Open(GetVIXLAssembler()); |
| 980 | } |
| 981 | |
| 982 | void ParallelMoveResolverARM64::FinishEmitNativeCode() { |
| 983 | vixl_temps_.Close(); |
| 984 | } |
| 985 | |
| 986 | Location ParallelMoveResolverARM64::AllocateScratchLocationFor(Location::Kind kind) { |
| 987 | DCHECK(kind == Location::kRegister || kind == Location::kFpuRegister || |
| 988 | kind == Location::kStackSlot || kind == Location::kDoubleStackSlot); |
| 989 | kind = (kind == Location::kFpuRegister) ? Location::kFpuRegister : Location::kRegister; |
| 990 | Location scratch = GetScratchLocation(kind); |
| 991 | if (!scratch.Equals(Location::NoLocation())) { |
| 992 | return scratch; |
| 993 | } |
| 994 | // Allocate from VIXL temp registers. |
| 995 | if (kind == Location::kRegister) { |
| 996 | scratch = LocationFrom(vixl_temps_.AcquireX()); |
| 997 | } else { |
| 998 | DCHECK(kind == Location::kFpuRegister); |
| 999 | scratch = LocationFrom(vixl_temps_.AcquireD()); |
| 1000 | } |
| 1001 | AddScratchLocation(scratch); |
| 1002 | return scratch; |
| 1003 | } |
| 1004 | |
| 1005 | void ParallelMoveResolverARM64::FreeScratchLocation(Location loc) { |
| 1006 | if (loc.IsRegister()) { |
| 1007 | vixl_temps_.Release(XRegisterFrom(loc)); |
| 1008 | } else { |
| 1009 | DCHECK(loc.IsFpuRegister()); |
| 1010 | vixl_temps_.Release(DRegisterFrom(loc)); |
| 1011 | } |
| 1012 | RemoveScratchLocation(loc); |
| 1013 | } |
| 1014 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1015 | void ParallelMoveResolverARM64::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 1016 | MoveOperands* move = moves_[index]; |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1017 | codegen_->MoveLocation(move->GetDestination(), move->GetSource(), Primitive::kPrimVoid); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1018 | } |
| 1019 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1020 | void CodeGeneratorARM64::GenerateFrameEntry() { |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1021 | MacroAssembler* masm = GetVIXLAssembler(); |
| 1022 | BlockPoolsScope block_pools(masm); |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1023 | __ Bind(&frame_entry_label_); |
| 1024 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1025 | bool do_overflow_check = FrameNeedsStackCheck(GetFrameSize(), kArm64) || !IsLeafMethod(); |
| 1026 | if (do_overflow_check) { |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1027 | UseScratchRegisterScope temps(masm); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1028 | Register temp = temps.AcquireX(); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1029 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1030 | __ Sub(temp, sp, static_cast<int32_t>(GetStackOverflowReservedBytes(kArm64))); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1031 | __ Ldr(wzr, MemOperand(temp, 0)); |
| 1032 | RecordPcInfo(nullptr, 0); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1033 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1034 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1035 | if (!HasEmptyFrame()) { |
| 1036 | int frame_size = GetFrameSize(); |
| 1037 | // Stack layout: |
| 1038 | // sp[frame_size - 8] : lr. |
| 1039 | // ... : other preserved core registers. |
| 1040 | // ... : other preserved fp registers. |
| 1041 | // ... : reserved frame space. |
| 1042 | // sp[0] : current method. |
| 1043 | __ Str(kArtMethodRegister, MemOperand(sp, -frame_size, PreIndex)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1044 | GetAssembler()->cfi().AdjustCFAOffset(frame_size); |
Zheng Xu | 69a5030 | 2015-04-14 20:04:41 +0800 | [diff] [blame] | 1045 | GetAssembler()->SpillRegisters(GetFramePreservedCoreRegisters(), |
| 1046 | frame_size - GetCoreSpillSize()); |
| 1047 | GetAssembler()->SpillRegisters(GetFramePreservedFPRegisters(), |
| 1048 | frame_size - FrameEntrySpillSize()); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1049 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1050 | } |
| 1051 | |
| 1052 | void CodeGeneratorARM64::GenerateFrameExit() { |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1053 | BlockPoolsScope block_pools(GetVIXLAssembler()); |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1054 | GetAssembler()->cfi().RememberState(); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1055 | if (!HasEmptyFrame()) { |
| 1056 | int frame_size = GetFrameSize(); |
Zheng Xu | 69a5030 | 2015-04-14 20:04:41 +0800 | [diff] [blame] | 1057 | GetAssembler()->UnspillRegisters(GetFramePreservedFPRegisters(), |
| 1058 | frame_size - FrameEntrySpillSize()); |
| 1059 | GetAssembler()->UnspillRegisters(GetFramePreservedCoreRegisters(), |
| 1060 | frame_size - GetCoreSpillSize()); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1061 | __ Drop(frame_size); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1062 | GetAssembler()->cfi().AdjustCFAOffset(-frame_size); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1063 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1064 | __ Ret(); |
| 1065 | GetAssembler()->cfi().RestoreState(); |
| 1066 | GetAssembler()->cfi().DefCFAOffset(GetFrameSize()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1067 | } |
| 1068 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1069 | CPURegList CodeGeneratorARM64::GetFramePreservedCoreRegisters() const { |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1070 | DCHECK(ArtVixlRegCodeCoherentForRegSet(core_spill_mask_, GetNumberOfCoreRegisters(), 0, 0)); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1071 | return CPURegList(CPURegister::kRegister, kXRegSize, |
| 1072 | core_spill_mask_); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1073 | } |
| 1074 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1075 | CPURegList CodeGeneratorARM64::GetFramePreservedFPRegisters() const { |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1076 | DCHECK(ArtVixlRegCodeCoherentForRegSet(0, 0, fpu_spill_mask_, |
| 1077 | GetNumberOfFloatingPointRegisters())); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1078 | return CPURegList(CPURegister::kFPRegister, kDRegSize, |
| 1079 | fpu_spill_mask_); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1080 | } |
| 1081 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1082 | void CodeGeneratorARM64::Bind(HBasicBlock* block) { |
| 1083 | __ Bind(GetLabelOf(block)); |
| 1084 | } |
| 1085 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1086 | void CodeGeneratorARM64::MoveConstant(Location location, int32_t value) { |
| 1087 | DCHECK(location.IsRegister()); |
| 1088 | __ Mov(RegisterFrom(location, Primitive::kPrimInt), value); |
| 1089 | } |
| 1090 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1091 | void CodeGeneratorARM64::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1092 | if (location.IsRegister()) { |
| 1093 | locations->AddTemp(location); |
| 1094 | } else { |
| 1095 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1096 | } |
| 1097 | } |
| 1098 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1099 | void CodeGeneratorARM64::MarkGCCard(Register object, Register value, bool value_can_be_null) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1100 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1101 | Register card = temps.AcquireX(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1102 | Register temp = temps.AcquireW(); // Index within the CardTable - 32bit. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1103 | vixl::aarch64::Label done; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1104 | if (value_can_be_null) { |
| 1105 | __ Cbz(value, &done); |
| 1106 | } |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1107 | __ Ldr(card, MemOperand(tr, Thread::CardTableOffset<kArm64PointerSize>().Int32Value())); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1108 | __ Lsr(temp, object, gc::accounting::CardTable::kCardShift); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1109 | __ Strb(card, MemOperand(card, temp.X())); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1110 | if (value_can_be_null) { |
| 1111 | __ Bind(&done); |
| 1112 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1113 | } |
| 1114 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1115 | void CodeGeneratorARM64::SetupBlockedRegisters() const { |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1116 | // Blocked core registers: |
| 1117 | // lr : Runtime reserved. |
| 1118 | // tr : Runtime reserved. |
| 1119 | // xSuspend : Runtime reserved. TODO: Unblock this when the runtime stops using it. |
| 1120 | // ip1 : VIXL core temp. |
| 1121 | // ip0 : VIXL core temp. |
| 1122 | // |
| 1123 | // Blocked fp registers: |
| 1124 | // d31 : VIXL fp temp. |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1125 | CPURegList reserved_core_registers = vixl_reserved_core_registers; |
| 1126 | reserved_core_registers.Combine(runtime_reserved_core_registers); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1127 | while (!reserved_core_registers.IsEmpty()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1128 | blocked_core_registers_[reserved_core_registers.PopLowestIndex().GetCode()] = true; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1129 | } |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1130 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1131 | CPURegList reserved_fp_registers = vixl_reserved_fp_registers; |
Zheng Xu | a3ec394 | 2015-02-15 18:39:46 +0800 | [diff] [blame] | 1132 | while (!reserved_fp_registers.IsEmpty()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1133 | blocked_fpu_registers_[reserved_fp_registers.PopLowestIndex().GetCode()] = true; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1134 | } |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1135 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1136 | if (GetGraph()->IsDebuggable()) { |
Nicolas Geoffray | ecf680d | 2015-10-05 11:15:37 +0100 | [diff] [blame] | 1137 | // Stubs do not save callee-save floating point registers. If the graph |
| 1138 | // is debuggable, we need to deal with these registers differently. For |
| 1139 | // now, just block them. |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1140 | CPURegList reserved_fp_registers_debuggable = callee_saved_fp_registers; |
| 1141 | while (!reserved_fp_registers_debuggable.IsEmpty()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1142 | blocked_fpu_registers_[reserved_fp_registers_debuggable.PopLowestIndex().GetCode()] = true; |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1143 | } |
| 1144 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1145 | } |
| 1146 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1147 | size_t CodeGeneratorARM64::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1148 | Register reg = Register(VIXLRegCodeFromART(reg_id), kXRegSize); |
| 1149 | __ Str(reg, MemOperand(sp, stack_index)); |
| 1150 | return kArm64WordSize; |
| 1151 | } |
| 1152 | |
| 1153 | size_t CodeGeneratorARM64::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1154 | Register reg = Register(VIXLRegCodeFromART(reg_id), kXRegSize); |
| 1155 | __ Ldr(reg, MemOperand(sp, stack_index)); |
| 1156 | return kArm64WordSize; |
| 1157 | } |
| 1158 | |
| 1159 | size_t CodeGeneratorARM64::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 1160 | FPRegister reg = FPRegister(reg_id, kDRegSize); |
| 1161 | __ Str(reg, MemOperand(sp, stack_index)); |
| 1162 | return kArm64WordSize; |
| 1163 | } |
| 1164 | |
| 1165 | size_t CodeGeneratorARM64::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 1166 | FPRegister reg = FPRegister(reg_id, kDRegSize); |
| 1167 | __ Ldr(reg, MemOperand(sp, stack_index)); |
| 1168 | return kArm64WordSize; |
| 1169 | } |
| 1170 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1171 | void CodeGeneratorARM64::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1172 | stream << XRegister(reg); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1173 | } |
| 1174 | |
| 1175 | void CodeGeneratorARM64::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1176 | stream << DRegister(reg); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1177 | } |
| 1178 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1179 | void CodeGeneratorARM64::MoveConstant(CPURegister destination, HConstant* constant) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1180 | if (constant->IsIntConstant()) { |
| 1181 | __ Mov(Register(destination), constant->AsIntConstant()->GetValue()); |
| 1182 | } else if (constant->IsLongConstant()) { |
| 1183 | __ Mov(Register(destination), constant->AsLongConstant()->GetValue()); |
| 1184 | } else if (constant->IsNullConstant()) { |
| 1185 | __ Mov(Register(destination), 0); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1186 | } else if (constant->IsFloatConstant()) { |
| 1187 | __ Fmov(FPRegister(destination), constant->AsFloatConstant()->GetValue()); |
| 1188 | } else { |
| 1189 | DCHECK(constant->IsDoubleConstant()); |
| 1190 | __ Fmov(FPRegister(destination), constant->AsDoubleConstant()->GetValue()); |
| 1191 | } |
| 1192 | } |
| 1193 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1194 | |
| 1195 | static bool CoherentConstantAndType(Location constant, Primitive::Type type) { |
| 1196 | DCHECK(constant.IsConstant()); |
| 1197 | HConstant* cst = constant.GetConstant(); |
| 1198 | return (cst->IsIntConstant() && type == Primitive::kPrimInt) || |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1199 | // Null is mapped to a core W register, which we associate with kPrimInt. |
| 1200 | (cst->IsNullConstant() && type == Primitive::kPrimInt) || |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1201 | (cst->IsLongConstant() && type == Primitive::kPrimLong) || |
| 1202 | (cst->IsFloatConstant() && type == Primitive::kPrimFloat) || |
| 1203 | (cst->IsDoubleConstant() && type == Primitive::kPrimDouble); |
| 1204 | } |
| 1205 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1206 | void CodeGeneratorARM64::MoveLocation(Location destination, |
| 1207 | Location source, |
| 1208 | Primitive::Type dst_type) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1209 | if (source.Equals(destination)) { |
| 1210 | return; |
| 1211 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1212 | |
| 1213 | // A valid move can always be inferred from the destination and source |
| 1214 | // locations. When moving from and to a register, the argument type can be |
| 1215 | // used to generate 32bit instead of 64bit moves. In debug mode we also |
| 1216 | // checks the coherency of the locations and the type. |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1217 | bool unspecified_type = (dst_type == Primitive::kPrimVoid); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1218 | |
| 1219 | if (destination.IsRegister() || destination.IsFpuRegister()) { |
| 1220 | if (unspecified_type) { |
| 1221 | HConstant* src_cst = source.IsConstant() ? source.GetConstant() : nullptr; |
| 1222 | if (source.IsStackSlot() || |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1223 | (src_cst != nullptr && (src_cst->IsIntConstant() |
| 1224 | || src_cst->IsFloatConstant() |
| 1225 | || src_cst->IsNullConstant()))) { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1226 | // For stack slots and 32bit constants, a 64bit type is appropriate. |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1227 | dst_type = destination.IsRegister() ? Primitive::kPrimInt : Primitive::kPrimFloat; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1228 | } else { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1229 | // If the source is a double stack slot or a 64bit constant, a 64bit |
| 1230 | // type is appropriate. Else the source is a register, and since the |
| 1231 | // type has not been specified, we chose a 64bit type to force a 64bit |
| 1232 | // move. |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1233 | dst_type = destination.IsRegister() ? Primitive::kPrimLong : Primitive::kPrimDouble; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1234 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1235 | } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1236 | DCHECK((destination.IsFpuRegister() && Primitive::IsFloatingPointType(dst_type)) || |
| 1237 | (destination.IsRegister() && !Primitive::IsFloatingPointType(dst_type))); |
| 1238 | CPURegister dst = CPURegisterFrom(destination, dst_type); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1239 | if (source.IsStackSlot() || source.IsDoubleStackSlot()) { |
| 1240 | DCHECK(dst.Is64Bits() == source.IsDoubleStackSlot()); |
| 1241 | __ Ldr(dst, StackOperandFrom(source)); |
| 1242 | } else if (source.IsConstant()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1243 | DCHECK(CoherentConstantAndType(source, dst_type)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1244 | MoveConstant(dst, source.GetConstant()); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1245 | } else if (source.IsRegister()) { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1246 | if (destination.IsRegister()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1247 | __ Mov(Register(dst), RegisterFrom(source, dst_type)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1248 | } else { |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1249 | DCHECK(destination.IsFpuRegister()); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1250 | Primitive::Type source_type = Primitive::Is64BitType(dst_type) |
| 1251 | ? Primitive::kPrimLong |
| 1252 | : Primitive::kPrimInt; |
| 1253 | __ Fmov(FPRegisterFrom(destination, dst_type), RegisterFrom(source, source_type)); |
| 1254 | } |
| 1255 | } else { |
| 1256 | DCHECK(source.IsFpuRegister()); |
| 1257 | if (destination.IsRegister()) { |
| 1258 | Primitive::Type source_type = Primitive::Is64BitType(dst_type) |
| 1259 | ? Primitive::kPrimDouble |
| 1260 | : Primitive::kPrimFloat; |
| 1261 | __ Fmov(RegisterFrom(destination, dst_type), FPRegisterFrom(source, source_type)); |
| 1262 | } else { |
| 1263 | DCHECK(destination.IsFpuRegister()); |
| 1264 | __ Fmov(FPRegister(dst), FPRegisterFrom(source, dst_type)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1265 | } |
| 1266 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1267 | } else { // The destination is not a register. It must be a stack slot. |
| 1268 | DCHECK(destination.IsStackSlot() || destination.IsDoubleStackSlot()); |
| 1269 | if (source.IsRegister() || source.IsFpuRegister()) { |
| 1270 | if (unspecified_type) { |
| 1271 | if (source.IsRegister()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1272 | dst_type = destination.IsStackSlot() ? Primitive::kPrimInt : Primitive::kPrimLong; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1273 | } else { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1274 | dst_type = destination.IsStackSlot() ? Primitive::kPrimFloat : Primitive::kPrimDouble; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1275 | } |
| 1276 | } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1277 | DCHECK((destination.IsDoubleStackSlot() == Primitive::Is64BitType(dst_type)) && |
| 1278 | (source.IsFpuRegister() == Primitive::IsFloatingPointType(dst_type))); |
| 1279 | __ Str(CPURegisterFrom(source, dst_type), StackOperandFrom(destination)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1280 | } else if (source.IsConstant()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1281 | DCHECK(unspecified_type || CoherentConstantAndType(source, dst_type)) |
| 1282 | << source << " " << dst_type; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1283 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 1284 | HConstant* src_cst = source.GetConstant(); |
| 1285 | CPURegister temp; |
Alexandre Rames | b2b753c | 2016-08-02 13:45:28 +0100 | [diff] [blame] | 1286 | if (src_cst->IsZeroBitPattern()) { |
| 1287 | temp = (src_cst->IsLongConstant() || src_cst->IsDoubleConstant()) ? xzr : wzr; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1288 | } else { |
Alexandre Rames | b2b753c | 2016-08-02 13:45:28 +0100 | [diff] [blame] | 1289 | if (src_cst->IsIntConstant()) { |
| 1290 | temp = temps.AcquireW(); |
| 1291 | } else if (src_cst->IsLongConstant()) { |
| 1292 | temp = temps.AcquireX(); |
| 1293 | } else if (src_cst->IsFloatConstant()) { |
| 1294 | temp = temps.AcquireS(); |
| 1295 | } else { |
| 1296 | DCHECK(src_cst->IsDoubleConstant()); |
| 1297 | temp = temps.AcquireD(); |
| 1298 | } |
| 1299 | MoveConstant(temp, src_cst); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1300 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1301 | __ Str(temp, StackOperandFrom(destination)); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1302 | } else { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1303 | DCHECK(source.IsStackSlot() || source.IsDoubleStackSlot()); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1304 | DCHECK(source.IsDoubleStackSlot() == destination.IsDoubleStackSlot()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1305 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1306 | // There is generally less pressure on FP registers. |
| 1307 | FPRegister temp = destination.IsDoubleStackSlot() ? temps.AcquireD() : temps.AcquireS(); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1308 | __ Ldr(temp, StackOperandFrom(source)); |
| 1309 | __ Str(temp, StackOperandFrom(destination)); |
| 1310 | } |
| 1311 | } |
| 1312 | } |
| 1313 | |
| 1314 | void CodeGeneratorARM64::Load(Primitive::Type type, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1315 | CPURegister dst, |
| 1316 | const MemOperand& src) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1317 | switch (type) { |
| 1318 | case Primitive::kPrimBoolean: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1319 | __ Ldrb(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1320 | break; |
| 1321 | case Primitive::kPrimByte: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1322 | __ Ldrsb(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1323 | break; |
| 1324 | case Primitive::kPrimShort: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1325 | __ Ldrsh(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1326 | break; |
| 1327 | case Primitive::kPrimChar: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1328 | __ Ldrh(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1329 | break; |
| 1330 | case Primitive::kPrimInt: |
| 1331 | case Primitive::kPrimNot: |
| 1332 | case Primitive::kPrimLong: |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1333 | case Primitive::kPrimFloat: |
| 1334 | case Primitive::kPrimDouble: |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 1335 | DCHECK_EQ(dst.Is64Bits(), Primitive::Is64BitType(type)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1336 | __ Ldr(dst, src); |
| 1337 | break; |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1338 | case Primitive::kPrimVoid: |
| 1339 | LOG(FATAL) << "Unreachable type " << type; |
| 1340 | } |
| 1341 | } |
| 1342 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1343 | void CodeGeneratorARM64::LoadAcquire(HInstruction* instruction, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1344 | CPURegister dst, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1345 | const MemOperand& src, |
| 1346 | bool needs_null_check) { |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1347 | MacroAssembler* masm = GetVIXLAssembler(); |
| 1348 | BlockPoolsScope block_pools(masm); |
| 1349 | UseScratchRegisterScope temps(masm); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1350 | Register temp_base = temps.AcquireX(); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1351 | Primitive::Type type = instruction->GetType(); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1352 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1353 | DCHECK(!src.IsPreIndex()); |
| 1354 | DCHECK(!src.IsPostIndex()); |
| 1355 | |
| 1356 | // TODO(vixl): Let the MacroAssembler handle MemOperand. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1357 | __ Add(temp_base, src.GetBaseRegister(), OperandFromMemOperand(src)); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1358 | MemOperand base = MemOperand(temp_base); |
| 1359 | switch (type) { |
| 1360 | case Primitive::kPrimBoolean: |
| 1361 | __ Ldarb(Register(dst), base); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1362 | if (needs_null_check) { |
| 1363 | MaybeRecordImplicitNullCheck(instruction); |
| 1364 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1365 | break; |
| 1366 | case Primitive::kPrimByte: |
| 1367 | __ Ldarb(Register(dst), base); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1368 | if (needs_null_check) { |
| 1369 | MaybeRecordImplicitNullCheck(instruction); |
| 1370 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1371 | __ Sbfx(Register(dst), Register(dst), 0, Primitive::ComponentSize(type) * kBitsPerByte); |
| 1372 | break; |
| 1373 | case Primitive::kPrimChar: |
| 1374 | __ Ldarh(Register(dst), base); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1375 | if (needs_null_check) { |
| 1376 | MaybeRecordImplicitNullCheck(instruction); |
| 1377 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1378 | break; |
| 1379 | case Primitive::kPrimShort: |
| 1380 | __ Ldarh(Register(dst), base); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1381 | if (needs_null_check) { |
| 1382 | MaybeRecordImplicitNullCheck(instruction); |
| 1383 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1384 | __ Sbfx(Register(dst), Register(dst), 0, Primitive::ComponentSize(type) * kBitsPerByte); |
| 1385 | break; |
| 1386 | case Primitive::kPrimInt: |
| 1387 | case Primitive::kPrimNot: |
| 1388 | case Primitive::kPrimLong: |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 1389 | DCHECK_EQ(dst.Is64Bits(), Primitive::Is64BitType(type)); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1390 | __ Ldar(Register(dst), base); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1391 | if (needs_null_check) { |
| 1392 | MaybeRecordImplicitNullCheck(instruction); |
| 1393 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1394 | break; |
| 1395 | case Primitive::kPrimFloat: |
| 1396 | case Primitive::kPrimDouble: { |
| 1397 | DCHECK(dst.IsFPRegister()); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 1398 | DCHECK_EQ(dst.Is64Bits(), Primitive::Is64BitType(type)); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1399 | |
| 1400 | Register temp = dst.Is64Bits() ? temps.AcquireX() : temps.AcquireW(); |
| 1401 | __ Ldar(temp, base); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1402 | if (needs_null_check) { |
| 1403 | MaybeRecordImplicitNullCheck(instruction); |
| 1404 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1405 | __ Fmov(FPRegister(dst), temp); |
| 1406 | break; |
| 1407 | } |
| 1408 | case Primitive::kPrimVoid: |
| 1409 | LOG(FATAL) << "Unreachable type " << type; |
| 1410 | } |
| 1411 | } |
| 1412 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1413 | void CodeGeneratorARM64::Store(Primitive::Type type, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1414 | CPURegister src, |
| 1415 | const MemOperand& dst) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1416 | switch (type) { |
| 1417 | case Primitive::kPrimBoolean: |
| 1418 | case Primitive::kPrimByte: |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1419 | __ Strb(Register(src), dst); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1420 | break; |
| 1421 | case Primitive::kPrimChar: |
| 1422 | case Primitive::kPrimShort: |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1423 | __ Strh(Register(src), dst); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1424 | break; |
| 1425 | case Primitive::kPrimInt: |
| 1426 | case Primitive::kPrimNot: |
| 1427 | case Primitive::kPrimLong: |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1428 | case Primitive::kPrimFloat: |
| 1429 | case Primitive::kPrimDouble: |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 1430 | DCHECK_EQ(src.Is64Bits(), Primitive::Is64BitType(type)); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1431 | __ Str(src, dst); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1432 | break; |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1433 | case Primitive::kPrimVoid: |
| 1434 | LOG(FATAL) << "Unreachable type " << type; |
| 1435 | } |
| 1436 | } |
| 1437 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1438 | void CodeGeneratorARM64::StoreRelease(Primitive::Type type, |
| 1439 | CPURegister src, |
| 1440 | const MemOperand& dst) { |
| 1441 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 1442 | Register temp_base = temps.AcquireX(); |
| 1443 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1444 | DCHECK(!dst.IsPreIndex()); |
| 1445 | DCHECK(!dst.IsPostIndex()); |
| 1446 | |
| 1447 | // TODO(vixl): Let the MacroAssembler handle this. |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 1448 | Operand op = OperandFromMemOperand(dst); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1449 | __ Add(temp_base, dst.GetBaseRegister(), op); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1450 | MemOperand base = MemOperand(temp_base); |
| 1451 | switch (type) { |
| 1452 | case Primitive::kPrimBoolean: |
| 1453 | case Primitive::kPrimByte: |
| 1454 | __ Stlrb(Register(src), base); |
| 1455 | break; |
| 1456 | case Primitive::kPrimChar: |
| 1457 | case Primitive::kPrimShort: |
| 1458 | __ Stlrh(Register(src), base); |
| 1459 | break; |
| 1460 | case Primitive::kPrimInt: |
| 1461 | case Primitive::kPrimNot: |
| 1462 | case Primitive::kPrimLong: |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 1463 | DCHECK_EQ(src.Is64Bits(), Primitive::Is64BitType(type)); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1464 | __ Stlr(Register(src), base); |
| 1465 | break; |
| 1466 | case Primitive::kPrimFloat: |
| 1467 | case Primitive::kPrimDouble: { |
| 1468 | DCHECK(src.IsFPRegister()); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 1469 | DCHECK_EQ(src.Is64Bits(), Primitive::Is64BitType(type)); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1470 | |
| 1471 | Register temp = src.Is64Bits() ? temps.AcquireX() : temps.AcquireW(); |
| 1472 | __ Fmov(temp, FPRegister(src)); |
| 1473 | __ Stlr(temp, base); |
| 1474 | break; |
| 1475 | } |
| 1476 | case Primitive::kPrimVoid: |
| 1477 | LOG(FATAL) << "Unreachable type " << type; |
| 1478 | } |
| 1479 | } |
| 1480 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1481 | void CodeGeneratorARM64::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 1482 | HInstruction* instruction, |
| 1483 | uint32_t dex_pc, |
| 1484 | SlowPathCode* slow_path) { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1485 | InvokeRuntime(GetThreadOffset<kArm64PointerSize>(entrypoint).Int32Value(), |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1486 | instruction, |
| 1487 | dex_pc, |
| 1488 | slow_path); |
| 1489 | } |
| 1490 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1491 | void CodeGeneratorARM64::InvokeRuntime(int32_t entry_point_offset, |
| 1492 | HInstruction* instruction, |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 1493 | uint32_t dex_pc, |
| 1494 | SlowPathCode* slow_path) { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1495 | ValidateInvokeRuntime(instruction, slow_path); |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1496 | BlockPoolsScope block_pools(GetVIXLAssembler()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1497 | __ Ldr(lr, MemOperand(tr, entry_point_offset)); |
| 1498 | __ Blr(lr); |
Roland Levillain | 896e32d | 2015-05-05 18:07:10 +0100 | [diff] [blame] | 1499 | RecordPcInfo(instruction, dex_pc, slow_path); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1500 | } |
| 1501 | |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 1502 | void CodeGeneratorARM64::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 1503 | HInstruction* instruction, |
| 1504 | SlowPathCode* slow_path) { |
| 1505 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
| 1506 | BlockPoolsScope block_pools(GetVIXLAssembler()); |
| 1507 | __ Ldr(lr, MemOperand(tr, entry_point_offset)); |
| 1508 | __ Blr(lr); |
| 1509 | } |
| 1510 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1511 | void InstructionCodeGeneratorARM64::GenerateClassInitializationCheck(SlowPathCodeARM64* slow_path, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1512 | Register class_reg) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1513 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 1514 | Register temp = temps.AcquireW(); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1515 | size_t status_offset = mirror::Class::StatusOffset().SizeValue(); |
| 1516 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1517 | // 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] | 1518 | // TODO(vixl): Let the MacroAssembler handle MemOperand. |
| 1519 | __ Add(temp, class_reg, status_offset); |
| 1520 | __ Ldar(temp, HeapOperand(temp)); |
| 1521 | __ Cmp(temp, mirror::Class::kStatusInitialized); |
| 1522 | __ B(lt, slow_path->GetEntryLabel()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1523 | __ Bind(slow_path->GetExitLabel()); |
| 1524 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1525 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1526 | void CodeGeneratorARM64::GenerateMemoryBarrier(MemBarrierKind kind) { |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1527 | BarrierType type = BarrierAll; |
| 1528 | |
| 1529 | switch (kind) { |
| 1530 | case MemBarrierKind::kAnyAny: |
| 1531 | case MemBarrierKind::kAnyStore: { |
| 1532 | type = BarrierAll; |
| 1533 | break; |
| 1534 | } |
| 1535 | case MemBarrierKind::kLoadAny: { |
| 1536 | type = BarrierReads; |
| 1537 | break; |
| 1538 | } |
| 1539 | case MemBarrierKind::kStoreStore: { |
| 1540 | type = BarrierWrites; |
| 1541 | break; |
| 1542 | } |
| 1543 | default: |
| 1544 | LOG(FATAL) << "Unexpected memory barrier " << kind; |
| 1545 | } |
| 1546 | __ Dmb(InnerShareable, type); |
| 1547 | } |
| 1548 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1549 | void InstructionCodeGeneratorARM64::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 1550 | HBasicBlock* successor) { |
| 1551 | SuspendCheckSlowPathARM64* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 1552 | down_cast<SuspendCheckSlowPathARM64*>(instruction->GetSlowPath()); |
| 1553 | if (slow_path == nullptr) { |
| 1554 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathARM64(instruction, successor); |
| 1555 | instruction->SetSlowPath(slow_path); |
| 1556 | codegen_->AddSlowPath(slow_path); |
| 1557 | if (successor != nullptr) { |
| 1558 | DCHECK(successor->IsLoopHeader()); |
| 1559 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 1560 | } |
| 1561 | } else { |
| 1562 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 1563 | } |
| 1564 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1565 | UseScratchRegisterScope temps(codegen_->GetVIXLAssembler()); |
| 1566 | Register temp = temps.AcquireW(); |
| 1567 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1568 | __ Ldrh(temp, MemOperand(tr, Thread::ThreadFlagsOffset<kArm64PointerSize>().SizeValue())); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1569 | if (successor == nullptr) { |
| 1570 | __ Cbnz(temp, slow_path->GetEntryLabel()); |
| 1571 | __ Bind(slow_path->GetReturnLabel()); |
| 1572 | } else { |
| 1573 | __ Cbz(temp, codegen_->GetLabelOf(successor)); |
| 1574 | __ B(slow_path->GetEntryLabel()); |
| 1575 | // slow_path will return to GetLabelOf(successor). |
| 1576 | } |
| 1577 | } |
| 1578 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1579 | InstructionCodeGeneratorARM64::InstructionCodeGeneratorARM64(HGraph* graph, |
| 1580 | CodeGeneratorARM64* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1581 | : InstructionCodeGenerator(graph, codegen), |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1582 | assembler_(codegen->GetAssembler()), |
| 1583 | codegen_(codegen) {} |
| 1584 | |
| 1585 | #define FOR_EACH_UNIMPLEMENTED_INSTRUCTION(M) \ |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1586 | /* No unimplemented IR. */ |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1587 | |
| 1588 | #define UNIMPLEMENTED_INSTRUCTION_BREAK_CODE(name) name##UnimplementedInstructionBreakCode |
| 1589 | |
| 1590 | enum UnimplementedInstructionBreakCode { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1591 | // Using a base helps identify when we hit such breakpoints. |
| 1592 | UnimplementedInstructionBreakCodeBaseCode = 0x900, |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1593 | #define ENUM_UNIMPLEMENTED_INSTRUCTION(name) UNIMPLEMENTED_INSTRUCTION_BREAK_CODE(name), |
| 1594 | FOR_EACH_UNIMPLEMENTED_INSTRUCTION(ENUM_UNIMPLEMENTED_INSTRUCTION) |
| 1595 | #undef ENUM_UNIMPLEMENTED_INSTRUCTION |
| 1596 | }; |
| 1597 | |
| 1598 | #define DEFINE_UNIMPLEMENTED_INSTRUCTION_VISITORS(name) \ |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1599 | void InstructionCodeGeneratorARM64::Visit##name(H##name* instr ATTRIBUTE_UNUSED) { \ |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1600 | __ Brk(UNIMPLEMENTED_INSTRUCTION_BREAK_CODE(name)); \ |
| 1601 | } \ |
| 1602 | void LocationsBuilderARM64::Visit##name(H##name* instr) { \ |
| 1603 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr); \ |
| 1604 | locations->SetOut(Location::Any()); \ |
| 1605 | } |
| 1606 | FOR_EACH_UNIMPLEMENTED_INSTRUCTION(DEFINE_UNIMPLEMENTED_INSTRUCTION_VISITORS) |
| 1607 | #undef DEFINE_UNIMPLEMENTED_INSTRUCTION_VISITORS |
| 1608 | |
| 1609 | #undef UNIMPLEMENTED_INSTRUCTION_BREAK_CODE |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1610 | #undef FOR_EACH_UNIMPLEMENTED_INSTRUCTION |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1611 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1612 | void LocationsBuilderARM64::HandleBinaryOp(HBinaryOperation* instr) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1613 | DCHECK_EQ(instr->InputCount(), 2U); |
| 1614 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr); |
| 1615 | Primitive::Type type = instr->GetResultType(); |
| 1616 | switch (type) { |
| 1617 | case Primitive::kPrimInt: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1618 | case Primitive::kPrimLong: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1619 | locations->SetInAt(0, Location::RequiresRegister()); |
Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 1620 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instr->InputAt(1), instr)); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 1621 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1622 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1623 | |
| 1624 | case Primitive::kPrimFloat: |
| 1625 | case Primitive::kPrimDouble: |
| 1626 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1627 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1628 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1629 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1630 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1631 | default: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1632 | LOG(FATAL) << "Unexpected " << instr->DebugName() << " type " << type; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1633 | } |
| 1634 | } |
| 1635 | |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1636 | void LocationsBuilderARM64::HandleFieldGet(HInstruction* instruction) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1637 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 1638 | |
| 1639 | bool object_field_get_with_read_barrier = |
| 1640 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1641 | LocationSummary* locations = |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1642 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 1643 | object_field_get_with_read_barrier ? |
| 1644 | LocationSummary::kCallOnSlowPath : |
| 1645 | LocationSummary::kNoCall); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1646 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1647 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 1648 | locations->SetOut(Location::RequiresFpuRegister()); |
| 1649 | } else { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1650 | // The output overlaps for an object field get when read barriers |
| 1651 | // are enabled: we do not want the load to overwrite the object's |
| 1652 | // location, as we need it to emit the read barrier. |
| 1653 | locations->SetOut( |
| 1654 | Location::RequiresRegister(), |
| 1655 | object_field_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1656 | } |
| 1657 | } |
| 1658 | |
| 1659 | void InstructionCodeGeneratorARM64::HandleFieldGet(HInstruction* instruction, |
| 1660 | const FieldInfo& field_info) { |
| 1661 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1662 | LocationSummary* locations = instruction->GetLocations(); |
| 1663 | Location base_loc = locations->InAt(0); |
| 1664 | Location out = locations->Out(); |
| 1665 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1666 | Primitive::Type field_type = field_info.GetFieldType(); |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1667 | BlockPoolsScope block_pools(GetVIXLAssembler()); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1668 | MemOperand field = HeapOperand(InputRegisterAt(instruction, 0), field_info.GetFieldOffset()); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1669 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1670 | if (field_type == Primitive::kPrimNot && kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 1671 | // Object FieldGet with Baker's read barrier case. |
| 1672 | MacroAssembler* masm = GetVIXLAssembler(); |
| 1673 | UseScratchRegisterScope temps(masm); |
| 1674 | // /* HeapReference<Object> */ out = *(base + offset) |
| 1675 | Register base = RegisterFrom(base_loc, Primitive::kPrimNot); |
| 1676 | Register temp = temps.AcquireW(); |
| 1677 | // Note that potential implicit null checks are handled in this |
| 1678 | // CodeGeneratorARM64::GenerateFieldLoadWithBakerReadBarrier call. |
| 1679 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 1680 | instruction, |
| 1681 | out, |
| 1682 | base, |
| 1683 | offset, |
| 1684 | temp, |
| 1685 | /* needs_null_check */ true, |
Serban Constantinescu | 4a6a67c | 2016-01-27 09:19:56 +0000 | [diff] [blame] | 1686 | field_info.IsVolatile()); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1687 | } else { |
| 1688 | // General case. |
| 1689 | if (field_info.IsVolatile()) { |
Serban Constantinescu | 4a6a67c | 2016-01-27 09:19:56 +0000 | [diff] [blame] | 1690 | // Note that a potential implicit null check is handled in this |
| 1691 | // CodeGeneratorARM64::LoadAcquire call. |
| 1692 | // NB: LoadAcquire will record the pc info if needed. |
| 1693 | codegen_->LoadAcquire( |
| 1694 | instruction, OutputCPURegister(instruction), field, /* needs_null_check */ true); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1695 | } else { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1696 | codegen_->Load(field_type, OutputCPURegister(instruction), field); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1697 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1698 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1699 | if (field_type == Primitive::kPrimNot) { |
| 1700 | // If read barriers are enabled, emit read barriers other than |
| 1701 | // Baker's using a slow path (and also unpoison the loaded |
| 1702 | // reference, if heap poisoning is enabled). |
| 1703 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 1704 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1705 | } |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1706 | } |
| 1707 | |
| 1708 | void LocationsBuilderARM64::HandleFieldSet(HInstruction* instruction) { |
| 1709 | LocationSummary* locations = |
| 1710 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 1711 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1712 | if (Primitive::IsFloatingPointType(instruction->InputAt(1)->GetType())) { |
| 1713 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1714 | } else { |
| 1715 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1716 | } |
| 1717 | } |
| 1718 | |
| 1719 | void InstructionCodeGeneratorARM64::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1720 | const FieldInfo& field_info, |
| 1721 | bool value_can_be_null) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1722 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1723 | BlockPoolsScope block_pools(GetVIXLAssembler()); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1724 | |
| 1725 | Register obj = InputRegisterAt(instruction, 0); |
| 1726 | CPURegister value = InputCPURegisterAt(instruction, 1); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1727 | CPURegister source = value; |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1728 | Offset offset = field_info.GetFieldOffset(); |
| 1729 | Primitive::Type field_type = field_info.GetFieldType(); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1730 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1731 | { |
| 1732 | // We use a block to end the scratch scope before the write barrier, thus |
| 1733 | // freeing the temporary registers so they can be used in `MarkGCCard`. |
| 1734 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 1735 | |
| 1736 | if (kPoisonHeapReferences && field_type == Primitive::kPrimNot) { |
| 1737 | DCHECK(value.IsW()); |
| 1738 | Register temp = temps.AcquireW(); |
| 1739 | __ Mov(temp, value.W()); |
| 1740 | GetAssembler()->PoisonHeapReference(temp.W()); |
| 1741 | source = temp; |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1742 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1743 | |
| 1744 | if (field_info.IsVolatile()) { |
Serban Constantinescu | 4a6a67c | 2016-01-27 09:19:56 +0000 | [diff] [blame] | 1745 | codegen_->StoreRelease(field_type, source, HeapOperand(obj, offset)); |
| 1746 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1747 | } else { |
| 1748 | codegen_->Store(field_type, source, HeapOperand(obj, offset)); |
| 1749 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 1750 | } |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1751 | } |
| 1752 | |
| 1753 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1754 | codegen_->MarkGCCard(obj, Register(value), value_can_be_null); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1755 | } |
| 1756 | } |
| 1757 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1758 | void InstructionCodeGeneratorARM64::HandleBinaryOp(HBinaryOperation* instr) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1759 | Primitive::Type type = instr->GetType(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1760 | |
| 1761 | switch (type) { |
| 1762 | case Primitive::kPrimInt: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1763 | case Primitive::kPrimLong: { |
| 1764 | Register dst = OutputRegister(instr); |
| 1765 | Register lhs = InputRegisterAt(instr, 0); |
| 1766 | Operand rhs = InputOperandAt(instr, 1); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1767 | if (instr->IsAdd()) { |
| 1768 | __ Add(dst, lhs, rhs); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1769 | } else if (instr->IsAnd()) { |
| 1770 | __ And(dst, lhs, rhs); |
| 1771 | } else if (instr->IsOr()) { |
| 1772 | __ Orr(dst, lhs, rhs); |
| 1773 | } else if (instr->IsSub()) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1774 | __ Sub(dst, lhs, rhs); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 1775 | } else if (instr->IsRor()) { |
| 1776 | if (rhs.IsImmediate()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1777 | uint32_t shift = rhs.GetImmediate() & (lhs.GetSizeInBits() - 1); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 1778 | __ Ror(dst, lhs, shift); |
| 1779 | } else { |
| 1780 | // Ensure shift distance is in the same size register as the result. If |
| 1781 | // we are rotating a long and the shift comes in a w register originally, |
| 1782 | // we don't need to sxtw for use as an x since the shift distances are |
| 1783 | // all & reg_bits - 1. |
| 1784 | __ Ror(dst, lhs, RegisterFrom(instr->GetLocations()->InAt(1), type)); |
| 1785 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1786 | } else { |
| 1787 | DCHECK(instr->IsXor()); |
| 1788 | __ Eor(dst, lhs, rhs); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1789 | } |
| 1790 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1791 | } |
| 1792 | case Primitive::kPrimFloat: |
| 1793 | case Primitive::kPrimDouble: { |
| 1794 | FPRegister dst = OutputFPRegister(instr); |
| 1795 | FPRegister lhs = InputFPRegisterAt(instr, 0); |
| 1796 | FPRegister rhs = InputFPRegisterAt(instr, 1); |
| 1797 | if (instr->IsAdd()) { |
| 1798 | __ Fadd(dst, lhs, rhs); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1799 | } else if (instr->IsSub()) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1800 | __ Fsub(dst, lhs, rhs); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1801 | } else { |
| 1802 | LOG(FATAL) << "Unexpected floating-point binary operation"; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1803 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1804 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1805 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1806 | default: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1807 | LOG(FATAL) << "Unexpected binary operation type " << type; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1808 | } |
| 1809 | } |
| 1810 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1811 | void LocationsBuilderARM64::HandleShift(HBinaryOperation* instr) { |
| 1812 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr()); |
| 1813 | |
| 1814 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr); |
| 1815 | Primitive::Type type = instr->GetResultType(); |
| 1816 | switch (type) { |
| 1817 | case Primitive::kPrimInt: |
| 1818 | case Primitive::kPrimLong: { |
| 1819 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1820 | locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1))); |
| 1821 | locations->SetOut(Location::RequiresRegister()); |
| 1822 | break; |
| 1823 | } |
| 1824 | default: |
| 1825 | LOG(FATAL) << "Unexpected shift type " << type; |
| 1826 | } |
| 1827 | } |
| 1828 | |
| 1829 | void InstructionCodeGeneratorARM64::HandleShift(HBinaryOperation* instr) { |
| 1830 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr()); |
| 1831 | |
| 1832 | Primitive::Type type = instr->GetType(); |
| 1833 | switch (type) { |
| 1834 | case Primitive::kPrimInt: |
| 1835 | case Primitive::kPrimLong: { |
| 1836 | Register dst = OutputRegister(instr); |
| 1837 | Register lhs = InputRegisterAt(instr, 0); |
| 1838 | Operand rhs = InputOperandAt(instr, 1); |
| 1839 | if (rhs.IsImmediate()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1840 | uint32_t shift_value = rhs.GetImmediate() & |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 1841 | (type == Primitive::kPrimInt ? kMaxIntShiftDistance : kMaxLongShiftDistance); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1842 | if (instr->IsShl()) { |
| 1843 | __ Lsl(dst, lhs, shift_value); |
| 1844 | } else if (instr->IsShr()) { |
| 1845 | __ Asr(dst, lhs, shift_value); |
| 1846 | } else { |
| 1847 | __ Lsr(dst, lhs, shift_value); |
| 1848 | } |
| 1849 | } else { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1850 | Register rhs_reg = dst.IsX() ? rhs.GetRegister().X() : rhs.GetRegister().W(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1851 | |
| 1852 | if (instr->IsShl()) { |
| 1853 | __ Lsl(dst, lhs, rhs_reg); |
| 1854 | } else if (instr->IsShr()) { |
| 1855 | __ Asr(dst, lhs, rhs_reg); |
| 1856 | } else { |
| 1857 | __ Lsr(dst, lhs, rhs_reg); |
| 1858 | } |
| 1859 | } |
| 1860 | break; |
| 1861 | } |
| 1862 | default: |
| 1863 | LOG(FATAL) << "Unexpected shift operation type " << type; |
| 1864 | } |
| 1865 | } |
| 1866 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1867 | void LocationsBuilderARM64::VisitAdd(HAdd* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1868 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1869 | } |
| 1870 | |
| 1871 | void InstructionCodeGeneratorARM64::VisitAdd(HAdd* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1872 | HandleBinaryOp(instruction); |
| 1873 | } |
| 1874 | |
| 1875 | void LocationsBuilderARM64::VisitAnd(HAnd* instruction) { |
| 1876 | HandleBinaryOp(instruction); |
| 1877 | } |
| 1878 | |
| 1879 | void InstructionCodeGeneratorARM64::VisitAnd(HAnd* instruction) { |
| 1880 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1881 | } |
| 1882 | |
Artem Serov | 7fc6350 | 2016-02-09 17:15:29 +0000 | [diff] [blame] | 1883 | void LocationsBuilderARM64::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instr) { |
Kevin Brodsky | 9ff0d20 | 2016-01-11 13:43:31 +0000 | [diff] [blame] | 1884 | DCHECK(Primitive::IsIntegralType(instr->GetType())) << instr->GetType(); |
| 1885 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr); |
| 1886 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1887 | // There is no immediate variant of negated bitwise instructions in AArch64. |
| 1888 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1889 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1890 | } |
| 1891 | |
Artem Serov | 7fc6350 | 2016-02-09 17:15:29 +0000 | [diff] [blame] | 1892 | void InstructionCodeGeneratorARM64::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instr) { |
Kevin Brodsky | 9ff0d20 | 2016-01-11 13:43:31 +0000 | [diff] [blame] | 1893 | Register dst = OutputRegister(instr); |
| 1894 | Register lhs = InputRegisterAt(instr, 0); |
| 1895 | Register rhs = InputRegisterAt(instr, 1); |
| 1896 | |
| 1897 | switch (instr->GetOpKind()) { |
| 1898 | case HInstruction::kAnd: |
| 1899 | __ Bic(dst, lhs, rhs); |
| 1900 | break; |
| 1901 | case HInstruction::kOr: |
| 1902 | __ Orn(dst, lhs, rhs); |
| 1903 | break; |
| 1904 | case HInstruction::kXor: |
| 1905 | __ Eon(dst, lhs, rhs); |
| 1906 | break; |
| 1907 | default: |
| 1908 | LOG(FATAL) << "Unreachable"; |
| 1909 | } |
| 1910 | } |
| 1911 | |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 1912 | void LocationsBuilderARM64::VisitArm64DataProcWithShifterOp( |
| 1913 | HArm64DataProcWithShifterOp* instruction) { |
| 1914 | DCHECK(instruction->GetType() == Primitive::kPrimInt || |
| 1915 | instruction->GetType() == Primitive::kPrimLong); |
| 1916 | LocationSummary* locations = |
| 1917 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 1918 | if (instruction->GetInstrKind() == HInstruction::kNeg) { |
| 1919 | locations->SetInAt(0, Location::ConstantLocation(instruction->InputAt(0)->AsConstant())); |
| 1920 | } else { |
| 1921 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1922 | } |
| 1923 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1924 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1925 | } |
| 1926 | |
| 1927 | void InstructionCodeGeneratorARM64::VisitArm64DataProcWithShifterOp( |
| 1928 | HArm64DataProcWithShifterOp* instruction) { |
| 1929 | Primitive::Type type = instruction->GetType(); |
| 1930 | HInstruction::InstructionKind kind = instruction->GetInstrKind(); |
| 1931 | DCHECK(type == Primitive::kPrimInt || type == Primitive::kPrimLong); |
| 1932 | Register out = OutputRegister(instruction); |
| 1933 | Register left; |
| 1934 | if (kind != HInstruction::kNeg) { |
| 1935 | left = InputRegisterAt(instruction, 0); |
| 1936 | } |
| 1937 | // If this `HArm64DataProcWithShifterOp` was created by merging a type conversion as the |
| 1938 | // shifter operand operation, the IR generating `right_reg` (input to the type |
| 1939 | // conversion) can have a different type from the current instruction's type, |
| 1940 | // so we manually indicate the type. |
| 1941 | Register right_reg = RegisterFrom(instruction->GetLocations()->InAt(1), type); |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 1942 | int64_t shift_amount = instruction->GetShiftAmount() & |
| 1943 | (type == Primitive::kPrimInt ? kMaxIntShiftDistance : kMaxLongShiftDistance); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 1944 | |
| 1945 | Operand right_operand(0); |
| 1946 | |
| 1947 | HArm64DataProcWithShifterOp::OpKind op_kind = instruction->GetOpKind(); |
| 1948 | if (HArm64DataProcWithShifterOp::IsExtensionOp(op_kind)) { |
| 1949 | right_operand = Operand(right_reg, helpers::ExtendFromOpKind(op_kind)); |
| 1950 | } else { |
| 1951 | right_operand = Operand(right_reg, helpers::ShiftFromOpKind(op_kind), shift_amount); |
| 1952 | } |
| 1953 | |
| 1954 | // Logical binary operations do not support extension operations in the |
| 1955 | // operand. Note that VIXL would still manage if it was passed by generating |
| 1956 | // the extension as a separate instruction. |
| 1957 | // `HNeg` also does not support extension. See comments in `ShifterOperandSupportsExtension()`. |
| 1958 | DCHECK(!right_operand.IsExtendedRegister() || |
| 1959 | (kind != HInstruction::kAnd && kind != HInstruction::kOr && kind != HInstruction::kXor && |
| 1960 | kind != HInstruction::kNeg)); |
| 1961 | switch (kind) { |
| 1962 | case HInstruction::kAdd: |
| 1963 | __ Add(out, left, right_operand); |
| 1964 | break; |
| 1965 | case HInstruction::kAnd: |
| 1966 | __ And(out, left, right_operand); |
| 1967 | break; |
| 1968 | case HInstruction::kNeg: |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1969 | DCHECK(instruction->InputAt(0)->AsConstant()->IsArithmeticZero()); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 1970 | __ Neg(out, right_operand); |
| 1971 | break; |
| 1972 | case HInstruction::kOr: |
| 1973 | __ Orr(out, left, right_operand); |
| 1974 | break; |
| 1975 | case HInstruction::kSub: |
| 1976 | __ Sub(out, left, right_operand); |
| 1977 | break; |
| 1978 | case HInstruction::kXor: |
| 1979 | __ Eor(out, left, right_operand); |
| 1980 | break; |
| 1981 | default: |
| 1982 | LOG(FATAL) << "Unexpected operation kind: " << kind; |
| 1983 | UNREACHABLE(); |
| 1984 | } |
| 1985 | } |
| 1986 | |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 1987 | void LocationsBuilderARM64::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
Roland Levillain | 4a3aa57 | 2016-08-15 13:17:06 +0000 | [diff] [blame] | 1988 | // The read barrier instrumentation does not support the HIntermediateAddress instruction yet. |
| 1989 | DCHECK(!kEmitCompilerReadBarrier); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1990 | LocationSummary* locations = |
| 1991 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 1992 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1993 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->GetOffset(), instruction)); |
| 1994 | locations->SetOut(Location::RequiresRegister()); |
| 1995 | } |
| 1996 | |
Roland Levillain | 4a3aa57 | 2016-08-15 13:17:06 +0000 | [diff] [blame] | 1997 | void InstructionCodeGeneratorARM64::VisitIntermediateAddress( |
| 1998 | HIntermediateAddress* instruction) { |
| 1999 | // The read barrier instrumentation does not support the HIntermediateAddress instruction yet. |
| 2000 | DCHECK(!kEmitCompilerReadBarrier); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2001 | __ Add(OutputRegister(instruction), |
| 2002 | InputRegisterAt(instruction, 0), |
| 2003 | Operand(InputOperandAt(instruction, 1))); |
| 2004 | } |
| 2005 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2006 | void LocationsBuilderARM64::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2007 | LocationSummary* locations = |
| 2008 | new (GetGraph()->GetArena()) LocationSummary(instr, LocationSummary::kNoCall); |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2009 | HInstruction* accumulator = instr->InputAt(HMultiplyAccumulate::kInputAccumulatorIndex); |
| 2010 | if (instr->GetOpKind() == HInstruction::kSub && |
| 2011 | accumulator->IsConstant() && |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2012 | accumulator->AsConstant()->IsArithmeticZero()) { |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2013 | // Don't allocate register for Mneg instruction. |
| 2014 | } else { |
| 2015 | locations->SetInAt(HMultiplyAccumulate::kInputAccumulatorIndex, |
| 2016 | Location::RequiresRegister()); |
| 2017 | } |
| 2018 | locations->SetInAt(HMultiplyAccumulate::kInputMulLeftIndex, Location::RequiresRegister()); |
| 2019 | locations->SetInAt(HMultiplyAccumulate::kInputMulRightIndex, Location::RequiresRegister()); |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2020 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2021 | } |
| 2022 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2023 | void InstructionCodeGeneratorARM64::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2024 | Register res = OutputRegister(instr); |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2025 | Register mul_left = InputRegisterAt(instr, HMultiplyAccumulate::kInputMulLeftIndex); |
| 2026 | Register mul_right = InputRegisterAt(instr, HMultiplyAccumulate::kInputMulRightIndex); |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2027 | |
| 2028 | // Avoid emitting code that could trigger Cortex A53's erratum 835769. |
| 2029 | // This fixup should be carried out for all multiply-accumulate instructions: |
| 2030 | // madd, msub, smaddl, smsubl, umaddl and umsubl. |
| 2031 | if (instr->GetType() == Primitive::kPrimLong && |
| 2032 | codegen_->GetInstructionSetFeatures().NeedFixCortexA53_835769()) { |
| 2033 | MacroAssembler* masm = down_cast<CodeGeneratorARM64*>(codegen_)->GetVIXLAssembler(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2034 | vixl::aarch64::Instruction* prev = |
| 2035 | masm->GetCursorAddress<vixl::aarch64::Instruction*>() - kInstructionSize; |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2036 | if (prev->IsLoadOrStore()) { |
| 2037 | // Make sure we emit only exactly one nop. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2038 | vixl::aarch64::CodeBufferCheckScope scope(masm, |
| 2039 | kInstructionSize, |
| 2040 | vixl::aarch64::CodeBufferCheckScope::kCheck, |
| 2041 | vixl::aarch64::CodeBufferCheckScope::kExactSize); |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2042 | __ nop(); |
| 2043 | } |
| 2044 | } |
| 2045 | |
| 2046 | if (instr->GetOpKind() == HInstruction::kAdd) { |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2047 | Register accumulator = InputRegisterAt(instr, HMultiplyAccumulate::kInputAccumulatorIndex); |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2048 | __ Madd(res, mul_left, mul_right, accumulator); |
| 2049 | } else { |
| 2050 | DCHECK(instr->GetOpKind() == HInstruction::kSub); |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2051 | HInstruction* accum_instr = instr->InputAt(HMultiplyAccumulate::kInputAccumulatorIndex); |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2052 | if (accum_instr->IsConstant() && accum_instr->AsConstant()->IsArithmeticZero()) { |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2053 | __ Mneg(res, mul_left, mul_right); |
| 2054 | } else { |
| 2055 | Register accumulator = InputRegisterAt(instr, HMultiplyAccumulate::kInputAccumulatorIndex); |
| 2056 | __ Msub(res, mul_left, mul_right, accumulator); |
| 2057 | } |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2058 | } |
| 2059 | } |
| 2060 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2061 | void LocationsBuilderARM64::VisitArrayGet(HArrayGet* instruction) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2062 | bool object_array_get_with_read_barrier = |
| 2063 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2064 | LocationSummary* locations = |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2065 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 2066 | object_array_get_with_read_barrier ? |
| 2067 | LocationSummary::kCallOnSlowPath : |
| 2068 | LocationSummary::kNoCall); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2069 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2070 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 2071 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 2072 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 2073 | } else { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2074 | // The output overlaps in the case of an object array get with |
| 2075 | // read barriers enabled: we do not want the move to overwrite the |
| 2076 | // array's location, as we need it to emit the read barrier. |
| 2077 | locations->SetOut( |
| 2078 | Location::RequiresRegister(), |
| 2079 | object_array_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 2080 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2081 | } |
| 2082 | |
| 2083 | void InstructionCodeGeneratorARM64::VisitArrayGet(HArrayGet* instruction) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2084 | Primitive::Type type = instruction->GetType(); |
| 2085 | Register obj = InputRegisterAt(instruction, 0); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2086 | LocationSummary* locations = instruction->GetLocations(); |
| 2087 | Location index = locations->InAt(1); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2088 | Location out = locations->Out(); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 2089 | uint32_t offset = CodeGenerator::GetArrayDataOffset(instruction); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2090 | |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 2091 | MacroAssembler* masm = GetVIXLAssembler(); |
| 2092 | UseScratchRegisterScope temps(masm); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2093 | // Block pools between `Load` and `MaybeRecordImplicitNullCheck`. |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 2094 | BlockPoolsScope block_pools(masm); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2095 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2096 | if (type == Primitive::kPrimNot && kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 2097 | // Object ArrayGet with Baker's read barrier case. |
| 2098 | Register temp = temps.AcquireW(); |
Roland Levillain | 4a3aa57 | 2016-08-15 13:17:06 +0000 | [diff] [blame] | 2099 | // The read barrier instrumentation does not support the HIntermediateAddress instruction yet. |
| 2100 | DCHECK(!instruction->GetArray()->IsIntermediateAddress()); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2101 | // Note that a potential implicit null check is handled in the |
| 2102 | // CodeGeneratorARM64::GenerateArrayLoadWithBakerReadBarrier call. |
| 2103 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
| 2104 | instruction, out, obj.W(), offset, index, temp, /* needs_null_check */ true); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2105 | } else { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2106 | // General case. |
| 2107 | MemOperand source = HeapOperand(obj); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2108 | if (index.IsConstant()) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2109 | offset += Int64ConstantFrom(index) << Primitive::ComponentSizeShift(type); |
| 2110 | source = HeapOperand(obj, offset); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2111 | } else { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2112 | Register temp = temps.AcquireSameSizeAs(obj); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2113 | if (instruction->GetArray()->IsIntermediateAddress()) { |
Roland Levillain | 4a3aa57 | 2016-08-15 13:17:06 +0000 | [diff] [blame] | 2114 | // The read barrier instrumentation does not support the |
| 2115 | // HIntermediateAddress instruction yet. |
| 2116 | DCHECK(!kEmitCompilerReadBarrier); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2117 | // We do not need to compute the intermediate address from the array: the |
| 2118 | // input instruction has done it already. See the comment in |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2119 | // `TryExtractArrayAccessAddress()`. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2120 | if (kIsDebugBuild) { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2121 | HIntermediateAddress* tmp = instruction->GetArray()->AsIntermediateAddress(); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2122 | DCHECK_EQ(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64(), offset); |
| 2123 | } |
| 2124 | temp = obj; |
| 2125 | } else { |
| 2126 | __ Add(temp, obj, offset); |
| 2127 | } |
| 2128 | source = HeapOperand(temp, XRegisterFrom(index), LSL, Primitive::ComponentSizeShift(type)); |
| 2129 | } |
| 2130 | |
| 2131 | codegen_->Load(type, OutputCPURegister(instruction), source); |
| 2132 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2133 | |
| 2134 | if (type == Primitive::kPrimNot) { |
| 2135 | static_assert( |
| 2136 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 2137 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 2138 | Location obj_loc = locations->InAt(0); |
| 2139 | if (index.IsConstant()) { |
| 2140 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, obj_loc, offset); |
| 2141 | } else { |
| 2142 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, obj_loc, offset, index); |
| 2143 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2144 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2145 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2146 | } |
| 2147 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2148 | void LocationsBuilderARM64::VisitArrayLength(HArrayLength* instruction) { |
| 2149 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 2150 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 2151 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2152 | } |
| 2153 | |
| 2154 | void InstructionCodeGeneratorARM64::VisitArrayLength(HArrayLength* instruction) { |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 2155 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 2156 | BlockPoolsScope block_pools(GetVIXLAssembler()); |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 2157 | __ Ldr(OutputRegister(instruction), HeapOperand(InputRegisterAt(instruction, 0), offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 2158 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2159 | } |
| 2160 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2161 | void LocationsBuilderARM64::VisitArraySet(HArraySet* instruction) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2162 | Primitive::Type value_type = instruction->GetComponentType(); |
| 2163 | |
| 2164 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
| 2165 | bool object_array_set_with_read_barrier = |
| 2166 | kEmitCompilerReadBarrier && (value_type == Primitive::kPrimNot); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2167 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 2168 | instruction, |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2169 | (may_need_runtime_call_for_type_check || object_array_set_with_read_barrier) ? |
| 2170 | LocationSummary::kCallOnSlowPath : |
| 2171 | LocationSummary::kNoCall); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2172 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2173 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2174 | if (Primitive::IsFloatingPointType(value_type)) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2175 | locations->SetInAt(2, Location::RequiresFpuRegister()); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2176 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2177 | locations->SetInAt(2, Location::RequiresRegister()); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2178 | } |
| 2179 | } |
| 2180 | |
| 2181 | void InstructionCodeGeneratorARM64::VisitArraySet(HArraySet* instruction) { |
| 2182 | Primitive::Type value_type = instruction->GetComponentType(); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2183 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2184 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2185 | bool needs_write_barrier = |
| 2186 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2187 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2188 | Register array = InputRegisterAt(instruction, 0); |
| 2189 | CPURegister value = InputCPURegisterAt(instruction, 2); |
| 2190 | CPURegister source = value; |
| 2191 | Location index = locations->InAt(1); |
| 2192 | size_t offset = mirror::Array::DataOffset(Primitive::ComponentSize(value_type)).Uint32Value(); |
| 2193 | MemOperand destination = HeapOperand(array); |
| 2194 | MacroAssembler* masm = GetVIXLAssembler(); |
| 2195 | BlockPoolsScope block_pools(masm); |
| 2196 | |
| 2197 | if (!needs_write_barrier) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2198 | DCHECK(!may_need_runtime_call_for_type_check); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2199 | if (index.IsConstant()) { |
| 2200 | offset += Int64ConstantFrom(index) << Primitive::ComponentSizeShift(value_type); |
| 2201 | destination = HeapOperand(array, offset); |
| 2202 | } else { |
| 2203 | UseScratchRegisterScope temps(masm); |
| 2204 | Register temp = temps.AcquireSameSizeAs(array); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2205 | if (instruction->GetArray()->IsIntermediateAddress()) { |
Roland Levillain | 4a3aa57 | 2016-08-15 13:17:06 +0000 | [diff] [blame] | 2206 | // The read barrier instrumentation does not support the |
| 2207 | // HIntermediateAddress instruction yet. |
| 2208 | DCHECK(!kEmitCompilerReadBarrier); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2209 | // We do not need to compute the intermediate address from the array: the |
| 2210 | // input instruction has done it already. See the comment in |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2211 | // `TryExtractArrayAccessAddress()`. |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2212 | if (kIsDebugBuild) { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2213 | HIntermediateAddress* tmp = instruction->GetArray()->AsIntermediateAddress(); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2214 | DCHECK(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64() == offset); |
| 2215 | } |
| 2216 | temp = array; |
| 2217 | } else { |
| 2218 | __ Add(temp, array, offset); |
| 2219 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2220 | destination = HeapOperand(temp, |
| 2221 | XRegisterFrom(index), |
| 2222 | LSL, |
| 2223 | Primitive::ComponentSizeShift(value_type)); |
| 2224 | } |
| 2225 | codegen_->Store(value_type, value, destination); |
| 2226 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2227 | } else { |
Roland Levillain | 4a3aa57 | 2016-08-15 13:17:06 +0000 | [diff] [blame] | 2228 | DCHECK(needs_write_barrier); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2229 | DCHECK(!instruction->GetArray()->IsIntermediateAddress()); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2230 | vixl::aarch64::Label done; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2231 | SlowPathCodeARM64* slow_path = nullptr; |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2232 | { |
| 2233 | // We use a block to end the scratch scope before the write barrier, thus |
| 2234 | // freeing the temporary registers so they can be used in `MarkGCCard`. |
| 2235 | UseScratchRegisterScope temps(masm); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2236 | Register temp = temps.AcquireSameSizeAs(array); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2237 | if (index.IsConstant()) { |
| 2238 | offset += Int64ConstantFrom(index) << Primitive::ComponentSizeShift(value_type); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2239 | destination = HeapOperand(array, offset); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2240 | } else { |
Alexandre Rames | 82000b0 | 2015-07-07 11:34:16 +0100 | [diff] [blame] | 2241 | destination = HeapOperand(temp, |
| 2242 | XRegisterFrom(index), |
| 2243 | LSL, |
| 2244 | Primitive::ComponentSizeShift(value_type)); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2245 | } |
| 2246 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2247 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2248 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 2249 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 2250 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2251 | if (may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2252 | slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathARM64(instruction); |
| 2253 | codegen_->AddSlowPath(slow_path); |
| 2254 | if (instruction->GetValueCanBeNull()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2255 | vixl::aarch64::Label non_zero; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2256 | __ Cbnz(Register(value), &non_zero); |
| 2257 | if (!index.IsConstant()) { |
| 2258 | __ Add(temp, array, offset); |
| 2259 | } |
| 2260 | __ Str(wzr, destination); |
| 2261 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2262 | __ B(&done); |
| 2263 | __ Bind(&non_zero); |
| 2264 | } |
| 2265 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2266 | if (kEmitCompilerReadBarrier) { |
| 2267 | // When read barriers are enabled, the type checking |
| 2268 | // instrumentation requires two read barriers: |
| 2269 | // |
| 2270 | // __ Mov(temp2, temp); |
| 2271 | // // /* HeapReference<Class> */ temp = temp->component_type_ |
| 2272 | // __ Ldr(temp, HeapOperand(temp, component_offset)); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2273 | // codegen_->GenerateReadBarrierSlow( |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2274 | // instruction, temp_loc, temp_loc, temp2_loc, component_offset); |
| 2275 | // |
| 2276 | // // /* HeapReference<Class> */ temp2 = value->klass_ |
| 2277 | // __ Ldr(temp2, HeapOperand(Register(value), class_offset)); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2278 | // codegen_->GenerateReadBarrierSlow( |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2279 | // instruction, temp2_loc, temp2_loc, value_loc, class_offset, temp_loc); |
| 2280 | // |
| 2281 | // __ Cmp(temp, temp2); |
| 2282 | // |
| 2283 | // However, the second read barrier may trash `temp`, as it |
| 2284 | // is a temporary register, and as such would not be saved |
| 2285 | // along with live registers before calling the runtime (nor |
| 2286 | // restored afterwards). So in this case, we bail out and |
| 2287 | // delegate the work to the array set slow path. |
| 2288 | // |
| 2289 | // TODO: Extend the register allocator to support a new |
| 2290 | // "(locally) live temp" location so as to avoid always |
| 2291 | // going into the slow path when read barriers are enabled. |
| 2292 | __ B(slow_path->GetEntryLabel()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2293 | } else { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2294 | Register temp2 = temps.AcquireSameSizeAs(array); |
| 2295 | // /* HeapReference<Class> */ temp = array->klass_ |
| 2296 | __ Ldr(temp, HeapOperand(array, class_offset)); |
| 2297 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2298 | GetAssembler()->MaybeUnpoisonHeapReference(temp); |
| 2299 | |
| 2300 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| 2301 | __ Ldr(temp, HeapOperand(temp, component_offset)); |
| 2302 | // /* HeapReference<Class> */ temp2 = value->klass_ |
| 2303 | __ Ldr(temp2, HeapOperand(Register(value), class_offset)); |
| 2304 | // If heap poisoning is enabled, no need to unpoison `temp` |
| 2305 | // nor `temp2`, as we are comparing two poisoned references. |
| 2306 | __ Cmp(temp, temp2); |
| 2307 | |
| 2308 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2309 | vixl::aarch64::Label do_put; |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2310 | __ B(eq, &do_put); |
| 2311 | // If heap poisoning is enabled, the `temp` reference has |
| 2312 | // not been unpoisoned yet; unpoison it now. |
| 2313 | GetAssembler()->MaybeUnpoisonHeapReference(temp); |
| 2314 | |
| 2315 | // /* HeapReference<Class> */ temp = temp->super_class_ |
| 2316 | __ Ldr(temp, HeapOperand(temp, super_offset)); |
| 2317 | // If heap poisoning is enabled, no need to unpoison |
| 2318 | // `temp`, as we are comparing against null below. |
| 2319 | __ Cbnz(temp, slow_path->GetEntryLabel()); |
| 2320 | __ Bind(&do_put); |
| 2321 | } else { |
| 2322 | __ B(ne, slow_path->GetEntryLabel()); |
| 2323 | } |
| 2324 | temps.Release(temp2); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2325 | } |
| 2326 | } |
| 2327 | |
| 2328 | if (kPoisonHeapReferences) { |
Nicolas Geoffray | a8a0fe2 | 2015-10-01 15:50:27 +0100 | [diff] [blame] | 2329 | Register temp2 = temps.AcquireSameSizeAs(array); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2330 | DCHECK(value.IsW()); |
Nicolas Geoffray | a8a0fe2 | 2015-10-01 15:50:27 +0100 | [diff] [blame] | 2331 | __ Mov(temp2, value.W()); |
| 2332 | GetAssembler()->PoisonHeapReference(temp2); |
| 2333 | source = temp2; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2334 | } |
| 2335 | |
| 2336 | if (!index.IsConstant()) { |
| 2337 | __ Add(temp, array, offset); |
| 2338 | } |
Nicolas Geoffray | 61b1dbe | 2015-10-01 10:27:52 +0100 | [diff] [blame] | 2339 | __ Str(source, destination); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2340 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2341 | if (!may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2342 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2343 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2344 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2345 | |
| 2346 | codegen_->MarkGCCard(array, value.W(), instruction->GetValueCanBeNull()); |
| 2347 | |
| 2348 | if (done.IsLinked()) { |
| 2349 | __ Bind(&done); |
| 2350 | } |
| 2351 | |
| 2352 | if (slow_path != nullptr) { |
| 2353 | __ Bind(slow_path->GetExitLabel()); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2354 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2355 | } |
| 2356 | } |
| 2357 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2358 | void LocationsBuilderARM64::VisitBoundsCheck(HBoundsCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2359 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 2360 | ? LocationSummary::kCallOnSlowPath |
| 2361 | : LocationSummary::kNoCall; |
| 2362 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2363 | locations->SetInAt(0, Location::RequiresRegister()); |
Serban Constantinescu | 760d8ef | 2015-03-28 18:09:56 +0000 | [diff] [blame] | 2364 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->InputAt(1), instruction)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2365 | if (instruction->HasUses()) { |
| 2366 | locations->SetOut(Location::SameAsFirstInput()); |
| 2367 | } |
| 2368 | } |
| 2369 | |
| 2370 | void InstructionCodeGeneratorARM64::VisitBoundsCheck(HBoundsCheck* instruction) { |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 2371 | BoundsCheckSlowPathARM64* slow_path = |
| 2372 | new (GetGraph()->GetArena()) BoundsCheckSlowPathARM64(instruction); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2373 | codegen_->AddSlowPath(slow_path); |
| 2374 | |
| 2375 | __ Cmp(InputRegisterAt(instruction, 0), InputOperandAt(instruction, 1)); |
| 2376 | __ B(slow_path->GetEntryLabel(), hs); |
| 2377 | } |
| 2378 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2379 | void LocationsBuilderARM64::VisitClinitCheck(HClinitCheck* check) { |
| 2380 | LocationSummary* locations = |
| 2381 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 2382 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2383 | if (check->HasUses()) { |
| 2384 | locations->SetOut(Location::SameAsFirstInput()); |
| 2385 | } |
| 2386 | } |
| 2387 | |
| 2388 | void InstructionCodeGeneratorARM64::VisitClinitCheck(HClinitCheck* check) { |
| 2389 | // We assume the class is not null. |
| 2390 | SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM64( |
| 2391 | check->GetLoadClass(), check, check->GetDexPc(), true); |
| 2392 | codegen_->AddSlowPath(slow_path); |
| 2393 | GenerateClassInitializationCheck(slow_path, InputRegisterAt(check, 0)); |
| 2394 | } |
| 2395 | |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2396 | static bool IsFloatingPointZeroConstant(HInstruction* inst) { |
| 2397 | return (inst->IsFloatConstant() && (inst->AsFloatConstant()->IsArithmeticZero())) |
| 2398 | || (inst->IsDoubleConstant() && (inst->AsDoubleConstant()->IsArithmeticZero())); |
| 2399 | } |
| 2400 | |
| 2401 | void InstructionCodeGeneratorARM64::GenerateFcmp(HInstruction* instruction) { |
| 2402 | FPRegister lhs_reg = InputFPRegisterAt(instruction, 0); |
| 2403 | Location rhs_loc = instruction->GetLocations()->InAt(1); |
| 2404 | if (rhs_loc.IsConstant()) { |
| 2405 | // 0.0 is the only immediate that can be encoded directly in |
| 2406 | // an FCMP instruction. |
| 2407 | // |
| 2408 | // Both the JLS (section 15.20.1) and the JVMS (section 6.5) |
| 2409 | // specify that in a floating-point comparison, positive zero |
| 2410 | // and negative zero are considered equal, so we can use the |
| 2411 | // literal 0.0 for both cases here. |
| 2412 | // |
| 2413 | // Note however that some methods (Float.equal, Float.compare, |
| 2414 | // Float.compareTo, Double.equal, Double.compare, |
| 2415 | // Double.compareTo, Math.max, Math.min, StrictMath.max, |
| 2416 | // StrictMath.min) consider 0.0 to be (strictly) greater than |
| 2417 | // -0.0. So if we ever translate calls to these methods into a |
| 2418 | // HCompare instruction, we must handle the -0.0 case with |
| 2419 | // care here. |
| 2420 | DCHECK(IsFloatingPointZeroConstant(rhs_loc.GetConstant())); |
| 2421 | __ Fcmp(lhs_reg, 0.0); |
| 2422 | } else { |
| 2423 | __ Fcmp(lhs_reg, InputFPRegisterAt(instruction, 1)); |
| 2424 | } |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2425 | } |
| 2426 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2427 | void LocationsBuilderARM64::VisitCompare(HCompare* compare) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2428 | LocationSummary* locations = |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2429 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
| 2430 | Primitive::Type in_type = compare->InputAt(0)->GetType(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2431 | switch (in_type) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 2432 | case Primitive::kPrimBoolean: |
| 2433 | case Primitive::kPrimByte: |
| 2434 | case Primitive::kPrimShort: |
| 2435 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2436 | case Primitive::kPrimInt: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2437 | case Primitive::kPrimLong: { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2438 | locations->SetInAt(0, Location::RequiresRegister()); |
Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 2439 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(compare->InputAt(1), compare)); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2440 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2441 | break; |
| 2442 | } |
| 2443 | case Primitive::kPrimFloat: |
| 2444 | case Primitive::kPrimDouble: { |
| 2445 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2446 | locations->SetInAt(1, |
| 2447 | IsFloatingPointZeroConstant(compare->InputAt(1)) |
| 2448 | ? Location::ConstantLocation(compare->InputAt(1)->AsConstant()) |
| 2449 | : Location::RequiresFpuRegister()); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2450 | locations->SetOut(Location::RequiresRegister()); |
| 2451 | break; |
| 2452 | } |
| 2453 | default: |
| 2454 | LOG(FATAL) << "Unexpected type for compare operation " << in_type; |
| 2455 | } |
| 2456 | } |
| 2457 | |
| 2458 | void InstructionCodeGeneratorARM64::VisitCompare(HCompare* compare) { |
| 2459 | Primitive::Type in_type = compare->InputAt(0)->GetType(); |
| 2460 | |
| 2461 | // 0 if: left == right |
| 2462 | // 1 if: left > right |
| 2463 | // -1 if: left < right |
| 2464 | switch (in_type) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 2465 | case Primitive::kPrimBoolean: |
| 2466 | case Primitive::kPrimByte: |
| 2467 | case Primitive::kPrimShort: |
| 2468 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2469 | case Primitive::kPrimInt: |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2470 | case Primitive::kPrimLong: { |
| 2471 | Register result = OutputRegister(compare); |
| 2472 | Register left = InputRegisterAt(compare, 0); |
| 2473 | Operand right = InputOperandAt(compare, 1); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2474 | __ Cmp(left, right); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2475 | __ Cset(result, ne); // result == +1 if NE or 0 otherwise |
| 2476 | __ Cneg(result, result, lt); // result == -1 if LT or unchanged otherwise |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2477 | break; |
| 2478 | } |
| 2479 | case Primitive::kPrimFloat: |
| 2480 | case Primitive::kPrimDouble: { |
| 2481 | Register result = OutputRegister(compare); |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2482 | GenerateFcmp(compare); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 2483 | __ Cset(result, ne); |
| 2484 | __ Cneg(result, result, ARM64FPCondition(kCondLT, compare->IsGtBias())); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2485 | break; |
| 2486 | } |
| 2487 | default: |
| 2488 | LOG(FATAL) << "Unimplemented compare type " << in_type; |
| 2489 | } |
| 2490 | } |
| 2491 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2492 | void LocationsBuilderARM64::HandleCondition(HCondition* instruction) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2493 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2494 | |
| 2495 | if (Primitive::IsFloatingPointType(instruction->InputAt(0)->GetType())) { |
| 2496 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2497 | locations->SetInAt(1, |
| 2498 | IsFloatingPointZeroConstant(instruction->InputAt(1)) |
| 2499 | ? Location::ConstantLocation(instruction->InputAt(1)->AsConstant()) |
| 2500 | : Location::RequiresFpuRegister()); |
| 2501 | } else { |
| 2502 | // Integer cases. |
| 2503 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2504 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->InputAt(1), instruction)); |
| 2505 | } |
| 2506 | |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2507 | if (!instruction->IsEmittedAtUseSite()) { |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 2508 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2509 | } |
| 2510 | } |
| 2511 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2512 | void InstructionCodeGeneratorARM64::HandleCondition(HCondition* instruction) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2513 | if (instruction->IsEmittedAtUseSite()) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2514 | return; |
| 2515 | } |
| 2516 | |
| 2517 | LocationSummary* locations = instruction->GetLocations(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2518 | Register res = RegisterFrom(locations->Out(), instruction->GetType()); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2519 | IfCondition if_cond = instruction->GetCondition(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2520 | |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2521 | if (Primitive::IsFloatingPointType(instruction->InputAt(0)->GetType())) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2522 | GenerateFcmp(instruction); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 2523 | __ Cset(res, ARM64FPCondition(if_cond, instruction->IsGtBias())); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2524 | } else { |
| 2525 | // Integer cases. |
| 2526 | Register lhs = InputRegisterAt(instruction, 0); |
| 2527 | Operand rhs = InputOperandAt(instruction, 1); |
| 2528 | __ Cmp(lhs, rhs); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 2529 | __ Cset(res, ARM64Condition(if_cond)); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2530 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2531 | } |
| 2532 | |
| 2533 | #define FOR_EACH_CONDITION_INSTRUCTION(M) \ |
| 2534 | M(Equal) \ |
| 2535 | M(NotEqual) \ |
| 2536 | M(LessThan) \ |
| 2537 | M(LessThanOrEqual) \ |
| 2538 | M(GreaterThan) \ |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2539 | M(GreaterThanOrEqual) \ |
| 2540 | M(Below) \ |
| 2541 | M(BelowOrEqual) \ |
| 2542 | M(Above) \ |
| 2543 | M(AboveOrEqual) |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2544 | #define DEFINE_CONDITION_VISITORS(Name) \ |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2545 | void LocationsBuilderARM64::Visit##Name(H##Name* comp) { HandleCondition(comp); } \ |
| 2546 | void InstructionCodeGeneratorARM64::Visit##Name(H##Name* comp) { HandleCondition(comp); } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2547 | FOR_EACH_CONDITION_INSTRUCTION(DEFINE_CONDITION_VISITORS) |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2548 | #undef DEFINE_CONDITION_VISITORS |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2549 | #undef FOR_EACH_CONDITION_INSTRUCTION |
| 2550 | |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2551 | void InstructionCodeGeneratorARM64::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 2552 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2553 | |
| 2554 | LocationSummary* locations = instruction->GetLocations(); |
| 2555 | Location second = locations->InAt(1); |
| 2556 | DCHECK(second.IsConstant()); |
| 2557 | |
| 2558 | Register out = OutputRegister(instruction); |
| 2559 | Register dividend = InputRegisterAt(instruction, 0); |
| 2560 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 2561 | DCHECK(imm == 1 || imm == -1); |
| 2562 | |
| 2563 | if (instruction->IsRem()) { |
| 2564 | __ Mov(out, 0); |
| 2565 | } else { |
| 2566 | if (imm == 1) { |
| 2567 | __ Mov(out, dividend); |
| 2568 | } else { |
| 2569 | __ Neg(out, dividend); |
| 2570 | } |
| 2571 | } |
| 2572 | } |
| 2573 | |
| 2574 | void InstructionCodeGeneratorARM64::DivRemByPowerOfTwo(HBinaryOperation* instruction) { |
| 2575 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2576 | |
| 2577 | LocationSummary* locations = instruction->GetLocations(); |
| 2578 | Location second = locations->InAt(1); |
| 2579 | DCHECK(second.IsConstant()); |
| 2580 | |
| 2581 | Register out = OutputRegister(instruction); |
| 2582 | Register dividend = InputRegisterAt(instruction, 0); |
| 2583 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 2584 | uint64_t abs_imm = static_cast<uint64_t>(AbsOrMin(imm)); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2585 | int ctz_imm = CTZ(abs_imm); |
| 2586 | |
| 2587 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2588 | Register temp = temps.AcquireSameSizeAs(out); |
| 2589 | |
| 2590 | if (instruction->IsDiv()) { |
| 2591 | __ Add(temp, dividend, abs_imm - 1); |
| 2592 | __ Cmp(dividend, 0); |
| 2593 | __ Csel(out, temp, dividend, lt); |
| 2594 | if (imm > 0) { |
| 2595 | __ Asr(out, out, ctz_imm); |
| 2596 | } else { |
| 2597 | __ Neg(out, Operand(out, ASR, ctz_imm)); |
| 2598 | } |
| 2599 | } else { |
| 2600 | int bits = instruction->GetResultType() == Primitive::kPrimInt ? 32 : 64; |
| 2601 | __ Asr(temp, dividend, bits - 1); |
| 2602 | __ Lsr(temp, temp, bits - ctz_imm); |
| 2603 | __ Add(out, dividend, temp); |
| 2604 | __ And(out, out, abs_imm - 1); |
| 2605 | __ Sub(out, out, temp); |
| 2606 | } |
| 2607 | } |
| 2608 | |
| 2609 | void InstructionCodeGeneratorARM64::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 2610 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2611 | |
| 2612 | LocationSummary* locations = instruction->GetLocations(); |
| 2613 | Location second = locations->InAt(1); |
| 2614 | DCHECK(second.IsConstant()); |
| 2615 | |
| 2616 | Register out = OutputRegister(instruction); |
| 2617 | Register dividend = InputRegisterAt(instruction, 0); |
| 2618 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 2619 | |
| 2620 | Primitive::Type type = instruction->GetResultType(); |
| 2621 | DCHECK(type == Primitive::kPrimInt || type == Primitive::kPrimLong); |
| 2622 | |
| 2623 | int64_t magic; |
| 2624 | int shift; |
| 2625 | CalculateMagicAndShiftForDivRem(imm, type == Primitive::kPrimLong /* is_long */, &magic, &shift); |
| 2626 | |
| 2627 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2628 | Register temp = temps.AcquireSameSizeAs(out); |
| 2629 | |
| 2630 | // temp = get_high(dividend * magic) |
| 2631 | __ Mov(temp, magic); |
| 2632 | if (type == Primitive::kPrimLong) { |
| 2633 | __ Smulh(temp, dividend, temp); |
| 2634 | } else { |
| 2635 | __ Smull(temp.X(), dividend, temp); |
| 2636 | __ Lsr(temp.X(), temp.X(), 32); |
| 2637 | } |
| 2638 | |
| 2639 | if (imm > 0 && magic < 0) { |
| 2640 | __ Add(temp, temp, dividend); |
| 2641 | } else if (imm < 0 && magic > 0) { |
| 2642 | __ Sub(temp, temp, dividend); |
| 2643 | } |
| 2644 | |
| 2645 | if (shift != 0) { |
| 2646 | __ Asr(temp, temp, shift); |
| 2647 | } |
| 2648 | |
| 2649 | if (instruction->IsDiv()) { |
| 2650 | __ Sub(out, temp, Operand(temp, ASR, type == Primitive::kPrimLong ? 63 : 31)); |
| 2651 | } else { |
| 2652 | __ Sub(temp, temp, Operand(temp, ASR, type == Primitive::kPrimLong ? 63 : 31)); |
| 2653 | // TODO: Strength reduction for msub. |
| 2654 | Register temp_imm = temps.AcquireSameSizeAs(out); |
| 2655 | __ Mov(temp_imm, imm); |
| 2656 | __ Msub(out, temp, temp_imm, dividend); |
| 2657 | } |
| 2658 | } |
| 2659 | |
| 2660 | void InstructionCodeGeneratorARM64::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 2661 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2662 | Primitive::Type type = instruction->GetResultType(); |
| 2663 | DCHECK(type == Primitive::kPrimInt || Primitive::kPrimLong); |
| 2664 | |
| 2665 | LocationSummary* locations = instruction->GetLocations(); |
| 2666 | Register out = OutputRegister(instruction); |
| 2667 | Location second = locations->InAt(1); |
| 2668 | |
| 2669 | if (second.IsConstant()) { |
| 2670 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 2671 | |
| 2672 | if (imm == 0) { |
| 2673 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 2674 | } else if (imm == 1 || imm == -1) { |
| 2675 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 2676 | } else if (IsPowerOfTwo(AbsOrMin(imm))) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2677 | DivRemByPowerOfTwo(instruction); |
| 2678 | } else { |
| 2679 | DCHECK(imm <= -2 || imm >= 2); |
| 2680 | GenerateDivRemWithAnyConstant(instruction); |
| 2681 | } |
| 2682 | } else { |
| 2683 | Register dividend = InputRegisterAt(instruction, 0); |
| 2684 | Register divisor = InputRegisterAt(instruction, 1); |
| 2685 | if (instruction->IsDiv()) { |
| 2686 | __ Sdiv(out, dividend, divisor); |
| 2687 | } else { |
| 2688 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2689 | Register temp = temps.AcquireSameSizeAs(out); |
| 2690 | __ Sdiv(temp, dividend, divisor); |
| 2691 | __ Msub(out, temp, divisor, dividend); |
| 2692 | } |
| 2693 | } |
| 2694 | } |
| 2695 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2696 | void LocationsBuilderARM64::VisitDiv(HDiv* div) { |
| 2697 | LocationSummary* locations = |
| 2698 | new (GetGraph()->GetArena()) LocationSummary(div, LocationSummary::kNoCall); |
| 2699 | switch (div->GetResultType()) { |
| 2700 | case Primitive::kPrimInt: |
| 2701 | case Primitive::kPrimLong: |
| 2702 | locations->SetInAt(0, Location::RequiresRegister()); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2703 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2704 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2705 | break; |
| 2706 | |
| 2707 | case Primitive::kPrimFloat: |
| 2708 | case Primitive::kPrimDouble: |
| 2709 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2710 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2711 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 2712 | break; |
| 2713 | |
| 2714 | default: |
| 2715 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 2716 | } |
| 2717 | } |
| 2718 | |
| 2719 | void InstructionCodeGeneratorARM64::VisitDiv(HDiv* div) { |
| 2720 | Primitive::Type type = div->GetResultType(); |
| 2721 | switch (type) { |
| 2722 | case Primitive::kPrimInt: |
| 2723 | case Primitive::kPrimLong: |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2724 | GenerateDivRemIntegral(div); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2725 | break; |
| 2726 | |
| 2727 | case Primitive::kPrimFloat: |
| 2728 | case Primitive::kPrimDouble: |
| 2729 | __ Fdiv(OutputFPRegister(div), InputFPRegisterAt(div, 0), InputFPRegisterAt(div, 1)); |
| 2730 | break; |
| 2731 | |
| 2732 | default: |
| 2733 | LOG(FATAL) << "Unexpected div type " << type; |
| 2734 | } |
| 2735 | } |
| 2736 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2737 | void LocationsBuilderARM64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2738 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 2739 | ? LocationSummary::kCallOnSlowPath |
| 2740 | : LocationSummary::kNoCall; |
| 2741 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2742 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
| 2743 | if (instruction->HasUses()) { |
| 2744 | locations->SetOut(Location::SameAsFirstInput()); |
| 2745 | } |
| 2746 | } |
| 2747 | |
| 2748 | void InstructionCodeGeneratorARM64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 2749 | SlowPathCodeARM64* slow_path = |
| 2750 | new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM64(instruction); |
| 2751 | codegen_->AddSlowPath(slow_path); |
| 2752 | Location value = instruction->GetLocations()->InAt(0); |
| 2753 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 2754 | Primitive::Type type = instruction->GetType(); |
| 2755 | |
Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 2756 | if (!Primitive::IsIntegralType(type)) { |
| 2757 | LOG(FATAL) << "Unexpected type " << type << " for DivZeroCheck."; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 2758 | return; |
| 2759 | } |
| 2760 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2761 | if (value.IsConstant()) { |
| 2762 | int64_t divisor = Int64ConstantFrom(value); |
| 2763 | if (divisor == 0) { |
| 2764 | __ B(slow_path->GetEntryLabel()); |
| 2765 | } else { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 2766 | // A division by a non-null constant is valid. We don't need to perform |
| 2767 | // any check, so simply fall through. |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2768 | } |
| 2769 | } else { |
| 2770 | __ Cbz(InputRegisterAt(instruction, 0), slow_path->GetEntryLabel()); |
| 2771 | } |
| 2772 | } |
| 2773 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2774 | void LocationsBuilderARM64::VisitDoubleConstant(HDoubleConstant* constant) { |
| 2775 | LocationSummary* locations = |
| 2776 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 2777 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2778 | } |
| 2779 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2780 | void InstructionCodeGeneratorARM64::VisitDoubleConstant( |
| 2781 | HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2782 | // Will be generated at use site. |
| 2783 | } |
| 2784 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2785 | void LocationsBuilderARM64::VisitExit(HExit* exit) { |
| 2786 | exit->SetLocations(nullptr); |
| 2787 | } |
| 2788 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2789 | void InstructionCodeGeneratorARM64::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2790 | } |
| 2791 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2792 | void LocationsBuilderARM64::VisitFloatConstant(HFloatConstant* constant) { |
| 2793 | LocationSummary* locations = |
| 2794 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 2795 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2796 | } |
| 2797 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2798 | void InstructionCodeGeneratorARM64::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2799 | // Will be generated at use site. |
| 2800 | } |
| 2801 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2802 | void InstructionCodeGeneratorARM64::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2803 | DCHECK(!successor->IsExitBlock()); |
| 2804 | HBasicBlock* block = got->GetBlock(); |
| 2805 | HInstruction* previous = got->GetPrevious(); |
| 2806 | HLoopInformation* info = block->GetLoopInformation(); |
| 2807 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2808 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2809 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck()); |
| 2810 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 2811 | return; |
| 2812 | } |
| 2813 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 2814 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 2815 | } |
| 2816 | if (!codegen_->GoesToNextBlock(block, successor)) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2817 | __ B(codegen_->GetLabelOf(successor)); |
| 2818 | } |
| 2819 | } |
| 2820 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2821 | void LocationsBuilderARM64::VisitGoto(HGoto* got) { |
| 2822 | got->SetLocations(nullptr); |
| 2823 | } |
| 2824 | |
| 2825 | void InstructionCodeGeneratorARM64::VisitGoto(HGoto* got) { |
| 2826 | HandleGoto(got, got->GetSuccessor()); |
| 2827 | } |
| 2828 | |
| 2829 | void LocationsBuilderARM64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 2830 | try_boundary->SetLocations(nullptr); |
| 2831 | } |
| 2832 | |
| 2833 | void InstructionCodeGeneratorARM64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 2834 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 2835 | if (!successor->IsExitBlock()) { |
| 2836 | HandleGoto(try_boundary, successor); |
| 2837 | } |
| 2838 | } |
| 2839 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2840 | void InstructionCodeGeneratorARM64::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2841 | size_t condition_input_index, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2842 | vixl::aarch64::Label* true_target, |
| 2843 | vixl::aarch64::Label* false_target) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2844 | // FP branching requires both targets to be explicit. If either of the targets |
| 2845 | // is nullptr (fallthrough) use and bind `fallthrough_target` instead. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2846 | vixl::aarch64::Label fallthrough_target; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2847 | HInstruction* cond = instruction->InputAt(condition_input_index); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2848 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2849 | if (true_target == nullptr && false_target == nullptr) { |
| 2850 | // Nothing to do. The code always falls through. |
| 2851 | return; |
| 2852 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2853 | // Constant condition, statically compared against "true" (integer value 1). |
| 2854 | if (cond->AsIntConstant()->IsTrue()) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2855 | if (true_target != nullptr) { |
| 2856 | __ B(true_target); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2857 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2858 | } else { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2859 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2860 | if (false_target != nullptr) { |
| 2861 | __ B(false_target); |
| 2862 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2863 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2864 | return; |
| 2865 | } |
| 2866 | |
| 2867 | // The following code generates these patterns: |
| 2868 | // (1) true_target == nullptr && false_target != nullptr |
| 2869 | // - opposite condition true => branch to false_target |
| 2870 | // (2) true_target != nullptr && false_target == nullptr |
| 2871 | // - condition true => branch to true_target |
| 2872 | // (3) true_target != nullptr && false_target != nullptr |
| 2873 | // - condition true => branch to true_target |
| 2874 | // - branch to false_target |
| 2875 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2876 | // The condition instruction has been materialized, compare the output to 0. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2877 | Location cond_val = instruction->GetLocations()->InAt(condition_input_index); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2878 | DCHECK(cond_val.IsRegister()); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2879 | if (true_target == nullptr) { |
| 2880 | __ Cbz(InputRegisterAt(instruction, condition_input_index), false_target); |
| 2881 | } else { |
| 2882 | __ Cbnz(InputRegisterAt(instruction, condition_input_index), true_target); |
| 2883 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2884 | } else { |
| 2885 | // The condition instruction has not been materialized, use its inputs as |
| 2886 | // the comparison and its condition as the branch condition. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2887 | HCondition* condition = cond->AsCondition(); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2888 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2889 | Primitive::Type type = condition->InputAt(0)->GetType(); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2890 | if (Primitive::IsFloatingPointType(type)) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2891 | GenerateFcmp(condition); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2892 | if (true_target == nullptr) { |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 2893 | IfCondition opposite_condition = condition->GetOppositeCondition(); |
| 2894 | __ B(ARM64FPCondition(opposite_condition, condition->IsGtBias()), false_target); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2895 | } else { |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 2896 | __ B(ARM64FPCondition(condition->GetCondition(), condition->IsGtBias()), true_target); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2897 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2898 | } else { |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2899 | // Integer cases. |
| 2900 | Register lhs = InputRegisterAt(condition, 0); |
| 2901 | Operand rhs = InputOperandAt(condition, 1); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2902 | |
| 2903 | Condition arm64_cond; |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2904 | vixl::aarch64::Label* non_fallthrough_target; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2905 | if (true_target == nullptr) { |
| 2906 | arm64_cond = ARM64Condition(condition->GetOppositeCondition()); |
| 2907 | non_fallthrough_target = false_target; |
| 2908 | } else { |
| 2909 | arm64_cond = ARM64Condition(condition->GetCondition()); |
| 2910 | non_fallthrough_target = true_target; |
| 2911 | } |
| 2912 | |
Aart Bik | 086d27e | 2016-01-20 17:02:00 -0800 | [diff] [blame] | 2913 | 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] | 2914 | rhs.IsImmediate() && (rhs.GetImmediate() == 0)) { |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2915 | switch (arm64_cond) { |
| 2916 | case eq: |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2917 | __ Cbz(lhs, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2918 | break; |
| 2919 | case ne: |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2920 | __ Cbnz(lhs, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2921 | break; |
| 2922 | case lt: |
| 2923 | // Test the sign bit and branch accordingly. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2924 | __ Tbnz(lhs, (lhs.IsX() ? kXRegSize : kWRegSize) - 1, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2925 | break; |
| 2926 | case ge: |
| 2927 | // Test the sign bit and branch accordingly. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2928 | __ Tbz(lhs, (lhs.IsX() ? kXRegSize : kWRegSize) - 1, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2929 | break; |
| 2930 | default: |
| 2931 | // Without the `static_cast` the compiler throws an error for |
| 2932 | // `-Werror=sign-promo`. |
| 2933 | LOG(FATAL) << "Unexpected condition: " << static_cast<int>(arm64_cond); |
| 2934 | } |
| 2935 | } else { |
| 2936 | __ Cmp(lhs, rhs); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2937 | __ B(arm64_cond, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2938 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2939 | } |
| 2940 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2941 | |
| 2942 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 2943 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 2944 | if (true_target != nullptr && false_target != nullptr) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2945 | __ B(false_target); |
| 2946 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2947 | |
| 2948 | if (fallthrough_target.IsLinked()) { |
| 2949 | __ Bind(&fallthrough_target); |
| 2950 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2951 | } |
| 2952 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2953 | void LocationsBuilderARM64::VisitIf(HIf* if_instr) { |
| 2954 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2955 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2956 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2957 | } |
| 2958 | } |
| 2959 | |
| 2960 | void InstructionCodeGeneratorARM64::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2961 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 2962 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2963 | vixl::aarch64::Label* true_target = codegen_->GetLabelOf(true_successor); |
| 2964 | if (codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor)) { |
| 2965 | true_target = nullptr; |
| 2966 | } |
| 2967 | vixl::aarch64::Label* false_target = codegen_->GetLabelOf(false_successor); |
| 2968 | if (codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor)) { |
| 2969 | false_target = nullptr; |
| 2970 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2971 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2972 | } |
| 2973 | |
| 2974 | void LocationsBuilderARM64::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 2975 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 2976 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2977 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2978 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2979 | } |
| 2980 | } |
| 2981 | |
| 2982 | void InstructionCodeGeneratorARM64::VisitDeoptimize(HDeoptimize* deoptimize) { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 2983 | SlowPathCodeARM64* slow_path = |
| 2984 | deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathARM64>(deoptimize); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2985 | GenerateTestAndBranch(deoptimize, |
| 2986 | /* condition_input_index */ 0, |
| 2987 | slow_path->GetEntryLabel(), |
| 2988 | /* false_target */ nullptr); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2989 | } |
| 2990 | |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 2991 | static inline bool IsConditionOnFloatingPointValues(HInstruction* condition) { |
| 2992 | return condition->IsCondition() && |
| 2993 | Primitive::IsFloatingPointType(condition->InputAt(0)->GetType()); |
| 2994 | } |
| 2995 | |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 2996 | static inline Condition GetConditionForSelect(HCondition* condition) { |
| 2997 | IfCondition cond = condition->AsCondition()->GetCondition(); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 2998 | return IsConditionOnFloatingPointValues(condition) ? ARM64FPCondition(cond, condition->IsGtBias()) |
| 2999 | : ARM64Condition(cond); |
| 3000 | } |
| 3001 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3002 | void LocationsBuilderARM64::VisitSelect(HSelect* select) { |
| 3003 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(select); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3004 | if (Primitive::IsFloatingPointType(select->GetType())) { |
| 3005 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3006 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3007 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3008 | } else { |
| 3009 | HConstant* cst_true_value = select->GetTrueValue()->AsConstant(); |
| 3010 | HConstant* cst_false_value = select->GetFalseValue()->AsConstant(); |
| 3011 | bool is_true_value_constant = cst_true_value != nullptr; |
| 3012 | bool is_false_value_constant = cst_false_value != nullptr; |
| 3013 | // Ask VIXL whether we should synthesize constants in registers. |
| 3014 | // We give an arbitrary register to VIXL when dealing with non-constant inputs. |
| 3015 | Operand true_op = is_true_value_constant ? |
| 3016 | Operand(Int64FromConstant(cst_true_value)) : Operand(x1); |
| 3017 | Operand false_op = is_false_value_constant ? |
| 3018 | Operand(Int64FromConstant(cst_false_value)) : Operand(x2); |
| 3019 | bool true_value_in_register = false; |
| 3020 | bool false_value_in_register = false; |
| 3021 | MacroAssembler::GetCselSynthesisInformation( |
| 3022 | x0, true_op, false_op, &true_value_in_register, &false_value_in_register); |
| 3023 | true_value_in_register |= !is_true_value_constant; |
| 3024 | false_value_in_register |= !is_false_value_constant; |
| 3025 | |
| 3026 | locations->SetInAt(1, true_value_in_register ? Location::RequiresRegister() |
| 3027 | : Location::ConstantLocation(cst_true_value)); |
| 3028 | locations->SetInAt(0, false_value_in_register ? Location::RequiresRegister() |
| 3029 | : Location::ConstantLocation(cst_false_value)); |
| 3030 | locations->SetOut(Location::RequiresRegister()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3031 | } |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3032 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3033 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
| 3034 | locations->SetInAt(2, Location::RequiresRegister()); |
| 3035 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3036 | } |
| 3037 | |
| 3038 | void InstructionCodeGeneratorARM64::VisitSelect(HSelect* select) { |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3039 | HInstruction* cond = select->GetCondition(); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3040 | Condition csel_cond; |
| 3041 | |
| 3042 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 3043 | if (cond->IsCondition() && cond->GetNext() == select) { |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3044 | // Use the condition flags set by the previous instruction. |
| 3045 | csel_cond = GetConditionForSelect(cond->AsCondition()); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3046 | } else { |
| 3047 | __ Cmp(InputRegisterAt(select, 2), 0); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3048 | csel_cond = ne; |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3049 | } |
| 3050 | } else if (IsConditionOnFloatingPointValues(cond)) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3051 | GenerateFcmp(cond); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3052 | csel_cond = GetConditionForSelect(cond->AsCondition()); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3053 | } else { |
| 3054 | __ Cmp(InputRegisterAt(cond, 0), InputOperandAt(cond, 1)); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3055 | csel_cond = GetConditionForSelect(cond->AsCondition()); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3056 | } |
| 3057 | |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3058 | if (Primitive::IsFloatingPointType(select->GetType())) { |
| 3059 | __ Fcsel(OutputFPRegister(select), |
| 3060 | InputFPRegisterAt(select, 1), |
| 3061 | InputFPRegisterAt(select, 0), |
| 3062 | csel_cond); |
| 3063 | } else { |
| 3064 | __ Csel(OutputRegister(select), |
| 3065 | InputOperandAt(select, 1), |
| 3066 | InputOperandAt(select, 0), |
| 3067 | csel_cond); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3068 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3069 | } |
| 3070 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 3071 | void LocationsBuilderARM64::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| 3072 | new (GetGraph()->GetArena()) LocationSummary(info); |
| 3073 | } |
| 3074 | |
David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 3075 | void InstructionCodeGeneratorARM64::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 3076 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 3077 | } |
| 3078 | |
| 3079 | void CodeGeneratorARM64::GenerateNop() { |
| 3080 | __ Nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 3081 | } |
| 3082 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3083 | void LocationsBuilderARM64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 3084 | HandleFieldGet(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3085 | } |
| 3086 | |
| 3087 | void InstructionCodeGeneratorARM64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 3088 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3089 | } |
| 3090 | |
| 3091 | void LocationsBuilderARM64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 3092 | HandleFieldSet(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3093 | } |
| 3094 | |
| 3095 | void InstructionCodeGeneratorARM64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3096 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3097 | } |
| 3098 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3099 | static bool TypeCheckNeedsATemporary(TypeCheckKind type_check_kind) { |
| 3100 | return kEmitCompilerReadBarrier && |
| 3101 | (kUseBakerReadBarrier || |
| 3102 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 3103 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 3104 | type_check_kind == TypeCheckKind::kArrayObjectCheck); |
| 3105 | } |
| 3106 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3107 | void LocationsBuilderARM64::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3108 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3109 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 3110 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3111 | case TypeCheckKind::kExactCheck: |
| 3112 | case TypeCheckKind::kAbstractClassCheck: |
| 3113 | case TypeCheckKind::kClassHierarchyCheck: |
| 3114 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3115 | call_kind = |
| 3116 | kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3117 | break; |
| 3118 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3119 | case TypeCheckKind::kUnresolvedCheck: |
| 3120 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3121 | call_kind = LocationSummary::kCallOnSlowPath; |
| 3122 | break; |
| 3123 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3124 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3125 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3126 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3127 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3128 | // The "out" register is used as a temporary, so it overlaps with the inputs. |
| 3129 | // Note that TypeCheckSlowPathARM64 uses this register too. |
| 3130 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 3131 | // When read barriers are enabled, we need a temporary register for |
| 3132 | // some cases. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3133 | if (TypeCheckNeedsATemporary(type_check_kind)) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3134 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3135 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3136 | } |
| 3137 | |
| 3138 | void InstructionCodeGeneratorARM64::VisitInstanceOf(HInstanceOf* instruction) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3139 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3140 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3141 | Location obj_loc = locations->InAt(0); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3142 | Register obj = InputRegisterAt(instruction, 0); |
| 3143 | Register cls = InputRegisterAt(instruction, 1); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3144 | Location out_loc = locations->Out(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3145 | Register out = OutputRegister(instruction); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3146 | Location maybe_temp_loc = TypeCheckNeedsATemporary(type_check_kind) ? |
| 3147 | locations->GetTemp(0) : |
| 3148 | Location::NoLocation(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3149 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 3150 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 3151 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 3152 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3153 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3154 | vixl::aarch64::Label done, zero; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3155 | SlowPathCodeARM64* slow_path = nullptr; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3156 | |
| 3157 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 3158 | // Avoid null check if we know `obj` is not null. |
| 3159 | if (instruction->MustDoNullCheck()) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3160 | __ Cbz(obj, &zero); |
| 3161 | } |
| 3162 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3163 | // /* HeapReference<Class> */ out = obj->klass_ |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3164 | GenerateReferenceLoadTwoRegisters(instruction, out_loc, obj_loc, class_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3165 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3166 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3167 | case TypeCheckKind::kExactCheck: { |
| 3168 | __ Cmp(out, cls); |
| 3169 | __ Cset(out, eq); |
| 3170 | if (zero.IsLinked()) { |
| 3171 | __ B(&done); |
| 3172 | } |
| 3173 | break; |
| 3174 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3175 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3176 | case TypeCheckKind::kAbstractClassCheck: { |
| 3177 | // If the class is abstract, we eagerly fetch the super class of the |
| 3178 | // object to avoid doing a comparison we know will fail. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3179 | vixl::aarch64::Label loop, success; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3180 | __ Bind(&loop); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3181 | // /* HeapReference<Class> */ out = out->super_class_ |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3182 | GenerateReferenceLoadOneRegister(instruction, out_loc, super_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3183 | // If `out` is null, we use it for the result, and jump to `done`. |
| 3184 | __ Cbz(out, &done); |
| 3185 | __ Cmp(out, cls); |
| 3186 | __ B(ne, &loop); |
| 3187 | __ Mov(out, 1); |
| 3188 | if (zero.IsLinked()) { |
| 3189 | __ B(&done); |
| 3190 | } |
| 3191 | break; |
| 3192 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3193 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3194 | case TypeCheckKind::kClassHierarchyCheck: { |
| 3195 | // Walk over the class hierarchy to find a match. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3196 | vixl::aarch64::Label loop, success; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3197 | __ Bind(&loop); |
| 3198 | __ Cmp(out, cls); |
| 3199 | __ B(eq, &success); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3200 | // /* HeapReference<Class> */ out = out->super_class_ |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3201 | GenerateReferenceLoadOneRegister(instruction, out_loc, super_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3202 | __ Cbnz(out, &loop); |
| 3203 | // If `out` is null, we use it for the result, and jump to `done`. |
| 3204 | __ B(&done); |
| 3205 | __ Bind(&success); |
| 3206 | __ Mov(out, 1); |
| 3207 | if (zero.IsLinked()) { |
| 3208 | __ B(&done); |
| 3209 | } |
| 3210 | break; |
| 3211 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3212 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3213 | case TypeCheckKind::kArrayObjectCheck: { |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 3214 | // Do an exact check. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3215 | vixl::aarch64::Label exact_check; |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 3216 | __ Cmp(out, cls); |
| 3217 | __ B(eq, &exact_check); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3218 | // 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] | 3219 | // /* HeapReference<Class> */ out = out->component_type_ |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3220 | GenerateReferenceLoadOneRegister(instruction, out_loc, component_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3221 | // If `out` is null, we use it for the result, and jump to `done`. |
| 3222 | __ Cbz(out, &done); |
| 3223 | __ Ldrh(out, HeapOperand(out, primitive_offset)); |
| 3224 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
| 3225 | __ Cbnz(out, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 3226 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3227 | __ Mov(out, 1); |
| 3228 | __ B(&done); |
| 3229 | break; |
| 3230 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3231 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3232 | case TypeCheckKind::kArrayCheck: { |
| 3233 | __ Cmp(out, cls); |
| 3234 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3235 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM64(instruction, |
| 3236 | /* is_fatal */ false); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3237 | codegen_->AddSlowPath(slow_path); |
| 3238 | __ B(ne, slow_path->GetEntryLabel()); |
| 3239 | __ Mov(out, 1); |
| 3240 | if (zero.IsLinked()) { |
| 3241 | __ B(&done); |
| 3242 | } |
| 3243 | break; |
| 3244 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3245 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 3246 | case TypeCheckKind::kUnresolvedCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3247 | case TypeCheckKind::kInterfaceCheck: { |
| 3248 | // Note that we indeed only call on slow path, but we always go |
| 3249 | // into the slow path for the unresolved and interface check |
| 3250 | // cases. |
| 3251 | // |
| 3252 | // We cannot directly call the InstanceofNonTrivial runtime |
| 3253 | // entry point without resorting to a type checking slow path |
| 3254 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 3255 | // require to assign fixed registers for the inputs of this |
| 3256 | // HInstanceOf instruction (following the runtime calling |
| 3257 | // convention), which might be cluttered by the potential first |
| 3258 | // read barrier emission at the beginning of this method. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3259 | // |
| 3260 | // TODO: Introduce a new runtime entry point taking the object |
| 3261 | // to test (instead of its class) as argument, and let it deal |
| 3262 | // with the read barrier issues. This will let us refactor this |
| 3263 | // case of the `switch` code as it was previously (with a direct |
| 3264 | // call to the runtime not using a type checking slow path). |
| 3265 | // This should also be beneficial for the other cases above. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3266 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 3267 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM64(instruction, |
| 3268 | /* is_fatal */ false); |
| 3269 | codegen_->AddSlowPath(slow_path); |
| 3270 | __ B(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3271 | if (zero.IsLinked()) { |
| 3272 | __ B(&done); |
| 3273 | } |
| 3274 | break; |
| 3275 | } |
| 3276 | } |
| 3277 | |
| 3278 | if (zero.IsLinked()) { |
| 3279 | __ Bind(&zero); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 3280 | __ Mov(out, 0); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3281 | } |
| 3282 | |
| 3283 | if (done.IsLinked()) { |
| 3284 | __ Bind(&done); |
| 3285 | } |
| 3286 | |
| 3287 | if (slow_path != nullptr) { |
| 3288 | __ Bind(slow_path->GetExitLabel()); |
| 3289 | } |
| 3290 | } |
| 3291 | |
| 3292 | void LocationsBuilderARM64::VisitCheckCast(HCheckCast* instruction) { |
| 3293 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 3294 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
| 3295 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3296 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 3297 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3298 | case TypeCheckKind::kExactCheck: |
| 3299 | case TypeCheckKind::kAbstractClassCheck: |
| 3300 | case TypeCheckKind::kClassHierarchyCheck: |
| 3301 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3302 | call_kind = (throws_into_catch || kEmitCompilerReadBarrier) ? |
| 3303 | LocationSummary::kCallOnSlowPath : |
| 3304 | LocationSummary::kNoCall; // In fact, call on a fatal (non-returning) slow path. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3305 | break; |
| 3306 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3307 | case TypeCheckKind::kUnresolvedCheck: |
| 3308 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3309 | call_kind = LocationSummary::kCallOnSlowPath; |
| 3310 | break; |
| 3311 | } |
| 3312 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3313 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 3314 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3315 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3316 | // Note that TypeCheckSlowPathARM64 uses this "temp" register too. |
| 3317 | locations->AddTemp(Location::RequiresRegister()); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3318 | // When read barriers are enabled, we need an additional temporary |
| 3319 | // register for some cases. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3320 | if (TypeCheckNeedsATemporary(type_check_kind)) { |
| 3321 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3322 | } |
| 3323 | } |
| 3324 | |
| 3325 | void InstructionCodeGeneratorARM64::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3326 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3327 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3328 | Location obj_loc = locations->InAt(0); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3329 | Register obj = InputRegisterAt(instruction, 0); |
| 3330 | Register cls = InputRegisterAt(instruction, 1); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3331 | Location temp_loc = locations->GetTemp(0); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3332 | Location maybe_temp2_loc = TypeCheckNeedsATemporary(type_check_kind) ? |
| 3333 | locations->GetTemp(1) : |
| 3334 | Location::NoLocation(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3335 | Register temp = WRegisterFrom(temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3336 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 3337 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 3338 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 3339 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3340 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3341 | bool is_type_check_slow_path_fatal = |
| 3342 | (type_check_kind == TypeCheckKind::kExactCheck || |
| 3343 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 3344 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 3345 | type_check_kind == TypeCheckKind::kArrayObjectCheck) && |
| 3346 | !instruction->CanThrowIntoCatchBlock(); |
| 3347 | SlowPathCodeARM64* type_check_slow_path = |
| 3348 | new (GetGraph()->GetArena()) TypeCheckSlowPathARM64(instruction, |
| 3349 | is_type_check_slow_path_fatal); |
| 3350 | codegen_->AddSlowPath(type_check_slow_path); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3351 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3352 | vixl::aarch64::Label done; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3353 | // Avoid null check if we know obj is not null. |
| 3354 | if (instruction->MustDoNullCheck()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 3355 | __ Cbz(obj, &done); |
| 3356 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3357 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3358 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3359 | GenerateReferenceLoadTwoRegisters(instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame] | 3360 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3361 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3362 | case TypeCheckKind::kExactCheck: |
| 3363 | case TypeCheckKind::kArrayCheck: { |
| 3364 | __ Cmp(temp, cls); |
| 3365 | // Jump to slow path for throwing the exception or doing a |
| 3366 | // more involved array check. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3367 | __ B(ne, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3368 | break; |
| 3369 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3370 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3371 | case TypeCheckKind::kAbstractClassCheck: { |
| 3372 | // If the class is abstract, we eagerly fetch the super class of the |
| 3373 | // object to avoid doing a comparison we know will fail. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3374 | vixl::aarch64::Label loop, compare_classes; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3375 | __ Bind(&loop); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3376 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3377 | GenerateReferenceLoadOneRegister(instruction, temp_loc, super_offset, maybe_temp2_loc); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3378 | |
| 3379 | // If the class reference currently in `temp` is not null, jump |
| 3380 | // to the `compare_classes` label to compare it with the checked |
| 3381 | // class. |
| 3382 | __ Cbnz(temp, &compare_classes); |
| 3383 | // Otherwise, jump to the slow path to throw the exception. |
| 3384 | // |
| 3385 | // But before, move back the object's class into `temp` before |
| 3386 | // going into the slow path, as it has been overwritten in the |
| 3387 | // meantime. |
| 3388 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3389 | GenerateReferenceLoadTwoRegisters( |
| 3390 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3391 | __ B(type_check_slow_path->GetEntryLabel()); |
| 3392 | |
| 3393 | __ Bind(&compare_classes); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3394 | __ Cmp(temp, cls); |
| 3395 | __ B(ne, &loop); |
| 3396 | break; |
| 3397 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3398 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3399 | case TypeCheckKind::kClassHierarchyCheck: { |
| 3400 | // Walk over the class hierarchy to find a match. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3401 | vixl::aarch64::Label loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3402 | __ Bind(&loop); |
| 3403 | __ Cmp(temp, cls); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 3404 | __ B(eq, &done); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3405 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3406 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3407 | GenerateReferenceLoadOneRegister(instruction, temp_loc, super_offset, maybe_temp2_loc); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3408 | |
| 3409 | // If the class reference currently in `temp` is not null, jump |
| 3410 | // back at the beginning of the loop. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3411 | __ Cbnz(temp, &loop); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3412 | // Otherwise, jump to the slow path to throw the exception. |
| 3413 | // |
| 3414 | // But before, move back the object's class into `temp` before |
| 3415 | // going into the slow path, as it has been overwritten in the |
| 3416 | // meantime. |
| 3417 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3418 | GenerateReferenceLoadTwoRegisters( |
| 3419 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3420 | __ B(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3421 | break; |
| 3422 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3423 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3424 | case TypeCheckKind::kArrayObjectCheck: { |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 3425 | // Do an exact check. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3426 | vixl::aarch64::Label check_non_primitive_component_type; |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 3427 | __ Cmp(temp, cls); |
| 3428 | __ B(eq, &done); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3429 | |
| 3430 | // 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] | 3431 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3432 | GenerateReferenceLoadOneRegister(instruction, temp_loc, component_offset, maybe_temp2_loc); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3433 | |
| 3434 | // If the component type is not null (i.e. the object is indeed |
| 3435 | // an array), jump to label `check_non_primitive_component_type` |
| 3436 | // to further check that this component type is not a primitive |
| 3437 | // type. |
| 3438 | __ Cbnz(temp, &check_non_primitive_component_type); |
| 3439 | // Otherwise, jump to the slow path to throw the exception. |
| 3440 | // |
| 3441 | // But before, move back the object's class into `temp` before |
| 3442 | // going into the slow path, as it has been overwritten in the |
| 3443 | // meantime. |
| 3444 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3445 | GenerateReferenceLoadTwoRegisters( |
| 3446 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3447 | __ B(type_check_slow_path->GetEntryLabel()); |
| 3448 | |
| 3449 | __ Bind(&check_non_primitive_component_type); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3450 | __ Ldrh(temp, HeapOperand(temp, primitive_offset)); |
| 3451 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3452 | __ Cbz(temp, &done); |
| 3453 | // Same comment as above regarding `temp` and the slow path. |
| 3454 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3455 | GenerateReferenceLoadTwoRegisters( |
| 3456 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3457 | __ B(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3458 | break; |
| 3459 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3460 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 3461 | case TypeCheckKind::kUnresolvedCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3462 | case TypeCheckKind::kInterfaceCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3463 | // We always go into the type check slow path for the unresolved |
| 3464 | // and interface check cases. |
| 3465 | // |
| 3466 | // We cannot directly call the CheckCast runtime entry point |
| 3467 | // without resorting to a type checking slow path here (i.e. by |
| 3468 | // calling InvokeRuntime directly), as it would require to |
| 3469 | // assign fixed registers for the inputs of this HInstanceOf |
| 3470 | // instruction (following the runtime calling convention), which |
| 3471 | // might be cluttered by the potential first read barrier |
| 3472 | // emission at the beginning of this method. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3473 | // |
| 3474 | // TODO: Introduce a new runtime entry point taking the object |
| 3475 | // to test (instead of its class) as argument, and let it deal |
| 3476 | // with the read barrier issues. This will let us refactor this |
| 3477 | // case of the `switch` code as it was previously (with a direct |
| 3478 | // call to the runtime not using a type checking slow path). |
| 3479 | // This should also be beneficial for the other cases above. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3480 | __ B(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3481 | break; |
| 3482 | } |
Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame] | 3483 | __ Bind(&done); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3484 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3485 | __ Bind(type_check_slow_path->GetExitLabel()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3486 | } |
| 3487 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3488 | void LocationsBuilderARM64::VisitIntConstant(HIntConstant* constant) { |
| 3489 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant); |
| 3490 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3491 | } |
| 3492 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3493 | void InstructionCodeGeneratorARM64::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3494 | // Will be generated at use site. |
| 3495 | } |
| 3496 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 3497 | void LocationsBuilderARM64::VisitNullConstant(HNullConstant* constant) { |
| 3498 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant); |
| 3499 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3500 | } |
| 3501 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3502 | void InstructionCodeGeneratorARM64::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 3503 | // Will be generated at use site. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 3504 | } |
| 3505 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 3506 | void LocationsBuilderARM64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 3507 | // The trampoline uses the same calling convention as dex calling conventions, |
| 3508 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 3509 | // the method_idx. |
| 3510 | HandleInvoke(invoke); |
| 3511 | } |
| 3512 | |
| 3513 | void InstructionCodeGeneratorARM64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 3514 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 3515 | } |
| 3516 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3517 | void LocationsBuilderARM64::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 3518 | InvokeDexCallingConventionVisitorARM64 calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 3519 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3520 | } |
| 3521 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3522 | void LocationsBuilderARM64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 3523 | HandleInvoke(invoke); |
| 3524 | } |
| 3525 | |
| 3526 | void InstructionCodeGeneratorARM64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 3527 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3528 | LocationSummary* locations = invoke->GetLocations(); |
| 3529 | Register temp = XRegisterFrom(locations->GetTemp(0)); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3530 | Location receiver = locations->InAt(0); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3531 | Offset class_offset = mirror::Object::ClassOffset(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 3532 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64PointerSize); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3533 | |
| 3534 | // The register ip1 is required to be used for the hidden argument in |
| 3535 | // art_quick_imt_conflict_trampoline, so prevent VIXL from using it. |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 3536 | MacroAssembler* masm = GetVIXLAssembler(); |
| 3537 | UseScratchRegisterScope scratch_scope(masm); |
| 3538 | BlockPoolsScope block_pools(masm); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3539 | scratch_scope.Exclude(ip1); |
| 3540 | __ Mov(ip1, invoke->GetDexMethodIndex()); |
| 3541 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3542 | if (receiver.IsStackSlot()) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 3543 | __ Ldr(temp.W(), StackOperandFrom(receiver)); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3544 | // /* HeapReference<Class> */ temp = temp->klass_ |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 3545 | __ Ldr(temp.W(), HeapOperand(temp.W(), class_offset)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3546 | } else { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3547 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 3548 | __ Ldr(temp.W(), HeapOperandFrom(receiver, class_offset)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3549 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3550 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3551 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 3552 | // emit a read barrier for the previous class reference load. |
| 3553 | // However this is not required in practice, as this is an |
| 3554 | // intermediate/temporary reference and because the current |
| 3555 | // concurrent copying collector keeps the from-space memory |
| 3556 | // intact/accessible until the end of the marking phase (the |
| 3557 | // concurrent copying collector may not in the future). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3558 | GetAssembler()->MaybeUnpoisonHeapReference(temp.W()); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 3559 | __ Ldr(temp, |
| 3560 | MemOperand(temp, mirror::Class::ImtPtrOffset(kArm64PointerSize).Uint32Value())); |
| 3561 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 3562 | invoke->GetImtIndex(), kArm64PointerSize)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3563 | // temp = temp->GetImtEntryAt(method_offset); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 3564 | __ Ldr(temp, MemOperand(temp, method_offset)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3565 | // lr = temp->GetEntryPoint(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 3566 | __ Ldr(lr, MemOperand(temp, entry_point.Int32Value())); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3567 | // lr(); |
| 3568 | __ Blr(lr); |
| 3569 | DCHECK(!codegen_->IsLeafMethod()); |
| 3570 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 3571 | } |
| 3572 | |
| 3573 | void LocationsBuilderARM64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 3574 | IntrinsicLocationsBuilderARM64 intrinsic(GetGraph()->GetArena()); |
| 3575 | if (intrinsic.TryDispatch(invoke)) { |
| 3576 | return; |
| 3577 | } |
| 3578 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3579 | HandleInvoke(invoke); |
| 3580 | } |
| 3581 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 3582 | void LocationsBuilderARM64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 3583 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 3584 | // art::PrepareForRegisterAllocation. |
| 3585 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3586 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 3587 | IntrinsicLocationsBuilderARM64 intrinsic(GetGraph()->GetArena()); |
| 3588 | if (intrinsic.TryDispatch(invoke)) { |
| 3589 | return; |
| 3590 | } |
| 3591 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3592 | HandleInvoke(invoke); |
| 3593 | } |
| 3594 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 3595 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARM64* codegen) { |
| 3596 | if (invoke->GetLocations()->Intrinsified()) { |
| 3597 | IntrinsicCodeGeneratorARM64 intrinsic(codegen); |
| 3598 | intrinsic.Dispatch(invoke); |
| 3599 | return true; |
| 3600 | } |
| 3601 | return false; |
| 3602 | } |
| 3603 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3604 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorARM64::GetSupportedInvokeStaticOrDirectDispatch( |
| 3605 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
| 3606 | MethodReference target_method ATTRIBUTE_UNUSED) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3607 | // On ARM64 we support all dispatch types. |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3608 | return desired_dispatch_info; |
| 3609 | } |
| 3610 | |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 3611 | void CodeGeneratorARM64::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3612 | // For better instruction scheduling we load the direct code pointer before the method pointer. |
| 3613 | bool direct_code_loaded = false; |
| 3614 | switch (invoke->GetCodePtrLocation()) { |
| 3615 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 3616 | // LR = code address from literal pool with link-time patch. |
| 3617 | __ Ldr(lr, DeduplicateMethodCodeLiteral(invoke->GetTargetMethod())); |
| 3618 | direct_code_loaded = true; |
| 3619 | break; |
| 3620 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
| 3621 | // LR = invoke->GetDirectCodePtr(); |
| 3622 | __ Ldr(lr, DeduplicateUint64Literal(invoke->GetDirectCodePtr())); |
| 3623 | direct_code_loaded = true; |
| 3624 | break; |
| 3625 | default: |
| 3626 | break; |
| 3627 | } |
| 3628 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 3629 | // 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] | 3630 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 3631 | switch (invoke->GetMethodLoadKind()) { |
| 3632 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: |
| 3633 | // temp = thread->string_init_entrypoint |
Alexandre Rames | 6dc0174 | 2015-11-12 14:44:19 +0000 | [diff] [blame] | 3634 | __ Ldr(XRegisterFrom(temp), MemOperand(tr, invoke->GetStringInitOffset())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3635 | break; |
| 3636 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3637 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3638 | break; |
| 3639 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 3640 | // Load method address from literal pool. |
Alexandre Rames | 6dc0174 | 2015-11-12 14:44:19 +0000 | [diff] [blame] | 3641 | __ Ldr(XRegisterFrom(temp), DeduplicateUint64Literal(invoke->GetMethodAddress())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3642 | break; |
| 3643 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup: |
| 3644 | // Load method address from literal pool with a link-time patch. |
Alexandre Rames | 6dc0174 | 2015-11-12 14:44:19 +0000 | [diff] [blame] | 3645 | __ Ldr(XRegisterFrom(temp), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3646 | DeduplicateMethodAddressLiteral(invoke->GetTargetMethod())); |
| 3647 | break; |
| 3648 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: { |
| 3649 | // Add ADRP with its PC-relative DexCache access patch. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 3650 | const DexFile& dex_file = *invoke->GetTargetMethod().dex_file; |
| 3651 | uint32_t element_offset = invoke->GetDexCacheArrayOffset(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3652 | vixl::aarch64::Label* adrp_label = NewPcRelativeDexCacheArrayPatch(dex_file, element_offset); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3653 | { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3654 | SingleEmissionCheckScope guard(GetVIXLAssembler()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 3655 | __ Bind(adrp_label); |
| 3656 | __ adrp(XRegisterFrom(temp), /* offset placeholder */ 0); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3657 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3658 | // Add LDR with its PC-relative DexCache access patch. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3659 | vixl::aarch64::Label* ldr_label = |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 3660 | NewPcRelativeDexCacheArrayPatch(dex_file, element_offset, adrp_label); |
Alexandre Rames | 6dc0174 | 2015-11-12 14:44:19 +0000 | [diff] [blame] | 3661 | { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3662 | SingleEmissionCheckScope guard(GetVIXLAssembler()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 3663 | __ Bind(ldr_label); |
| 3664 | __ ldr(XRegisterFrom(temp), MemOperand(XRegisterFrom(temp), /* offset placeholder */ 0)); |
Alexandre Rames | 6dc0174 | 2015-11-12 14:44:19 +0000 | [diff] [blame] | 3665 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3666 | break; |
Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 3667 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3668 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3669 | Location current_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3670 | Register reg = XRegisterFrom(temp); |
| 3671 | Register method_reg; |
| 3672 | if (current_method.IsRegister()) { |
| 3673 | method_reg = XRegisterFrom(current_method); |
| 3674 | } else { |
| 3675 | DCHECK(invoke->GetLocations()->Intrinsified()); |
| 3676 | DCHECK(!current_method.IsValid()); |
| 3677 | method_reg = reg; |
| 3678 | __ Ldr(reg.X(), MemOperand(sp, kCurrentMethodStackOffset)); |
| 3679 | } |
Vladimir Marko | b2c431e | 2015-08-19 12:45:42 +0000 | [diff] [blame] | 3680 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3681 | // /* ArtMethod*[] */ temp = temp.ptr_sized_fields_->dex_cache_resolved_methods_; |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 3682 | __ Ldr(reg.X(), |
| 3683 | MemOperand(method_reg.X(), |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 3684 | ArtMethod::DexCacheResolvedMethodsOffset(kArm64PointerSize).Int32Value())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3685 | // temp = temp[index_in_cache]; |
Vladimir Marko | 40ecb12 | 2016-04-06 17:33:41 +0100 | [diff] [blame] | 3686 | // Note: Don't use invoke->GetTargetMethod() as it may point to a different dex file. |
| 3687 | uint32_t index_in_cache = invoke->GetDexMethodIndex(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3688 | __ Ldr(reg.X(), MemOperand(reg.X(), GetCachePointerOffset(index_in_cache))); |
| 3689 | break; |
| 3690 | } |
| 3691 | } |
| 3692 | |
| 3693 | switch (invoke->GetCodePtrLocation()) { |
| 3694 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 3695 | __ Bl(&frame_entry_label_); |
| 3696 | break; |
| 3697 | case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative: { |
| 3698 | relative_call_patches_.emplace_back(invoke->GetTargetMethod()); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3699 | vixl::aarch64::Label* label = &relative_call_patches_.back().label; |
| 3700 | SingleEmissionCheckScope guard(GetVIXLAssembler()); |
Alexandre Rames | 6dc0174 | 2015-11-12 14:44:19 +0000 | [diff] [blame] | 3701 | __ Bind(label); |
| 3702 | __ 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] | 3703 | break; |
| 3704 | } |
| 3705 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 3706 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
| 3707 | // LR prepared above for better instruction scheduling. |
| 3708 | DCHECK(direct_code_loaded); |
| 3709 | // lr() |
| 3710 | __ Blr(lr); |
| 3711 | break; |
| 3712 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 3713 | // LR = callee_method->entry_point_from_quick_compiled_code_; |
| 3714 | __ Ldr(lr, MemOperand( |
Alexandre Rames | 6dc0174 | 2015-11-12 14:44:19 +0000 | [diff] [blame] | 3715 | XRegisterFrom(callee_method), |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 3716 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64PointerSize).Int32Value())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3717 | // lr() |
| 3718 | __ Blr(lr); |
| 3719 | break; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 3720 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3721 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 3722 | DCHECK(!IsLeafMethod()); |
| 3723 | } |
| 3724 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 3725 | void CodeGeneratorARM64::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_in) { |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 3726 | // Use the calling convention instead of the location of the receiver, as |
| 3727 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 3728 | // slow path, the arguments have been moved to the right place, so here we are |
| 3729 | // guaranteed that the receiver is the first register of the calling convention. |
| 3730 | InvokeDexCallingConvention calling_convention; |
| 3731 | Register receiver = calling_convention.GetRegisterAt(0); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 3732 | Register temp = XRegisterFrom(temp_in); |
| 3733 | size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 3734 | invoke->GetVTableIndex(), kArm64PointerSize).SizeValue(); |
| 3735 | Offset class_offset = mirror::Object::ClassOffset(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 3736 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64PointerSize); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 3737 | |
| 3738 | BlockPoolsScope block_pools(GetVIXLAssembler()); |
| 3739 | |
| 3740 | DCHECK(receiver.IsRegister()); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3741 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 3742 | __ Ldr(temp.W(), HeapOperandFrom(LocationFrom(receiver), class_offset)); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 3743 | MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3744 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 3745 | // emit a read barrier for the previous class reference load. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3746 | // intermediate/temporary reference and because the current |
| 3747 | // concurrent copying collector keeps the from-space memory |
| 3748 | // intact/accessible until the end of the marking phase (the |
| 3749 | // concurrent copying collector may not in the future). |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 3750 | GetAssembler()->MaybeUnpoisonHeapReference(temp.W()); |
| 3751 | // temp = temp->GetMethodAt(method_offset); |
| 3752 | __ Ldr(temp, MemOperand(temp, method_offset)); |
| 3753 | // lr = temp->GetEntryPoint(); |
| 3754 | __ Ldr(lr, MemOperand(temp, entry_point.SizeValue())); |
| 3755 | // lr(); |
| 3756 | __ Blr(lr); |
| 3757 | } |
| 3758 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3759 | vixl::aarch64::Label* CodeGeneratorARM64::NewPcRelativeStringPatch( |
| 3760 | const DexFile& dex_file, |
| 3761 | uint32_t string_index, |
| 3762 | vixl::aarch64::Label* adrp_label) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 3763 | return NewPcRelativePatch(dex_file, string_index, adrp_label, &pc_relative_string_patches_); |
| 3764 | } |
| 3765 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3766 | vixl::aarch64::Label* CodeGeneratorARM64::NewPcRelativeTypePatch( |
| 3767 | const DexFile& dex_file, |
| 3768 | uint32_t type_index, |
| 3769 | vixl::aarch64::Label* adrp_label) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 3770 | return NewPcRelativePatch(dex_file, type_index, adrp_label, &pc_relative_type_patches_); |
| 3771 | } |
| 3772 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3773 | vixl::aarch64::Label* CodeGeneratorARM64::NewPcRelativeDexCacheArrayPatch( |
| 3774 | const DexFile& dex_file, |
| 3775 | uint32_t element_offset, |
| 3776 | vixl::aarch64::Label* adrp_label) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 3777 | return NewPcRelativePatch(dex_file, element_offset, adrp_label, &pc_relative_dex_cache_patches_); |
| 3778 | } |
| 3779 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3780 | vixl::aarch64::Label* CodeGeneratorARM64::NewPcRelativePatch( |
| 3781 | const DexFile& dex_file, |
| 3782 | uint32_t offset_or_index, |
| 3783 | vixl::aarch64::Label* adrp_label, |
| 3784 | ArenaDeque<PcRelativePatchInfo>* patches) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 3785 | // Add a patch entry and return the label. |
| 3786 | patches->emplace_back(dex_file, offset_or_index); |
| 3787 | PcRelativePatchInfo* info = &patches->back(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3788 | vixl::aarch64::Label* label = &info->label; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 3789 | // If adrp_label is null, this is the ADRP patch and needs to point to its own label. |
| 3790 | info->pc_insn_label = (adrp_label != nullptr) ? adrp_label : label; |
| 3791 | return label; |
| 3792 | } |
| 3793 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3794 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateBootImageStringLiteral( |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 3795 | const DexFile& dex_file, uint32_t string_index) { |
| 3796 | return boot_image_string_patches_.GetOrCreate( |
| 3797 | StringReference(&dex_file, string_index), |
| 3798 | [this]() { return __ CreateLiteralDestroyedWithPool<uint32_t>(/* placeholder */ 0u); }); |
| 3799 | } |
| 3800 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3801 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateBootImageTypeLiteral( |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 3802 | const DexFile& dex_file, uint32_t type_index) { |
| 3803 | return boot_image_type_patches_.GetOrCreate( |
| 3804 | TypeReference(&dex_file, type_index), |
| 3805 | [this]() { return __ CreateLiteralDestroyedWithPool<uint32_t>(/* placeholder */ 0u); }); |
| 3806 | } |
| 3807 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3808 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateBootImageAddressLiteral( |
| 3809 | uint64_t address) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 3810 | bool needs_patch = GetCompilerOptions().GetIncludePatchInformation(); |
| 3811 | Uint32ToLiteralMap* map = needs_patch ? &boot_image_address_patches_ : &uint32_literals_; |
| 3812 | return DeduplicateUint32Literal(dchecked_integral_cast<uint32_t>(address), map); |
| 3813 | } |
| 3814 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3815 | vixl::aarch64::Literal<uint64_t>* CodeGeneratorARM64::DeduplicateDexCacheAddressLiteral( |
| 3816 | uint64_t address) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 3817 | return DeduplicateUint64Literal(address); |
| 3818 | } |
| 3819 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3820 | void CodeGeneratorARM64::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) { |
| 3821 | DCHECK(linker_patches->empty()); |
| 3822 | size_t size = |
| 3823 | method_patches_.size() + |
| 3824 | call_patches_.size() + |
| 3825 | relative_call_patches_.size() + |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 3826 | pc_relative_dex_cache_patches_.size() + |
| 3827 | boot_image_string_patches_.size() + |
| 3828 | pc_relative_string_patches_.size() + |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 3829 | boot_image_type_patches_.size() + |
| 3830 | pc_relative_type_patches_.size() + |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 3831 | boot_image_address_patches_.size(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3832 | linker_patches->reserve(size); |
| 3833 | for (const auto& entry : method_patches_) { |
| 3834 | const MethodReference& target_method = entry.first; |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3835 | vixl::aarch64::Literal<uint64_t>* literal = entry.second; |
| 3836 | linker_patches->push_back(LinkerPatch::MethodPatch(literal->GetOffset(), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3837 | target_method.dex_file, |
| 3838 | target_method.dex_method_index)); |
| 3839 | } |
| 3840 | for (const auto& entry : call_patches_) { |
| 3841 | const MethodReference& target_method = entry.first; |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3842 | vixl::aarch64::Literal<uint64_t>* literal = entry.second; |
| 3843 | linker_patches->push_back(LinkerPatch::CodePatch(literal->GetOffset(), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3844 | target_method.dex_file, |
| 3845 | target_method.dex_method_index)); |
| 3846 | } |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3847 | for (const MethodPatchInfo<vixl::aarch64::Label>& info : relative_call_patches_) { |
| 3848 | linker_patches->push_back(LinkerPatch::RelativeCodePatch(info.label.GetLocation(), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3849 | info.target_method.dex_file, |
| 3850 | info.target_method.dex_method_index)); |
| 3851 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 3852 | for (const PcRelativePatchInfo& info : pc_relative_dex_cache_patches_) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3853 | linker_patches->push_back(LinkerPatch::DexCacheArrayPatch(info.label.GetLocation(), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3854 | &info.target_dex_file, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3855 | info.pc_insn_label->GetLocation(), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 3856 | info.offset_or_index)); |
| 3857 | } |
| 3858 | for (const auto& entry : boot_image_string_patches_) { |
| 3859 | const StringReference& target_string = entry.first; |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3860 | vixl::aarch64::Literal<uint32_t>* literal = entry.second; |
| 3861 | linker_patches->push_back(LinkerPatch::StringPatch(literal->GetOffset(), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 3862 | target_string.dex_file, |
| 3863 | target_string.string_index)); |
| 3864 | } |
| 3865 | for (const PcRelativePatchInfo& info : pc_relative_string_patches_) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3866 | linker_patches->push_back(LinkerPatch::RelativeStringPatch(info.label.GetLocation(), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 3867 | &info.target_dex_file, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3868 | info.pc_insn_label->GetLocation(), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 3869 | info.offset_or_index)); |
| 3870 | } |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 3871 | for (const auto& entry : boot_image_type_patches_) { |
| 3872 | const TypeReference& target_type = entry.first; |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3873 | vixl::aarch64::Literal<uint32_t>* literal = entry.second; |
| 3874 | linker_patches->push_back(LinkerPatch::TypePatch(literal->GetOffset(), |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 3875 | target_type.dex_file, |
| 3876 | target_type.type_index)); |
| 3877 | } |
| 3878 | for (const PcRelativePatchInfo& info : pc_relative_type_patches_) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3879 | linker_patches->push_back(LinkerPatch::RelativeTypePatch(info.label.GetLocation(), |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 3880 | &info.target_dex_file, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3881 | info.pc_insn_label->GetLocation(), |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 3882 | info.offset_or_index)); |
| 3883 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 3884 | for (const auto& entry : boot_image_address_patches_) { |
| 3885 | DCHECK(GetCompilerOptions().GetIncludePatchInformation()); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3886 | vixl::aarch64::Literal<uint32_t>* literal = entry.second; |
| 3887 | linker_patches->push_back(LinkerPatch::RecordPosition(literal->GetOffset())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3888 | } |
| 3889 | } |
| 3890 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3891 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateUint32Literal(uint32_t value, |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 3892 | Uint32ToLiteralMap* map) { |
| 3893 | return map->GetOrCreate( |
| 3894 | value, |
| 3895 | [this, value]() { return __ CreateLiteralDestroyedWithPool<uint32_t>(value); }); |
| 3896 | } |
| 3897 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3898 | vixl::aarch64::Literal<uint64_t>* CodeGeneratorARM64::DeduplicateUint64Literal(uint64_t value) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 3899 | return uint64_literals_.GetOrCreate( |
| 3900 | value, |
| 3901 | [this, value]() { return __ CreateLiteralDestroyedWithPool<uint64_t>(value); }); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3902 | } |
| 3903 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3904 | vixl::aarch64::Literal<uint64_t>* CodeGeneratorARM64::DeduplicateMethodLiteral( |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3905 | MethodReference target_method, |
| 3906 | MethodToLiteralMap* map) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 3907 | return map->GetOrCreate( |
| 3908 | target_method, |
| 3909 | [this]() { return __ CreateLiteralDestroyedWithPool<uint64_t>(/* placeholder */ 0u); }); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3910 | } |
| 3911 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3912 | vixl::aarch64::Literal<uint64_t>* CodeGeneratorARM64::DeduplicateMethodAddressLiteral( |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3913 | MethodReference target_method) { |
| 3914 | return DeduplicateMethodLiteral(target_method, &method_patches_); |
| 3915 | } |
| 3916 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3917 | vixl::aarch64::Literal<uint64_t>* CodeGeneratorARM64::DeduplicateMethodCodeLiteral( |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3918 | MethodReference target_method) { |
| 3919 | return DeduplicateMethodLiteral(target_method, &call_patches_); |
| 3920 | } |
| 3921 | |
| 3922 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 3923 | void InstructionCodeGeneratorARM64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 3924 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 3925 | // art::PrepareForRegisterAllocation. |
| 3926 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3927 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 3928 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 3929 | return; |
| 3930 | } |
| 3931 | |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 3932 | BlockPoolsScope block_pools(GetVIXLAssembler()); |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 3933 | LocationSummary* locations = invoke->GetLocations(); |
| 3934 | codegen_->GenerateStaticOrDirectCall( |
| 3935 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 3936 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3937 | } |
| 3938 | |
| 3939 | void InstructionCodeGeneratorARM64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 3940 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 3941 | return; |
| 3942 | } |
| 3943 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 3944 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3945 | DCHECK(!codegen_->IsLeafMethod()); |
| 3946 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 3947 | } |
| 3948 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 3949 | HLoadClass::LoadKind CodeGeneratorARM64::GetSupportedLoadClassKind( |
| 3950 | HLoadClass::LoadKind desired_class_load_kind) { |
| 3951 | if (kEmitCompilerReadBarrier) { |
| 3952 | switch (desired_class_load_kind) { |
| 3953 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: |
| 3954 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
| 3955 | case HLoadClass::LoadKind::kBootImageAddress: |
| 3956 | // TODO: Implement for read barrier. |
| 3957 | return HLoadClass::LoadKind::kDexCacheViaMethod; |
| 3958 | default: |
| 3959 | break; |
| 3960 | } |
| 3961 | } |
| 3962 | switch (desired_class_load_kind) { |
| 3963 | case HLoadClass::LoadKind::kReferrersClass: |
| 3964 | break; |
| 3965 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: |
| 3966 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 3967 | break; |
| 3968 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
| 3969 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 3970 | break; |
| 3971 | case HLoadClass::LoadKind::kBootImageAddress: |
| 3972 | break; |
| 3973 | case HLoadClass::LoadKind::kDexCacheAddress: |
| 3974 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 3975 | break; |
| 3976 | case HLoadClass::LoadKind::kDexCachePcRelative: |
| 3977 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| 3978 | break; |
| 3979 | case HLoadClass::LoadKind::kDexCacheViaMethod: |
| 3980 | break; |
| 3981 | } |
| 3982 | return desired_class_load_kind; |
| 3983 | } |
| 3984 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3985 | void LocationsBuilderARM64::VisitLoadClass(HLoadClass* cls) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 3986 | if (cls->NeedsAccessCheck()) { |
| 3987 | InvokeRuntimeCallingConvention calling_convention; |
| 3988 | CodeGenerator::CreateLoadClassLocationSummary( |
| 3989 | cls, |
| 3990 | LocationFrom(calling_convention.GetRegisterAt(0)), |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3991 | LocationFrom(vixl::aarch64::x0), |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 3992 | /* code_generator_supports_read_barrier */ true); |
| 3993 | return; |
| 3994 | } |
| 3995 | |
| 3996 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || kEmitCompilerReadBarrier) |
| 3997 | ? LocationSummary::kCallOnSlowPath |
| 3998 | : LocationSummary::kNoCall; |
| 3999 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(cls, call_kind); |
| 4000 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
| 4001 | if (load_kind == HLoadClass::LoadKind::kReferrersClass || |
| 4002 | load_kind == HLoadClass::LoadKind::kDexCacheViaMethod) { |
| 4003 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4004 | } |
| 4005 | locations->SetOut(Location::RequiresRegister()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4006 | } |
| 4007 | |
| 4008 | void InstructionCodeGeneratorARM64::VisitLoadClass(HLoadClass* cls) { |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 4009 | if (cls->NeedsAccessCheck()) { |
| 4010 | codegen_->MoveConstant(cls->GetLocations()->GetTemp(0), cls->GetTypeIndex()); |
| 4011 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pInitializeTypeAndVerifyAccess), |
| 4012 | cls, |
| 4013 | cls->GetDexPc(), |
| 4014 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 4015 | CheckEntrypointTypes<kQuickInitializeTypeAndVerifyAccess, void*, uint32_t>(); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 4016 | return; |
| 4017 | } |
| 4018 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4019 | Location out_loc = cls->GetLocations()->Out(); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 4020 | Register out = OutputRegister(cls); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4021 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4022 | bool generate_null_check = false; |
| 4023 | switch (cls->GetLoadKind()) { |
| 4024 | case HLoadClass::LoadKind::kReferrersClass: { |
| 4025 | DCHECK(!cls->CanCallRuntime()); |
| 4026 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 4027 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 4028 | Register current_method = InputRegisterAt(cls, 0); |
| 4029 | GenerateGcRootFieldLoad( |
| 4030 | cls, out_loc, current_method, ArtMethod::DeclaringClassOffset().Int32Value()); |
| 4031 | break; |
| 4032 | } |
| 4033 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: |
| 4034 | DCHECK(!kEmitCompilerReadBarrier); |
| 4035 | __ Ldr(out, codegen_->DeduplicateBootImageTypeLiteral(cls->GetDexFile(), |
| 4036 | cls->GetTypeIndex())); |
| 4037 | break; |
| 4038 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { |
| 4039 | DCHECK(!kEmitCompilerReadBarrier); |
| 4040 | // Add ADRP with its PC-relative type patch. |
| 4041 | const DexFile& dex_file = cls->GetDexFile(); |
| 4042 | uint32_t type_index = cls->GetTypeIndex(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4043 | vixl::aarch64::Label* adrp_label = codegen_->NewPcRelativeTypePatch(dex_file, type_index); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4044 | { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4045 | SingleEmissionCheckScope guard(GetVIXLAssembler()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4046 | __ Bind(adrp_label); |
| 4047 | __ adrp(out.X(), /* offset placeholder */ 0); |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 4048 | } |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4049 | // Add ADD with its PC-relative type patch. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4050 | vixl::aarch64::Label* add_label = |
| 4051 | codegen_->NewPcRelativeTypePatch(dex_file, type_index, adrp_label); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4052 | { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4053 | SingleEmissionCheckScope guard(GetVIXLAssembler()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4054 | __ Bind(add_label); |
| 4055 | __ add(out.X(), out.X(), Operand(/* offset placeholder */ 0)); |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 4056 | } |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4057 | break; |
| 4058 | } |
| 4059 | case HLoadClass::LoadKind::kBootImageAddress: { |
| 4060 | DCHECK(!kEmitCompilerReadBarrier); |
| 4061 | DCHECK(cls->GetAddress() != 0u && IsUint<32>(cls->GetAddress())); |
| 4062 | __ Ldr(out.W(), codegen_->DeduplicateBootImageAddressLiteral(cls->GetAddress())); |
| 4063 | break; |
| 4064 | } |
| 4065 | case HLoadClass::LoadKind::kDexCacheAddress: { |
| 4066 | DCHECK_NE(cls->GetAddress(), 0u); |
| 4067 | // LDR immediate has a 12-bit offset multiplied by the size and for 32-bit loads |
| 4068 | // that gives a 16KiB range. To try and reduce the number of literals if we load |
| 4069 | // multiple types, simply split the dex cache address to a 16KiB aligned base |
| 4070 | // loaded from a literal and the remaining offset embedded in the load. |
| 4071 | static_assert(sizeof(GcRoot<mirror::Class>) == 4u, "Expected GC root to be 4 bytes."); |
| 4072 | DCHECK_ALIGNED(cls->GetAddress(), 4u); |
| 4073 | constexpr size_t offset_bits = /* encoded bits */ 12 + /* scale */ 2; |
| 4074 | uint64_t base_address = cls->GetAddress() & ~MaxInt<uint64_t>(offset_bits); |
| 4075 | uint32_t offset = cls->GetAddress() & MaxInt<uint64_t>(offset_bits); |
| 4076 | __ Ldr(out.X(), codegen_->DeduplicateDexCacheAddressLiteral(base_address)); |
| 4077 | // /* GcRoot<mirror::Class> */ out = *(base_address + offset) |
| 4078 | GenerateGcRootFieldLoad(cls, out_loc, out.X(), offset); |
| 4079 | generate_null_check = !cls->IsInDexCache(); |
| 4080 | break; |
| 4081 | } |
| 4082 | case HLoadClass::LoadKind::kDexCachePcRelative: { |
| 4083 | // Add ADRP with its PC-relative DexCache access patch. |
| 4084 | const DexFile& dex_file = cls->GetDexFile(); |
| 4085 | uint32_t element_offset = cls->GetDexCacheElementOffset(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4086 | vixl::aarch64::Label* adrp_label = |
| 4087 | codegen_->NewPcRelativeDexCacheArrayPatch(dex_file, element_offset); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4088 | { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4089 | SingleEmissionCheckScope guard(GetVIXLAssembler()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4090 | __ Bind(adrp_label); |
| 4091 | __ adrp(out.X(), /* offset placeholder */ 0); |
| 4092 | } |
| 4093 | // Add LDR with its PC-relative DexCache access patch. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4094 | vixl::aarch64::Label* ldr_label = |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4095 | codegen_->NewPcRelativeDexCacheArrayPatch(dex_file, element_offset, adrp_label); |
| 4096 | // /* GcRoot<mirror::Class> */ out = *(base_address + offset) /* PC-relative */ |
| 4097 | GenerateGcRootFieldLoad(cls, out_loc, out.X(), /* offset placeholder */ 0, ldr_label); |
| 4098 | generate_null_check = !cls->IsInDexCache(); |
| 4099 | break; |
| 4100 | } |
| 4101 | case HLoadClass::LoadKind::kDexCacheViaMethod: { |
| 4102 | MemberOffset resolved_types_offset = |
| 4103 | ArtMethod::DexCacheResolvedTypesOffset(kArm64PointerSize); |
| 4104 | // /* GcRoot<mirror::Class>[] */ out = |
| 4105 | // current_method.ptr_sized_fields_->dex_cache_resolved_types_ |
| 4106 | Register current_method = InputRegisterAt(cls, 0); |
| 4107 | __ Ldr(out.X(), MemOperand(current_method, resolved_types_offset.Int32Value())); |
| 4108 | // /* GcRoot<mirror::Class> */ out = out[type_index] |
| 4109 | GenerateGcRootFieldLoad( |
| 4110 | cls, out_loc, out.X(), CodeGenerator::GetCacheOffset(cls->GetTypeIndex())); |
| 4111 | generate_null_check = !cls->IsInDexCache(); |
| 4112 | break; |
| 4113 | } |
| 4114 | } |
| 4115 | |
| 4116 | if (generate_null_check || cls->MustGenerateClinitCheck()) { |
| 4117 | DCHECK(cls->CanCallRuntime()); |
| 4118 | SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM64( |
| 4119 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 4120 | codegen_->AddSlowPath(slow_path); |
| 4121 | if (generate_null_check) { |
| 4122 | __ Cbz(out, slow_path->GetEntryLabel()); |
| 4123 | } |
| 4124 | if (cls->MustGenerateClinitCheck()) { |
| 4125 | GenerateClassInitializationCheck(slow_path, out); |
| 4126 | } else { |
| 4127 | __ Bind(slow_path->GetExitLabel()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4128 | } |
| 4129 | } |
| 4130 | } |
| 4131 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 4132 | static MemOperand GetExceptionTlsAddress() { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4133 | return MemOperand(tr, Thread::ExceptionOffset<kArm64PointerSize>().Int32Value()); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 4134 | } |
| 4135 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4136 | void LocationsBuilderARM64::VisitLoadException(HLoadException* load) { |
| 4137 | LocationSummary* locations = |
| 4138 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 4139 | locations->SetOut(Location::RequiresRegister()); |
| 4140 | } |
| 4141 | |
| 4142 | void InstructionCodeGeneratorARM64::VisitLoadException(HLoadException* instruction) { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 4143 | __ Ldr(OutputRegister(instruction), GetExceptionTlsAddress()); |
| 4144 | } |
| 4145 | |
| 4146 | void LocationsBuilderARM64::VisitClearException(HClearException* clear) { |
| 4147 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 4148 | } |
| 4149 | |
| 4150 | void InstructionCodeGeneratorARM64::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 4151 | __ Str(wzr, GetExceptionTlsAddress()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4152 | } |
| 4153 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4154 | HLoadString::LoadKind CodeGeneratorARM64::GetSupportedLoadStringKind( |
| 4155 | HLoadString::LoadKind desired_string_load_kind) { |
| 4156 | if (kEmitCompilerReadBarrier) { |
| 4157 | switch (desired_string_load_kind) { |
| 4158 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: |
| 4159 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
| 4160 | case HLoadString::LoadKind::kBootImageAddress: |
| 4161 | // TODO: Implement for read barrier. |
| 4162 | return HLoadString::LoadKind::kDexCacheViaMethod; |
| 4163 | default: |
| 4164 | break; |
| 4165 | } |
| 4166 | } |
| 4167 | switch (desired_string_load_kind) { |
| 4168 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: |
| 4169 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 4170 | break; |
| 4171 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
| 4172 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 4173 | break; |
| 4174 | case HLoadString::LoadKind::kBootImageAddress: |
| 4175 | break; |
| 4176 | case HLoadString::LoadKind::kDexCacheAddress: |
Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 4177 | DCHECK(Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4178 | break; |
| 4179 | case HLoadString::LoadKind::kDexCachePcRelative: |
Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 4180 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4181 | break; |
| 4182 | case HLoadString::LoadKind::kDexCacheViaMethod: |
| 4183 | break; |
| 4184 | } |
| 4185 | return desired_string_load_kind; |
| 4186 | } |
| 4187 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4188 | void LocationsBuilderARM64::VisitLoadString(HLoadString* load) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4189 | LocationSummary::CallKind call_kind = (load->NeedsEnvironment() || kEmitCompilerReadBarrier) |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 4190 | ? LocationSummary::kCallOnSlowPath |
| 4191 | : LocationSummary::kNoCall; |
| 4192 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4193 | if (load->GetLoadKind() == HLoadString::LoadKind::kDexCacheViaMethod) { |
| 4194 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4195 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4196 | locations->SetOut(Location::RequiresRegister()); |
| 4197 | } |
| 4198 | |
| 4199 | void InstructionCodeGeneratorARM64::VisitLoadString(HLoadString* load) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4200 | Register out = OutputRegister(load); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4201 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4202 | switch (load->GetLoadKind()) { |
| 4203 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: |
| 4204 | DCHECK(!kEmitCompilerReadBarrier); |
| 4205 | __ Ldr(out, codegen_->DeduplicateBootImageStringLiteral(load->GetDexFile(), |
| 4206 | load->GetStringIndex())); |
| 4207 | return; // No dex cache slow path. |
| 4208 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
| 4209 | DCHECK(!kEmitCompilerReadBarrier); |
| 4210 | // Add ADRP with its PC-relative String patch. |
| 4211 | const DexFile& dex_file = load->GetDexFile(); |
| 4212 | uint32_t string_index = load->GetStringIndex(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4213 | vixl::aarch64::Label* adrp_label = codegen_->NewPcRelativeStringPatch(dex_file, string_index); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4214 | { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4215 | SingleEmissionCheckScope guard(GetVIXLAssembler()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4216 | __ Bind(adrp_label); |
| 4217 | __ adrp(out.X(), /* offset placeholder */ 0); |
| 4218 | } |
| 4219 | // Add ADD with its PC-relative String patch. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4220 | vixl::aarch64::Label* add_label = |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4221 | codegen_->NewPcRelativeStringPatch(dex_file, string_index, adrp_label); |
| 4222 | { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4223 | SingleEmissionCheckScope guard(GetVIXLAssembler()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4224 | __ Bind(add_label); |
| 4225 | __ add(out.X(), out.X(), Operand(/* offset placeholder */ 0)); |
| 4226 | } |
| 4227 | return; // No dex cache slow path. |
| 4228 | } |
| 4229 | case HLoadString::LoadKind::kBootImageAddress: { |
| 4230 | DCHECK(!kEmitCompilerReadBarrier); |
| 4231 | DCHECK(load->GetAddress() != 0u && IsUint<32>(load->GetAddress())); |
| 4232 | __ Ldr(out.W(), codegen_->DeduplicateBootImageAddressLiteral(load->GetAddress())); |
| 4233 | return; // No dex cache slow path. |
| 4234 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4235 | default: |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 4236 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4237 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4238 | |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 4239 | // TODO: Re-add the compiler code to do string dex cache lookup again. |
| 4240 | SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathARM64(load); |
| 4241 | codegen_->AddSlowPath(slow_path); |
| 4242 | __ B(slow_path->GetEntryLabel()); |
| 4243 | __ Bind(slow_path->GetExitLabel()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4244 | } |
| 4245 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4246 | void LocationsBuilderARM64::VisitLongConstant(HLongConstant* constant) { |
| 4247 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant); |
| 4248 | locations->SetOut(Location::ConstantLocation(constant)); |
| 4249 | } |
| 4250 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4251 | void InstructionCodeGeneratorARM64::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4252 | // Will be generated at use site. |
| 4253 | } |
| 4254 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4255 | void LocationsBuilderARM64::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 4256 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4257 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4258 | InvokeRuntimeCallingConvention calling_convention; |
| 4259 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 4260 | } |
| 4261 | |
| 4262 | void InstructionCodeGeneratorARM64::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 4263 | codegen_->InvokeRuntime(instruction->IsEnter() |
| 4264 | ? QUICK_ENTRY_POINT(pLockObject) : QUICK_ENTRY_POINT(pUnlockObject), |
| 4265 | instruction, |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 4266 | instruction->GetDexPc(), |
| 4267 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 4268 | if (instruction->IsEnter()) { |
| 4269 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 4270 | } else { |
| 4271 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 4272 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4273 | } |
| 4274 | |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 4275 | void LocationsBuilderARM64::VisitMul(HMul* mul) { |
| 4276 | LocationSummary* locations = |
| 4277 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 4278 | switch (mul->GetResultType()) { |
| 4279 | case Primitive::kPrimInt: |
| 4280 | case Primitive::kPrimLong: |
| 4281 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4282 | locations->SetInAt(1, Location::RequiresRegister()); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 4283 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 4284 | break; |
| 4285 | |
| 4286 | case Primitive::kPrimFloat: |
| 4287 | case Primitive::kPrimDouble: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 4288 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4289 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4290 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 4291 | break; |
| 4292 | |
| 4293 | default: |
| 4294 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 4295 | } |
| 4296 | } |
| 4297 | |
| 4298 | void InstructionCodeGeneratorARM64::VisitMul(HMul* mul) { |
| 4299 | switch (mul->GetResultType()) { |
| 4300 | case Primitive::kPrimInt: |
| 4301 | case Primitive::kPrimLong: |
| 4302 | __ Mul(OutputRegister(mul), InputRegisterAt(mul, 0), InputRegisterAt(mul, 1)); |
| 4303 | break; |
| 4304 | |
| 4305 | case Primitive::kPrimFloat: |
| 4306 | case Primitive::kPrimDouble: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 4307 | __ Fmul(OutputFPRegister(mul), InputFPRegisterAt(mul, 0), InputFPRegisterAt(mul, 1)); |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 4308 | break; |
| 4309 | |
| 4310 | default: |
| 4311 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 4312 | } |
| 4313 | } |
| 4314 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 4315 | void LocationsBuilderARM64::VisitNeg(HNeg* neg) { |
| 4316 | LocationSummary* locations = |
| 4317 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 4318 | switch (neg->GetResultType()) { |
| 4319 | case Primitive::kPrimInt: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4320 | case Primitive::kPrimLong: |
Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 4321 | locations->SetInAt(0, ARM64EncodableConstantOrRegister(neg->InputAt(0), neg)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4322 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 4323 | break; |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 4324 | |
| 4325 | case Primitive::kPrimFloat: |
| 4326 | case Primitive::kPrimDouble: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4327 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4328 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 4329 | break; |
| 4330 | |
| 4331 | default: |
| 4332 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 4333 | } |
| 4334 | } |
| 4335 | |
| 4336 | void InstructionCodeGeneratorARM64::VisitNeg(HNeg* neg) { |
| 4337 | switch (neg->GetResultType()) { |
| 4338 | case Primitive::kPrimInt: |
| 4339 | case Primitive::kPrimLong: |
| 4340 | __ Neg(OutputRegister(neg), InputOperandAt(neg, 0)); |
| 4341 | break; |
| 4342 | |
| 4343 | case Primitive::kPrimFloat: |
| 4344 | case Primitive::kPrimDouble: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4345 | __ Fneg(OutputFPRegister(neg), InputFPRegisterAt(neg, 0)); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 4346 | break; |
| 4347 | |
| 4348 | default: |
| 4349 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 4350 | } |
| 4351 | } |
| 4352 | |
| 4353 | void LocationsBuilderARM64::VisitNewArray(HNewArray* instruction) { |
| 4354 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4355 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 4356 | InvokeRuntimeCallingConvention calling_convention; |
| 4357 | locations->AddTemp(LocationFrom(calling_convention.GetRegisterAt(0))); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 4358 | locations->SetOut(LocationFrom(x0)); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 4359 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 4360 | locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(2))); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 4361 | } |
| 4362 | |
| 4363 | void InstructionCodeGeneratorARM64::VisitNewArray(HNewArray* instruction) { |
| 4364 | LocationSummary* locations = instruction->GetLocations(); |
| 4365 | InvokeRuntimeCallingConvention calling_convention; |
| 4366 | Register type_index = RegisterFrom(locations->GetTemp(0), Primitive::kPrimInt); |
| 4367 | DCHECK(type_index.Is(w0)); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 4368 | __ Mov(type_index, instruction->GetTypeIndex()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4369 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 4370 | // of poisoning the reference. |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4371 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), |
| 4372 | instruction, |
| 4373 | instruction->GetDexPc(), |
| 4374 | nullptr); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4375 | CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck, void*, uint32_t, int32_t, ArtMethod*>(); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 4376 | } |
| 4377 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4378 | void LocationsBuilderARM64::VisitNewInstance(HNewInstance* instruction) { |
| 4379 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4380 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4381 | InvokeRuntimeCallingConvention calling_convention; |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4382 | if (instruction->IsStringAlloc()) { |
| 4383 | locations->AddTemp(LocationFrom(kArtMethodRegister)); |
| 4384 | } else { |
| 4385 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 4386 | locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(1))); |
| 4387 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4388 | locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimNot)); |
| 4389 | } |
| 4390 | |
| 4391 | void InstructionCodeGeneratorARM64::VisitNewInstance(HNewInstance* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4392 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 4393 | // of poisoning the reference. |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4394 | if (instruction->IsStringAlloc()) { |
| 4395 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 4396 | Location temp = instruction->GetLocations()->GetTemp(0); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4397 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64PointerSize); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4398 | __ Ldr(XRegisterFrom(temp), MemOperand(tr, QUICK_ENTRY_POINT(pNewEmptyString))); |
| 4399 | __ Ldr(lr, MemOperand(XRegisterFrom(temp), code_offset.Int32Value())); |
| 4400 | __ Blr(lr); |
| 4401 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 4402 | } else { |
| 4403 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), |
| 4404 | instruction, |
| 4405 | instruction->GetDexPc(), |
| 4406 | nullptr); |
| 4407 | CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, ArtMethod*>(); |
| 4408 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4409 | } |
| 4410 | |
| 4411 | void LocationsBuilderARM64::VisitNot(HNot* instruction) { |
| 4412 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Alexandre Rames | 4e59651 | 2014-11-07 15:56:50 +0000 | [diff] [blame] | 4413 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 4414 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4415 | } |
| 4416 | |
| 4417 | void InstructionCodeGeneratorARM64::VisitNot(HNot* instruction) { |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 4418 | switch (instruction->GetResultType()) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4419 | case Primitive::kPrimInt: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4420 | case Primitive::kPrimLong: |
Roland Levillain | 55dcfb5 | 2014-10-24 18:09:09 +0100 | [diff] [blame] | 4421 | __ Mvn(OutputRegister(instruction), InputOperandAt(instruction, 0)); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4422 | break; |
| 4423 | |
| 4424 | default: |
| 4425 | LOG(FATAL) << "Unexpected type for not operation " << instruction->GetResultType(); |
| 4426 | } |
| 4427 | } |
| 4428 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4429 | void LocationsBuilderARM64::VisitBooleanNot(HBooleanNot* instruction) { |
| 4430 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 4431 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4432 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4433 | } |
| 4434 | |
| 4435 | void InstructionCodeGeneratorARM64::VisitBooleanNot(HBooleanNot* instruction) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4436 | __ Eor(OutputRegister(instruction), InputRegisterAt(instruction, 0), vixl::aarch64::Operand(1)); |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4437 | } |
| 4438 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4439 | void LocationsBuilderARM64::VisitNullCheck(HNullCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4440 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 4441 | ? LocationSummary::kCallOnSlowPath |
| 4442 | : LocationSummary::kNoCall; |
| 4443 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4444 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4445 | if (instruction->HasUses()) { |
| 4446 | locations->SetOut(Location::SameAsFirstInput()); |
| 4447 | } |
| 4448 | } |
| 4449 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4450 | void CodeGeneratorARM64::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 4451 | if (CanMoveNullCheckToUser(instruction)) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4452 | return; |
| 4453 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4454 | |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 4455 | BlockPoolsScope block_pools(GetVIXLAssembler()); |
| 4456 | Location obj = instruction->GetLocations()->InAt(0); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4457 | __ Ldr(wzr, HeapOperandFrom(obj, Offset(0))); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4458 | RecordPcInfo(instruction, instruction->GetDexPc()); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4459 | } |
| 4460 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4461 | void CodeGeneratorARM64::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4462 | SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM64(instruction); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4463 | AddSlowPath(slow_path); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4464 | |
| 4465 | LocationSummary* locations = instruction->GetLocations(); |
| 4466 | Location obj = locations->InAt(0); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4467 | |
| 4468 | __ Cbz(RegisterFrom(obj, instruction->InputAt(0)->GetType()), slow_path->GetEntryLabel()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4469 | } |
| 4470 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4471 | void InstructionCodeGeneratorARM64::VisitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4472 | codegen_->GenerateNullCheck(instruction); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4473 | } |
| 4474 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4475 | void LocationsBuilderARM64::VisitOr(HOr* instruction) { |
| 4476 | HandleBinaryOp(instruction); |
| 4477 | } |
| 4478 | |
| 4479 | void InstructionCodeGeneratorARM64::VisitOr(HOr* instruction) { |
| 4480 | HandleBinaryOp(instruction); |
| 4481 | } |
| 4482 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 4483 | void LocationsBuilderARM64::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
| 4484 | LOG(FATAL) << "Unreachable"; |
| 4485 | } |
| 4486 | |
| 4487 | void InstructionCodeGeneratorARM64::VisitParallelMove(HParallelMove* instruction) { |
| 4488 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 4489 | } |
| 4490 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4491 | void LocationsBuilderARM64::VisitParameterValue(HParameterValue* instruction) { |
| 4492 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 4493 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 4494 | if (location.IsStackSlot()) { |
| 4495 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 4496 | } else if (location.IsDoubleStackSlot()) { |
| 4497 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 4498 | } |
| 4499 | locations->SetOut(location); |
| 4500 | } |
| 4501 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4502 | void InstructionCodeGeneratorARM64::VisitParameterValue( |
| 4503 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4504 | // Nothing to do, the parameter is already at its location. |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4505 | } |
| 4506 | |
| 4507 | void LocationsBuilderARM64::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 4508 | LocationSummary* locations = |
| 4509 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 4510 | locations->SetOut(LocationFrom(kArtMethodRegister)); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4511 | } |
| 4512 | |
| 4513 | void InstructionCodeGeneratorARM64::VisitCurrentMethod( |
| 4514 | HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
| 4515 | // Nothing to do, the method is already at its location. |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4516 | } |
| 4517 | |
| 4518 | void LocationsBuilderARM64::VisitPhi(HPhi* instruction) { |
| 4519 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4520 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4521 | locations->SetInAt(i, Location::Any()); |
| 4522 | } |
| 4523 | locations->SetOut(Location::Any()); |
| 4524 | } |
| 4525 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4526 | void InstructionCodeGeneratorARM64::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4527 | LOG(FATAL) << "Unreachable"; |
| 4528 | } |
| 4529 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4530 | void LocationsBuilderARM64::VisitRem(HRem* rem) { |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 4531 | Primitive::Type type = rem->GetResultType(); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 4532 | LocationSummary::CallKind call_kind = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4533 | Primitive::IsFloatingPointType(type) ? LocationSummary::kCallOnMainOnly |
| 4534 | : LocationSummary::kNoCall; |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 4535 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind); |
| 4536 | |
| 4537 | switch (type) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4538 | case Primitive::kPrimInt: |
| 4539 | case Primitive::kPrimLong: |
| 4540 | locations->SetInAt(0, Location::RequiresRegister()); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 4541 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4542 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4543 | break; |
| 4544 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 4545 | case Primitive::kPrimFloat: |
| 4546 | case Primitive::kPrimDouble: { |
| 4547 | InvokeRuntimeCallingConvention calling_convention; |
| 4548 | locations->SetInAt(0, LocationFrom(calling_convention.GetFpuRegisterAt(0))); |
| 4549 | locations->SetInAt(1, LocationFrom(calling_convention.GetFpuRegisterAt(1))); |
| 4550 | locations->SetOut(calling_convention.GetReturnLocation(type)); |
| 4551 | |
| 4552 | break; |
| 4553 | } |
| 4554 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4555 | default: |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 4556 | LOG(FATAL) << "Unexpected rem type " << type; |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4557 | } |
| 4558 | } |
| 4559 | |
| 4560 | void InstructionCodeGeneratorARM64::VisitRem(HRem* rem) { |
| 4561 | Primitive::Type type = rem->GetResultType(); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 4562 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4563 | switch (type) { |
| 4564 | case Primitive::kPrimInt: |
| 4565 | case Primitive::kPrimLong: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 4566 | GenerateDivRemIntegral(rem); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4567 | break; |
| 4568 | } |
| 4569 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 4570 | case Primitive::kPrimFloat: |
| 4571 | case Primitive::kPrimDouble: { |
| 4572 | int32_t entry_offset = (type == Primitive::kPrimFloat) ? QUICK_ENTRY_POINT(pFmodf) |
| 4573 | : QUICK_ENTRY_POINT(pFmod); |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 4574 | codegen_->InvokeRuntime(entry_offset, rem, rem->GetDexPc(), nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 4575 | if (type == Primitive::kPrimFloat) { |
| 4576 | CheckEntrypointTypes<kQuickFmodf, float, float, float>(); |
| 4577 | } else { |
| 4578 | CheckEntrypointTypes<kQuickFmod, double, double, double>(); |
| 4579 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 4580 | break; |
| 4581 | } |
| 4582 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4583 | default: |
| 4584 | LOG(FATAL) << "Unexpected rem type " << type; |
Vladimir Marko | 351dddf | 2015-12-11 16:34:46 +0000 | [diff] [blame] | 4585 | UNREACHABLE(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4586 | } |
| 4587 | } |
| 4588 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 4589 | void LocationsBuilderARM64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 4590 | memory_barrier->SetLocations(nullptr); |
| 4591 | } |
| 4592 | |
| 4593 | void InstructionCodeGeneratorARM64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 4594 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 4595 | } |
| 4596 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4597 | void LocationsBuilderARM64::VisitReturn(HReturn* instruction) { |
| 4598 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 4599 | Primitive::Type return_type = instruction->InputAt(0)->GetType(); |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 4600 | locations->SetInAt(0, ARM64ReturnLocation(return_type)); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4601 | } |
| 4602 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4603 | void InstructionCodeGeneratorARM64::VisitReturn(HReturn* instruction ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4604 | codegen_->GenerateFrameExit(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4605 | } |
| 4606 | |
| 4607 | void LocationsBuilderARM64::VisitReturnVoid(HReturnVoid* instruction) { |
| 4608 | instruction->SetLocations(nullptr); |
| 4609 | } |
| 4610 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4611 | void InstructionCodeGeneratorARM64::VisitReturnVoid(HReturnVoid* instruction ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4612 | codegen_->GenerateFrameExit(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4613 | } |
| 4614 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4615 | void LocationsBuilderARM64::VisitRor(HRor* ror) { |
| 4616 | HandleBinaryOp(ror); |
| 4617 | } |
| 4618 | |
| 4619 | void InstructionCodeGeneratorARM64::VisitRor(HRor* ror) { |
| 4620 | HandleBinaryOp(ror); |
| 4621 | } |
| 4622 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4623 | void LocationsBuilderARM64::VisitShl(HShl* shl) { |
| 4624 | HandleShift(shl); |
| 4625 | } |
| 4626 | |
| 4627 | void InstructionCodeGeneratorARM64::VisitShl(HShl* shl) { |
| 4628 | HandleShift(shl); |
| 4629 | } |
| 4630 | |
| 4631 | void LocationsBuilderARM64::VisitShr(HShr* shr) { |
| 4632 | HandleShift(shr); |
| 4633 | } |
| 4634 | |
| 4635 | void InstructionCodeGeneratorARM64::VisitShr(HShr* shr) { |
| 4636 | HandleShift(shr); |
| 4637 | } |
| 4638 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4639 | void LocationsBuilderARM64::VisitSub(HSub* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4640 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4641 | } |
| 4642 | |
| 4643 | void InstructionCodeGeneratorARM64::VisitSub(HSub* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4644 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4645 | } |
| 4646 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4647 | void LocationsBuilderARM64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 4648 | HandleFieldGet(instruction); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4649 | } |
| 4650 | |
| 4651 | void InstructionCodeGeneratorARM64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 4652 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4653 | } |
| 4654 | |
| 4655 | void LocationsBuilderARM64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 4656 | HandleFieldSet(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4657 | } |
| 4658 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4659 | void InstructionCodeGeneratorARM64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4660 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4661 | } |
| 4662 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 4663 | void LocationsBuilderARM64::VisitUnresolvedInstanceFieldGet( |
| 4664 | HUnresolvedInstanceFieldGet* instruction) { |
| 4665 | FieldAccessCallingConventionARM64 calling_convention; |
| 4666 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4667 | instruction, instruction->GetFieldType(), calling_convention); |
| 4668 | } |
| 4669 | |
| 4670 | void InstructionCodeGeneratorARM64::VisitUnresolvedInstanceFieldGet( |
| 4671 | HUnresolvedInstanceFieldGet* instruction) { |
| 4672 | FieldAccessCallingConventionARM64 calling_convention; |
| 4673 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4674 | instruction->GetFieldType(), |
| 4675 | instruction->GetFieldIndex(), |
| 4676 | instruction->GetDexPc(), |
| 4677 | calling_convention); |
| 4678 | } |
| 4679 | |
| 4680 | void LocationsBuilderARM64::VisitUnresolvedInstanceFieldSet( |
| 4681 | HUnresolvedInstanceFieldSet* instruction) { |
| 4682 | FieldAccessCallingConventionARM64 calling_convention; |
| 4683 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4684 | instruction, instruction->GetFieldType(), calling_convention); |
| 4685 | } |
| 4686 | |
| 4687 | void InstructionCodeGeneratorARM64::VisitUnresolvedInstanceFieldSet( |
| 4688 | HUnresolvedInstanceFieldSet* instruction) { |
| 4689 | FieldAccessCallingConventionARM64 calling_convention; |
| 4690 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4691 | instruction->GetFieldType(), |
| 4692 | instruction->GetFieldIndex(), |
| 4693 | instruction->GetDexPc(), |
| 4694 | calling_convention); |
| 4695 | } |
| 4696 | |
| 4697 | void LocationsBuilderARM64::VisitUnresolvedStaticFieldGet( |
| 4698 | HUnresolvedStaticFieldGet* instruction) { |
| 4699 | FieldAccessCallingConventionARM64 calling_convention; |
| 4700 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4701 | instruction, instruction->GetFieldType(), calling_convention); |
| 4702 | } |
| 4703 | |
| 4704 | void InstructionCodeGeneratorARM64::VisitUnresolvedStaticFieldGet( |
| 4705 | HUnresolvedStaticFieldGet* instruction) { |
| 4706 | FieldAccessCallingConventionARM64 calling_convention; |
| 4707 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4708 | instruction->GetFieldType(), |
| 4709 | instruction->GetFieldIndex(), |
| 4710 | instruction->GetDexPc(), |
| 4711 | calling_convention); |
| 4712 | } |
| 4713 | |
| 4714 | void LocationsBuilderARM64::VisitUnresolvedStaticFieldSet( |
| 4715 | HUnresolvedStaticFieldSet* instruction) { |
| 4716 | FieldAccessCallingConventionARM64 calling_convention; |
| 4717 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4718 | instruction, instruction->GetFieldType(), calling_convention); |
| 4719 | } |
| 4720 | |
| 4721 | void InstructionCodeGeneratorARM64::VisitUnresolvedStaticFieldSet( |
| 4722 | HUnresolvedStaticFieldSet* instruction) { |
| 4723 | FieldAccessCallingConventionARM64 calling_convention; |
| 4724 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4725 | instruction->GetFieldType(), |
| 4726 | instruction->GetFieldIndex(), |
| 4727 | instruction->GetDexPc(), |
| 4728 | calling_convention); |
| 4729 | } |
| 4730 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4731 | void LocationsBuilderARM64::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 4732 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
| 4733 | } |
| 4734 | |
| 4735 | void InstructionCodeGeneratorARM64::VisitSuspendCheck(HSuspendCheck* instruction) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4736 | HBasicBlock* block = instruction->GetBlock(); |
| 4737 | if (block->GetLoopInformation() != nullptr) { |
| 4738 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 4739 | // The back edge will generate the suspend check. |
| 4740 | return; |
| 4741 | } |
| 4742 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 4743 | // The goto will generate the suspend check. |
| 4744 | return; |
| 4745 | } |
| 4746 | GenerateSuspendCheck(instruction, nullptr); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4747 | } |
| 4748 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4749 | void LocationsBuilderARM64::VisitThrow(HThrow* instruction) { |
| 4750 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4751 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4752 | InvokeRuntimeCallingConvention calling_convention; |
| 4753 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 4754 | } |
| 4755 | |
| 4756 | void InstructionCodeGeneratorARM64::VisitThrow(HThrow* instruction) { |
| 4757 | codegen_->InvokeRuntime( |
Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 4758 | QUICK_ENTRY_POINT(pDeliverException), instruction, instruction->GetDexPc(), nullptr); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 4759 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4760 | } |
| 4761 | |
| 4762 | void LocationsBuilderARM64::VisitTypeConversion(HTypeConversion* conversion) { |
| 4763 | LocationSummary* locations = |
| 4764 | new (GetGraph()->GetArena()) LocationSummary(conversion, LocationSummary::kNoCall); |
| 4765 | Primitive::Type input_type = conversion->GetInputType(); |
| 4766 | Primitive::Type result_type = conversion->GetResultType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 4767 | DCHECK_NE(input_type, result_type); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4768 | if ((input_type == Primitive::kPrimNot) || (input_type == Primitive::kPrimVoid) || |
| 4769 | (result_type == Primitive::kPrimNot) || (result_type == Primitive::kPrimVoid)) { |
| 4770 | LOG(FATAL) << "Unexpected type conversion from " << input_type << " to " << result_type; |
| 4771 | } |
| 4772 | |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 4773 | if (Primitive::IsFloatingPointType(input_type)) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4774 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4775 | } else { |
| 4776 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4777 | } |
| 4778 | |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 4779 | if (Primitive::IsFloatingPointType(result_type)) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4780 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4781 | } else { |
| 4782 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4783 | } |
| 4784 | } |
| 4785 | |
| 4786 | void InstructionCodeGeneratorARM64::VisitTypeConversion(HTypeConversion* conversion) { |
| 4787 | Primitive::Type result_type = conversion->GetResultType(); |
| 4788 | Primitive::Type input_type = conversion->GetInputType(); |
| 4789 | |
| 4790 | DCHECK_NE(input_type, result_type); |
| 4791 | |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 4792 | if (Primitive::IsIntegralType(result_type) && Primitive::IsIntegralType(input_type)) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4793 | int result_size = Primitive::ComponentSize(result_type); |
| 4794 | int input_size = Primitive::ComponentSize(input_type); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 4795 | int min_size = std::min(result_size, input_size); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4796 | Register output = OutputRegister(conversion); |
| 4797 | Register source = InputRegisterAt(conversion, 0); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 4798 | if (result_type == Primitive::kPrimInt && input_type == Primitive::kPrimLong) { |
Alexandre Rames | 4dff2fd | 2015-08-20 13:36:35 +0100 | [diff] [blame] | 4799 | // 'int' values are used directly as W registers, discarding the top |
| 4800 | // bits, so we don't need to sign-extend and can just perform a move. |
| 4801 | // We do not pass the `kDiscardForSameWReg` argument to force clearing the |
| 4802 | // top 32 bits of the target register. We theoretically could leave those |
| 4803 | // bits unchanged, but we would have to make sure that no code uses a |
| 4804 | // 32bit input value as a 64bit value assuming that the top 32 bits are |
| 4805 | // zero. |
| 4806 | __ Mov(output.W(), source.W()); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 4807 | } else if (result_type == Primitive::kPrimChar || |
| 4808 | (input_type == Primitive::kPrimChar && input_size < result_size)) { |
| 4809 | __ Ubfx(output, |
| 4810 | output.IsX() ? source.X() : source.W(), |
| 4811 | 0, Primitive::ComponentSize(Primitive::kPrimChar) * kBitsPerByte); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4812 | } else { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 4813 | __ Sbfx(output, output.IsX() ? source.X() : source.W(), 0, min_size * kBitsPerByte); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4814 | } |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 4815 | } else if (Primitive::IsFloatingPointType(result_type) && Primitive::IsIntegralType(input_type)) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4816 | __ Scvtf(OutputFPRegister(conversion), InputRegisterAt(conversion, 0)); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 4817 | } else if (Primitive::IsIntegralType(result_type) && Primitive::IsFloatingPointType(input_type)) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4818 | CHECK(result_type == Primitive::kPrimInt || result_type == Primitive::kPrimLong); |
| 4819 | __ Fcvtzs(OutputRegister(conversion), InputFPRegisterAt(conversion, 0)); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 4820 | } else if (Primitive::IsFloatingPointType(result_type) && |
| 4821 | Primitive::IsFloatingPointType(input_type)) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4822 | __ Fcvt(OutputFPRegister(conversion), InputFPRegisterAt(conversion, 0)); |
| 4823 | } else { |
| 4824 | LOG(FATAL) << "Unexpected or unimplemented type conversion from " << input_type |
| 4825 | << " to " << result_type; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4826 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4827 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4828 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 4829 | void LocationsBuilderARM64::VisitUShr(HUShr* ushr) { |
| 4830 | HandleShift(ushr); |
| 4831 | } |
| 4832 | |
| 4833 | void InstructionCodeGeneratorARM64::VisitUShr(HUShr* ushr) { |
| 4834 | HandleShift(ushr); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4835 | } |
| 4836 | |
| 4837 | void LocationsBuilderARM64::VisitXor(HXor* instruction) { |
| 4838 | HandleBinaryOp(instruction); |
| 4839 | } |
| 4840 | |
| 4841 | void InstructionCodeGeneratorARM64::VisitXor(HXor* instruction) { |
| 4842 | HandleBinaryOp(instruction); |
| 4843 | } |
| 4844 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4845 | void LocationsBuilderARM64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 4846 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 4847 | LOG(FATAL) << "Unreachable"; |
| 4848 | } |
| 4849 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4850 | void InstructionCodeGeneratorARM64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 4851 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 4852 | LOG(FATAL) << "Unreachable"; |
| 4853 | } |
| 4854 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 4855 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 4856 | void LocationsBuilderARM64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 4857 | LocationSummary* locations = |
| 4858 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 4859 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4860 | } |
| 4861 | |
| 4862 | void InstructionCodeGeneratorARM64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 4863 | int32_t lower_bound = switch_instr->GetStartValue(); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 4864 | uint32_t num_entries = switch_instr->GetNumEntries(); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 4865 | Register value_reg = InputRegisterAt(switch_instr, 0); |
| 4866 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 4867 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 4868 | // 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] | 4869 | static constexpr int32_t kMaxExpectedSizePerHInstruction = 16 * kInstructionSize; |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 4870 | // ADR has a limited range(+/-1MB), so we set a threshold for the number of HIRs in the graph to |
| 4871 | // make sure we don't emit it if the target may run out of range. |
| 4872 | // TODO: Instead of emitting all jump tables at the end of the code, we could keep track of ADR |
| 4873 | // ranges and emit the tables only as required. |
| 4874 | static constexpr int32_t kJumpTableInstructionThreshold = 1* MB / kMaxExpectedSizePerHInstruction; |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 4875 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 4876 | if (num_entries <= kPackedSwitchCompareJumpThreshold || |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 4877 | // Current instruction id is an upper bound of the number of HIRs in the graph. |
| 4878 | GetGraph()->GetCurrentInstructionId() > kJumpTableInstructionThreshold) { |
| 4879 | // Create a series of compare/jumps. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 4880 | UseScratchRegisterScope temps(codegen_->GetVIXLAssembler()); |
| 4881 | Register temp = temps.AcquireW(); |
| 4882 | __ Subs(temp, value_reg, Operand(lower_bound)); |
| 4883 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 4884 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 4885 | // Jump to successors[0] if value == lower_bound. |
| 4886 | __ B(eq, codegen_->GetLabelOf(successors[0])); |
| 4887 | int32_t last_index = 0; |
| 4888 | for (; num_entries - last_index > 2; last_index += 2) { |
| 4889 | __ Subs(temp, temp, Operand(2)); |
| 4890 | // Jump to successors[last_index + 1] if value < case_value[last_index + 2]. |
| 4891 | __ B(lo, codegen_->GetLabelOf(successors[last_index + 1])); |
| 4892 | // Jump to successors[last_index + 2] if value == case_value[last_index + 2]. |
| 4893 | __ B(eq, codegen_->GetLabelOf(successors[last_index + 2])); |
| 4894 | } |
| 4895 | if (num_entries - last_index == 2) { |
| 4896 | // The last missing case_value. |
| 4897 | __ Cmp(temp, Operand(1)); |
| 4898 | __ B(eq, codegen_->GetLabelOf(successors[last_index + 1])); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 4899 | } |
| 4900 | |
| 4901 | // And the default for any other value. |
| 4902 | if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) { |
| 4903 | __ B(codegen_->GetLabelOf(default_block)); |
| 4904 | } |
| 4905 | } else { |
Alexandre Rames | c01a664 | 2016-04-15 11:54:06 +0100 | [diff] [blame] | 4906 | JumpTableARM64* jump_table = codegen_->CreateJumpTable(switch_instr); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 4907 | |
| 4908 | UseScratchRegisterScope temps(codegen_->GetVIXLAssembler()); |
| 4909 | |
| 4910 | // Below instructions should use at most one blocked register. Since there are two blocked |
| 4911 | // registers, we are free to block one. |
| 4912 | Register temp_w = temps.AcquireW(); |
| 4913 | Register index; |
| 4914 | // Remove the bias. |
| 4915 | if (lower_bound != 0) { |
| 4916 | index = temp_w; |
| 4917 | __ Sub(index, value_reg, Operand(lower_bound)); |
| 4918 | } else { |
| 4919 | index = value_reg; |
| 4920 | } |
| 4921 | |
| 4922 | // Jump to default block if index is out of the range. |
| 4923 | __ Cmp(index, Operand(num_entries)); |
| 4924 | __ B(hs, codegen_->GetLabelOf(default_block)); |
| 4925 | |
| 4926 | // In current VIXL implementation, it won't require any blocked registers to encode the |
| 4927 | // immediate value for Adr. So we are free to use both VIXL blocked registers to reduce the |
| 4928 | // register pressure. |
| 4929 | Register table_base = temps.AcquireX(); |
| 4930 | // Load jump offset from the table. |
| 4931 | __ Adr(table_base, jump_table->GetTableStartLabel()); |
| 4932 | Register jump_offset = temp_w; |
| 4933 | __ Ldr(jump_offset, MemOperand(table_base, index, UXTW, 2)); |
| 4934 | |
| 4935 | // Jump to target block by branching to table_base(pc related) + offset. |
| 4936 | Register target_address = table_base; |
| 4937 | __ Add(target_address, table_base, Operand(jump_offset, SXTW)); |
| 4938 | __ Br(target_address); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 4939 | } |
| 4940 | } |
| 4941 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 4942 | void InstructionCodeGeneratorARM64::GenerateReferenceLoadOneRegister(HInstruction* instruction, |
| 4943 | Location out, |
| 4944 | uint32_t offset, |
| 4945 | Location maybe_temp) { |
| 4946 | Primitive::Type type = Primitive::kPrimNot; |
| 4947 | Register out_reg = RegisterFrom(out, type); |
| 4948 | if (kEmitCompilerReadBarrier) { |
| 4949 | Register temp_reg = RegisterFrom(maybe_temp, type); |
| 4950 | if (kUseBakerReadBarrier) { |
| 4951 | // Load with fast path based Baker's read barrier. |
| 4952 | // /* HeapReference<Object> */ out = *(out + offset) |
| 4953 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 4954 | out, |
| 4955 | out_reg, |
| 4956 | offset, |
| 4957 | temp_reg, |
| 4958 | /* needs_null_check */ false, |
| 4959 | /* use_load_acquire */ false); |
| 4960 | } else { |
| 4961 | // Load with slow path based read barrier. |
| 4962 | // Save the value of `out` into `maybe_temp` before overwriting it |
| 4963 | // in the following move operation, as we will need it for the |
| 4964 | // read barrier below. |
| 4965 | __ Mov(temp_reg, out_reg); |
| 4966 | // /* HeapReference<Object> */ out = *(out + offset) |
| 4967 | __ Ldr(out_reg, HeapOperand(out_reg, offset)); |
| 4968 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
| 4969 | } |
| 4970 | } else { |
| 4971 | // Plain load with no read barrier. |
| 4972 | // /* HeapReference<Object> */ out = *(out + offset) |
| 4973 | __ Ldr(out_reg, HeapOperand(out_reg, offset)); |
| 4974 | GetAssembler()->MaybeUnpoisonHeapReference(out_reg); |
| 4975 | } |
| 4976 | } |
| 4977 | |
| 4978 | void InstructionCodeGeneratorARM64::GenerateReferenceLoadTwoRegisters(HInstruction* instruction, |
| 4979 | Location out, |
| 4980 | Location obj, |
| 4981 | uint32_t offset, |
| 4982 | Location maybe_temp) { |
| 4983 | Primitive::Type type = Primitive::kPrimNot; |
| 4984 | Register out_reg = RegisterFrom(out, type); |
| 4985 | Register obj_reg = RegisterFrom(obj, type); |
| 4986 | if (kEmitCompilerReadBarrier) { |
| 4987 | if (kUseBakerReadBarrier) { |
| 4988 | // Load with fast path based Baker's read barrier. |
| 4989 | Register temp_reg = RegisterFrom(maybe_temp, type); |
| 4990 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 4991 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 4992 | out, |
| 4993 | obj_reg, |
| 4994 | offset, |
| 4995 | temp_reg, |
| 4996 | /* needs_null_check */ false, |
| 4997 | /* use_load_acquire */ false); |
| 4998 | } else { |
| 4999 | // Load with slow path based read barrier. |
| 5000 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 5001 | __ Ldr(out_reg, HeapOperand(obj_reg, offset)); |
| 5002 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 5003 | } |
| 5004 | } else { |
| 5005 | // Plain load with no read barrier. |
| 5006 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 5007 | __ Ldr(out_reg, HeapOperand(obj_reg, offset)); |
| 5008 | GetAssembler()->MaybeUnpoisonHeapReference(out_reg); |
| 5009 | } |
| 5010 | } |
| 5011 | |
| 5012 | void InstructionCodeGeneratorARM64::GenerateGcRootFieldLoad(HInstruction* instruction, |
| 5013 | Location root, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5014 | Register obj, |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5015 | uint32_t offset, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5016 | vixl::aarch64::Label* fixup_label) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5017 | Register root_reg = RegisterFrom(root, Primitive::kPrimNot); |
| 5018 | if (kEmitCompilerReadBarrier) { |
| 5019 | if (kUseBakerReadBarrier) { |
| 5020 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
| 5021 | // Baker's read barrier are used: |
| 5022 | // |
| 5023 | // root = obj.field; |
| 5024 | // if (Thread::Current()->GetIsGcMarking()) { |
| 5025 | // root = ReadBarrier::Mark(root) |
| 5026 | // } |
| 5027 | |
| 5028 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5029 | if (fixup_label == nullptr) { |
| 5030 | __ Ldr(root_reg, MemOperand(obj, offset)); |
| 5031 | } else { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5032 | SingleEmissionCheckScope guard(GetVIXLAssembler()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5033 | __ Bind(fixup_label); |
| 5034 | __ ldr(root_reg, MemOperand(obj, offset)); |
| 5035 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5036 | static_assert( |
| 5037 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 5038 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 5039 | "have different sizes."); |
| 5040 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 5041 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 5042 | "have different sizes."); |
| 5043 | |
| 5044 | // Slow path used to mark the GC root `root`. |
| 5045 | SlowPathCodeARM64* slow_path = |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 5046 | new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathARM64(instruction, root); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5047 | codegen_->AddSlowPath(slow_path); |
| 5048 | |
| 5049 | MacroAssembler* masm = GetVIXLAssembler(); |
| 5050 | UseScratchRegisterScope temps(masm); |
| 5051 | Register temp = temps.AcquireW(); |
| 5052 | // temp = Thread::Current()->GetIsGcMarking() |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5053 | __ Ldr(temp, MemOperand(tr, Thread::IsGcMarkingOffset<kArm64PointerSize>().Int32Value())); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5054 | __ Cbnz(temp, slow_path->GetEntryLabel()); |
| 5055 | __ Bind(slow_path->GetExitLabel()); |
| 5056 | } else { |
| 5057 | // GC root loaded through a slow path for read barriers other |
| 5058 | // than Baker's. |
| 5059 | // /* GcRoot<mirror::Object>* */ root = obj + offset |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5060 | if (fixup_label == nullptr) { |
| 5061 | __ Add(root_reg.X(), obj.X(), offset); |
| 5062 | } else { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5063 | SingleEmissionCheckScope guard(GetVIXLAssembler()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5064 | __ Bind(fixup_label); |
| 5065 | __ add(root_reg.X(), obj.X(), offset); |
| 5066 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5067 | // /* mirror::Object* */ root = root->Read() |
| 5068 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 5069 | } |
| 5070 | } else { |
| 5071 | // Plain GC root load with no read barrier. |
| 5072 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5073 | if (fixup_label == nullptr) { |
| 5074 | __ Ldr(root_reg, MemOperand(obj, offset)); |
| 5075 | } else { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5076 | SingleEmissionCheckScope guard(GetVIXLAssembler()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5077 | __ Bind(fixup_label); |
| 5078 | __ ldr(root_reg, MemOperand(obj, offset)); |
| 5079 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5080 | // Note that GC roots are not affected by heap poisoning, thus we |
| 5081 | // do not have to unpoison `root_reg` here. |
| 5082 | } |
| 5083 | } |
| 5084 | |
| 5085 | void CodeGeneratorARM64::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 5086 | Location ref, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5087 | Register obj, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5088 | uint32_t offset, |
| 5089 | Register temp, |
| 5090 | bool needs_null_check, |
| 5091 | bool use_load_acquire) { |
| 5092 | DCHECK(kEmitCompilerReadBarrier); |
| 5093 | DCHECK(kUseBakerReadBarrier); |
| 5094 | |
| 5095 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 5096 | Location no_index = Location::NoLocation(); |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 5097 | size_t no_scale_factor = 0U; |
| 5098 | GenerateReferenceLoadWithBakerReadBarrier(instruction, |
| 5099 | ref, |
| 5100 | obj, |
| 5101 | offset, |
| 5102 | no_index, |
| 5103 | no_scale_factor, |
| 5104 | temp, |
| 5105 | needs_null_check, |
| 5106 | use_load_acquire); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5107 | } |
| 5108 | |
| 5109 | void CodeGeneratorARM64::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 5110 | Location ref, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5111 | Register obj, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5112 | uint32_t data_offset, |
| 5113 | Location index, |
| 5114 | Register temp, |
| 5115 | bool needs_null_check) { |
| 5116 | DCHECK(kEmitCompilerReadBarrier); |
| 5117 | DCHECK(kUseBakerReadBarrier); |
| 5118 | |
| 5119 | // Array cells are never volatile variables, therefore array loads |
| 5120 | // never use Load-Acquire instructions on ARM64. |
| 5121 | const bool use_load_acquire = false; |
| 5122 | |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 5123 | static_assert( |
| 5124 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 5125 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5126 | // /* HeapReference<Object> */ ref = |
| 5127 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 5128 | size_t scale_factor = Primitive::ComponentSizeShift(Primitive::kPrimNot); |
| 5129 | GenerateReferenceLoadWithBakerReadBarrier(instruction, |
| 5130 | ref, |
| 5131 | obj, |
| 5132 | data_offset, |
| 5133 | index, |
| 5134 | scale_factor, |
| 5135 | temp, |
| 5136 | needs_null_check, |
| 5137 | use_load_acquire); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5138 | } |
| 5139 | |
| 5140 | void CodeGeneratorARM64::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 5141 | Location ref, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5142 | Register obj, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5143 | uint32_t offset, |
| 5144 | Location index, |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 5145 | size_t scale_factor, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5146 | Register temp, |
| 5147 | bool needs_null_check, |
| 5148 | bool use_load_acquire) { |
| 5149 | DCHECK(kEmitCompilerReadBarrier); |
| 5150 | DCHECK(kUseBakerReadBarrier); |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 5151 | // If we are emitting an array load, we should not be using a |
| 5152 | // Load Acquire instruction. In other words: |
| 5153 | // `instruction->IsArrayGet()` => `!use_load_acquire`. |
| 5154 | DCHECK(!instruction->IsArrayGet() || !use_load_acquire); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5155 | |
| 5156 | MacroAssembler* masm = GetVIXLAssembler(); |
| 5157 | UseScratchRegisterScope temps(masm); |
| 5158 | |
| 5159 | // In slow path based read barriers, the read barrier call is |
| 5160 | // inserted after the original load. However, in fast path based |
| 5161 | // Baker's read barriers, we need to perform the load of |
| 5162 | // mirror::Object::monitor_ *before* the original reference load. |
| 5163 | // This load-load ordering is required by the read barrier. |
| 5164 | // The fast path/slow path (for Baker's algorithm) should look like: |
| 5165 | // |
| 5166 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 5167 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 5168 | // HeapReference<Object> ref = *src; // Original reference load. |
| 5169 | // bool is_gray = (rb_state == ReadBarrier::gray_ptr_); |
| 5170 | // if (is_gray) { |
| 5171 | // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path. |
| 5172 | // } |
| 5173 | // |
| 5174 | // Note: the original implementation in ReadBarrier::Barrier is |
| 5175 | // slightly more complex as it performs additional checks that we do |
| 5176 | // not do here for performance reasons. |
| 5177 | |
| 5178 | Primitive::Type type = Primitive::kPrimNot; |
| 5179 | Register ref_reg = RegisterFrom(ref, type); |
| 5180 | DCHECK(obj.IsW()); |
| 5181 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 5182 | |
| 5183 | // /* int32_t */ monitor = obj->monitor_ |
| 5184 | __ Ldr(temp, HeapOperand(obj, monitor_offset)); |
| 5185 | if (needs_null_check) { |
| 5186 | MaybeRecordImplicitNullCheck(instruction); |
| 5187 | } |
| 5188 | // /* LockWord */ lock_word = LockWord(monitor) |
| 5189 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 5190 | "art::LockWord and int32_t have different sizes."); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5191 | |
Vladimir Marko | 877a033 | 2016-07-11 19:30:56 +0100 | [diff] [blame] | 5192 | // Introduce a dependency on the lock_word including rb_state, |
| 5193 | // to prevent load-load reordering, and without using |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5194 | // a memory barrier (which would be more expensive). |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 5195 | // `obj` is unchanged by this operation, but its value now depends |
| 5196 | // on `temp`. |
Vladimir Marko | 877a033 | 2016-07-11 19:30:56 +0100 | [diff] [blame] | 5197 | __ Add(obj.X(), obj.X(), Operand(temp.X(), LSR, 32)); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5198 | |
| 5199 | // The actual reference load. |
| 5200 | if (index.IsValid()) { |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 5201 | // Load types involving an "index". |
| 5202 | if (use_load_acquire) { |
| 5203 | // UnsafeGetObjectVolatile intrinsic case. |
| 5204 | // Register `index` is not an index in an object array, but an |
| 5205 | // offset to an object reference field within object `obj`. |
| 5206 | DCHECK(instruction->IsInvoke()) << instruction->DebugName(); |
| 5207 | DCHECK(instruction->GetLocations()->Intrinsified()); |
| 5208 | DCHECK(instruction->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile) |
| 5209 | << instruction->AsInvoke()->GetIntrinsic(); |
| 5210 | DCHECK_EQ(offset, 0U); |
| 5211 | DCHECK_EQ(scale_factor, 0U); |
| 5212 | DCHECK_EQ(needs_null_check, 0U); |
| 5213 | // /* HeapReference<Object> */ ref = *(obj + index) |
| 5214 | MemOperand field = HeapOperand(obj, XRegisterFrom(index)); |
| 5215 | LoadAcquire(instruction, ref_reg, field, /* needs_null_check */ false); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5216 | } else { |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 5217 | // ArrayGet and UnsafeGetObject intrinsics cases. |
| 5218 | // /* HeapReference<Object> */ ref = *(obj + offset + (index << scale_factor)) |
| 5219 | if (index.IsConstant()) { |
| 5220 | uint32_t computed_offset = offset + (Int64ConstantFrom(index) << scale_factor); |
| 5221 | Load(type, ref_reg, HeapOperand(obj, computed_offset)); |
| 5222 | } else { |
Vladimir Marko | 877a033 | 2016-07-11 19:30:56 +0100 | [diff] [blame] | 5223 | Register temp2 = temps.AcquireW(); |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 5224 | __ Add(temp2, obj, offset); |
| 5225 | Load(type, ref_reg, HeapOperand(temp2, XRegisterFrom(index), LSL, scale_factor)); |
| 5226 | temps.Release(temp2); |
| 5227 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5228 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5229 | } else { |
| 5230 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 5231 | MemOperand field = HeapOperand(obj, offset); |
| 5232 | if (use_load_acquire) { |
| 5233 | LoadAcquire(instruction, ref_reg, field, /* needs_null_check */ false); |
| 5234 | } else { |
| 5235 | Load(type, ref_reg, field); |
| 5236 | } |
| 5237 | } |
| 5238 | |
| 5239 | // Object* ref = ref_addr->AsMirrorPtr() |
| 5240 | GetAssembler()->MaybeUnpoisonHeapReference(ref_reg); |
| 5241 | |
| 5242 | // Slow path used to mark the object `ref` when it is gray. |
| 5243 | SlowPathCodeARM64* slow_path = |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 5244 | new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathARM64(instruction, ref); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5245 | AddSlowPath(slow_path); |
| 5246 | |
| 5247 | // if (rb_state == ReadBarrier::gray_ptr_) |
| 5248 | // ref = ReadBarrier::Mark(ref); |
Vladimir Marko | 877a033 | 2016-07-11 19:30:56 +0100 | [diff] [blame] | 5249 | // Given the numeric representation, it's enough to check the low bit of the rb_state. |
| 5250 | static_assert(ReadBarrier::white_ptr_ == 0, "Expecting white to have value 0"); |
| 5251 | static_assert(ReadBarrier::gray_ptr_ == 1, "Expecting gray to have value 1"); |
| 5252 | static_assert(ReadBarrier::black_ptr_ == 2, "Expecting black to have value 2"); |
| 5253 | __ Tbnz(temp, LockWord::kReadBarrierStateShift, slow_path->GetEntryLabel()); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5254 | __ Bind(slow_path->GetExitLabel()); |
| 5255 | } |
| 5256 | |
| 5257 | void CodeGeneratorARM64::GenerateReadBarrierSlow(HInstruction* instruction, |
| 5258 | Location out, |
| 5259 | Location ref, |
| 5260 | Location obj, |
| 5261 | uint32_t offset, |
| 5262 | Location index) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5263 | DCHECK(kEmitCompilerReadBarrier); |
| 5264 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5265 | // Insert a slow path based read barrier *after* the reference load. |
| 5266 | // |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5267 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 5268 | // reference will be carried out by the runtime within the slow |
| 5269 | // path. |
| 5270 | // |
| 5271 | // Note that `ref` currently does not get unpoisoned (when heap |
| 5272 | // poisoning is enabled), which is alright as the `ref` argument is |
| 5273 | // not used by the artReadBarrierSlow entry point. |
| 5274 | // |
| 5275 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
| 5276 | SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) |
| 5277 | ReadBarrierForHeapReferenceSlowPathARM64(instruction, out, ref, obj, offset, index); |
| 5278 | AddSlowPath(slow_path); |
| 5279 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5280 | __ B(slow_path->GetEntryLabel()); |
| 5281 | __ Bind(slow_path->GetExitLabel()); |
| 5282 | } |
| 5283 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5284 | void CodeGeneratorARM64::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 5285 | Location out, |
| 5286 | Location ref, |
| 5287 | Location obj, |
| 5288 | uint32_t offset, |
| 5289 | Location index) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5290 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5291 | // Baker's read barriers shall be handled by the fast path |
| 5292 | // (CodeGeneratorARM64::GenerateReferenceLoadWithBakerReadBarrier). |
| 5293 | DCHECK(!kUseBakerReadBarrier); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5294 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 5295 | // by the runtime within the slow path. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5296 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5297 | } else if (kPoisonHeapReferences) { |
| 5298 | GetAssembler()->UnpoisonHeapReference(WRegisterFrom(out)); |
| 5299 | } |
| 5300 | } |
| 5301 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5302 | void CodeGeneratorARM64::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 5303 | Location out, |
| 5304 | Location root) { |
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 GC root load. |
| 5308 | // |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5309 | // Note that GC roots are not affected by heap poisoning, so we do |
| 5310 | // not need to do anything special for this here. |
| 5311 | SlowPathCodeARM64* slow_path = |
| 5312 | new (GetGraph()->GetArena()) ReadBarrierForRootSlowPathARM64(instruction, out, root); |
| 5313 | AddSlowPath(slow_path); |
| 5314 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5315 | __ B(slow_path->GetEntryLabel()); |
| 5316 | __ Bind(slow_path->GetExitLabel()); |
| 5317 | } |
| 5318 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 5319 | void LocationsBuilderARM64::VisitClassTableGet(HClassTableGet* instruction) { |
| 5320 | LocationSummary* locations = |
| 5321 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 5322 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5323 | locations->SetOut(Location::RequiresRegister()); |
| 5324 | } |
| 5325 | |
| 5326 | void InstructionCodeGeneratorARM64::VisitClassTableGet(HClassTableGet* instruction) { |
| 5327 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5328 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 5329 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 5330 | instruction->GetIndex(), kArm64PointerSize).SizeValue(); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 5331 | __ Ldr(XRegisterFrom(locations->Out()), |
| 5332 | MemOperand(XRegisterFrom(locations->InAt(0)), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 5333 | } else { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 5334 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 5335 | instruction->GetIndex(), kArm64PointerSize)); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 5336 | __ Ldr(XRegisterFrom(locations->Out()), MemOperand(XRegisterFrom(locations->InAt(0)), |
| 5337 | mirror::Class::ImtPtrOffset(kArm64PointerSize).Uint32Value())); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 5338 | __ Ldr(XRegisterFrom(locations->Out()), |
| 5339 | MemOperand(XRegisterFrom(locations->Out()), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 5340 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 5341 | } |
| 5342 | |
| 5343 | |
| 5344 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5345 | #undef __ |
| 5346 | #undef QUICK_ENTRY_POINT |
| 5347 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5348 | } // namespace arm64 |
| 5349 | } // namespace art |