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 | |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 19 | #include "arch/arm64/asm_support_arm64.h" |
Serban Constantinescu | 579885a | 2015-02-22 20:51:33 +0000 | [diff] [blame] | 20 | #include "arch/arm64/instruction_set_features_arm64.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 21 | #include "art_method.h" |
Andreas Gampe | 5678db5 | 2017-06-08 14:11:18 -0700 | [diff] [blame] | 22 | #include "base/bit_utils.h" |
| 23 | #include "base/bit_utils_iterator.h" |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 24 | #include "class_table.h" |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 25 | #include "code_generator_utils.h" |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 26 | #include "compiled_method.h" |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 27 | #include "entrypoints/quick/quick_entrypoints.h" |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 28 | #include "entrypoints/quick/quick_entrypoints_enum.h" |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 29 | #include "gc/accounting/card_table.h" |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 30 | #include "gc/space/image_space.h" |
Andreas Gampe | 09659c2 | 2017-09-18 18:23:32 -0700 | [diff] [blame] | 31 | #include "heap_poisoning.h" |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 32 | #include "intrinsics.h" |
| 33 | #include "intrinsics_arm64.h" |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 34 | #include "linker/linker_patch.h" |
Andreas Gampe | 8cf9cb3 | 2017-07-19 09:28:38 -0700 | [diff] [blame] | 35 | #include "lock_word.h" |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 36 | #include "mirror/array-inl.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 37 | #include "mirror/class-inl.h" |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 38 | #include "offsets.h" |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 39 | #include "thread.h" |
| 40 | #include "utils/arm64/assembler_arm64.h" |
| 41 | #include "utils/assembler.h" |
| 42 | #include "utils/stack_checks.h" |
| 43 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 44 | using namespace vixl::aarch64; // NOLINT(build/namespaces) |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 45 | using vixl::ExactAssemblyScope; |
| 46 | using vixl::CodeBufferCheckScope; |
| 47 | using vixl::EmissionCheckScope; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 48 | |
| 49 | #ifdef __ |
| 50 | #error "ARM64 Codegen VIXL macro-assembler macro already defined." |
| 51 | #endif |
| 52 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 53 | namespace art { |
| 54 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 55 | template<class MirrorType> |
| 56 | class GcRoot; |
| 57 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 58 | namespace arm64 { |
| 59 | |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 60 | using helpers::ARM64EncodableConstantOrRegister; |
| 61 | using helpers::ArtVixlRegCodeCoherentForRegSet; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 62 | using helpers::CPURegisterFrom; |
| 63 | using helpers::DRegisterFrom; |
| 64 | using helpers::FPRegisterFrom; |
| 65 | using helpers::HeapOperand; |
| 66 | using helpers::HeapOperandFrom; |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 67 | using helpers::InputCPURegisterOrZeroRegAt; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 68 | using helpers::InputFPRegisterAt; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 69 | using helpers::InputOperandAt; |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 70 | using helpers::InputRegisterAt; |
Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 71 | using helpers::Int64FromLocation; |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 72 | using helpers::IsConstantZeroBitPattern; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 73 | using helpers::LocationFrom; |
| 74 | using helpers::OperandFromMemOperand; |
| 75 | using helpers::OutputCPURegister; |
| 76 | using helpers::OutputFPRegister; |
| 77 | using helpers::OutputRegister; |
Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 78 | using helpers::QRegisterFrom; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 79 | using helpers::RegisterFrom; |
| 80 | using helpers::StackOperandFrom; |
| 81 | using helpers::VIXLRegCodeFromART; |
| 82 | using helpers::WRegisterFrom; |
| 83 | using helpers::XRegisterFrom; |
| 84 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 85 | // 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] | 86 | // table version generates 7 instructions and num_entries literals. Compare/jump sequence will |
| 87 | // generates less code/data with a small num_entries. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 88 | static constexpr uint32_t kPackedSwitchCompareJumpThreshold = 7; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 89 | |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 90 | // Reference load (except object array loads) is using LDR Wt, [Xn, #offset] which can handle |
| 91 | // offset < 16KiB. For offsets >= 16KiB, the load shall be emitted as two or more instructions. |
| 92 | // For the Baker read barrier implementation using link-generated thunks we need to split |
| 93 | // the offset explicitly. |
| 94 | constexpr uint32_t kReferenceLoadMinFarOffset = 16 * KB; |
| 95 | |
| 96 | // Flags controlling the use of link-time generated thunks for Baker read barriers. |
Vladimir Marko | d1ef873 | 2017-04-18 13:55:13 +0100 | [diff] [blame] | 97 | constexpr bool kBakerReadBarrierLinkTimeThunksEnableForFields = true; |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 98 | constexpr bool kBakerReadBarrierLinkTimeThunksEnableForArrays = true; |
Vladimir Marko | d1ef873 | 2017-04-18 13:55:13 +0100 | [diff] [blame] | 99 | constexpr bool kBakerReadBarrierLinkTimeThunksEnableForGcRoots = true; |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 100 | |
| 101 | // Some instructions have special requirements for a temporary, for example |
| 102 | // LoadClass/kBssEntry and LoadString/kBssEntry for Baker read barrier require |
| 103 | // temp that's not an R0 (to avoid an extra move) and Baker read barrier field |
| 104 | // loads with large offsets need a fixed register to limit the number of link-time |
| 105 | // thunks we generate. For these and similar cases, we want to reserve a specific |
| 106 | // register that's neither callee-save nor an argument register. We choose x15. |
| 107 | inline Location FixedTempLocation() { |
| 108 | return Location::RegisterLocation(x15.GetCode()); |
| 109 | } |
| 110 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 111 | inline Condition ARM64Condition(IfCondition cond) { |
| 112 | switch (cond) { |
| 113 | case kCondEQ: return eq; |
| 114 | case kCondNE: return ne; |
| 115 | case kCondLT: return lt; |
| 116 | case kCondLE: return le; |
| 117 | case kCondGT: return gt; |
| 118 | case kCondGE: return ge; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 119 | case kCondB: return lo; |
| 120 | case kCondBE: return ls; |
| 121 | case kCondA: return hi; |
| 122 | case kCondAE: return hs; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 123 | } |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 124 | LOG(FATAL) << "Unreachable"; |
| 125 | UNREACHABLE(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 126 | } |
| 127 | |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 128 | inline Condition ARM64FPCondition(IfCondition cond, bool gt_bias) { |
| 129 | // The ARM64 condition codes can express all the necessary branches, see the |
| 130 | // "Meaning (floating-point)" column in the table C1-1 in the ARMv8 reference manual. |
| 131 | // There is no dex instruction or HIR that would need the missing conditions |
| 132 | // "equal or unordered" or "not equal". |
| 133 | switch (cond) { |
| 134 | case kCondEQ: return eq; |
| 135 | case kCondNE: return ne /* unordered */; |
| 136 | case kCondLT: return gt_bias ? cc : lt /* unordered */; |
| 137 | case kCondLE: return gt_bias ? ls : le /* unordered */; |
| 138 | case kCondGT: return gt_bias ? hi /* unordered */ : gt; |
| 139 | case kCondGE: return gt_bias ? cs /* unordered */ : ge; |
| 140 | default: |
| 141 | LOG(FATAL) << "UNREACHABLE"; |
| 142 | UNREACHABLE(); |
| 143 | } |
| 144 | } |
| 145 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 146 | Location ARM64ReturnLocation(DataType::Type return_type) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 147 | // Note that in practice, `LocationFrom(x0)` and `LocationFrom(w0)` create the |
| 148 | // same Location object, and so do `LocationFrom(d0)` and `LocationFrom(s0)`, |
| 149 | // but we use the exact registers for clarity. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 150 | if (return_type == DataType::Type::kFloat32) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 151 | return LocationFrom(s0); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 152 | } else if (return_type == DataType::Type::kFloat64) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 153 | return LocationFrom(d0); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 154 | } else if (return_type == DataType::Type::kInt64) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 155 | return LocationFrom(x0); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 156 | } else if (return_type == DataType::Type::kVoid) { |
Nicolas Geoffray | 925e562 | 2015-06-03 12:23:32 +0100 | [diff] [blame] | 157 | return Location::NoLocation(); |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 158 | } else { |
| 159 | return LocationFrom(w0); |
| 160 | } |
| 161 | } |
| 162 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 163 | Location InvokeRuntimeCallingConvention::GetReturnLocation(DataType::Type return_type) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 164 | return ARM64ReturnLocation(return_type); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 165 | } |
| 166 | |
Vladimir Marko | 3232dbb | 2018-07-25 15:42:46 +0100 | [diff] [blame] | 167 | static RegisterSet OneRegInReferenceOutSaveEverythingCallerSaves() { |
| 168 | InvokeRuntimeCallingConvention calling_convention; |
| 169 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 170 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0).GetCode())); |
| 171 | DCHECK_EQ(calling_convention.GetRegisterAt(0).GetCode(), |
| 172 | RegisterFrom(calling_convention.GetReturnLocation(DataType::Type::kReference), |
| 173 | DataType::Type::kReference).GetCode()); |
| 174 | return caller_saves; |
| 175 | } |
| 176 | |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 177 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 178 | #define __ down_cast<CodeGeneratorARM64*>(codegen)->GetVIXLAssembler()-> // NOLINT |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 179 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kArm64PointerSize, x).Int32Value() |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 180 | |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 181 | // Calculate memory accessing operand for save/restore live registers. |
| 182 | static void SaveRestoreLiveRegistersHelper(CodeGenerator* codegen, |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 183 | LocationSummary* locations, |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 184 | int64_t spill_offset, |
| 185 | bool is_save) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 186 | const uint32_t core_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ true); |
| 187 | const uint32_t fp_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ false); |
| 188 | DCHECK(ArtVixlRegCodeCoherentForRegSet(core_spills, |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 189 | codegen->GetNumberOfCoreRegisters(), |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 190 | fp_spills, |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 191 | codegen->GetNumberOfFloatingPointRegisters())); |
| 192 | |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 193 | CPURegList core_list = CPURegList(CPURegister::kRegister, kXRegSize, core_spills); |
Artem Serov | 7957d95 | 2017-04-04 15:44:09 +0100 | [diff] [blame] | 194 | unsigned v_reg_size = codegen->GetGraph()->HasSIMD() ? kQRegSize : kDRegSize; |
| 195 | CPURegList fp_list = CPURegList(CPURegister::kVRegister, v_reg_size, fp_spills); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 196 | |
| 197 | MacroAssembler* masm = down_cast<CodeGeneratorARM64*>(codegen)->GetVIXLAssembler(); |
| 198 | UseScratchRegisterScope temps(masm); |
| 199 | |
| 200 | Register base = masm->StackPointer(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 201 | int64_t core_spill_size = core_list.GetTotalSizeInBytes(); |
| 202 | int64_t fp_spill_size = fp_list.GetTotalSizeInBytes(); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 203 | int64_t reg_size = kXRegSizeInBytes; |
| 204 | int64_t max_ls_pair_offset = spill_offset + core_spill_size + fp_spill_size - 2 * reg_size; |
| 205 | uint32_t ls_access_size = WhichPowerOf2(reg_size); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 206 | if (((core_list.GetCount() > 1) || (fp_list.GetCount() > 1)) && |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 207 | !masm->IsImmLSPair(max_ls_pair_offset, ls_access_size)) { |
| 208 | // If the offset does not fit in the instruction's immediate field, use an alternate register |
| 209 | // to compute the base address(float point registers spill base address). |
| 210 | Register new_base = temps.AcquireSameSizeAs(base); |
| 211 | __ Add(new_base, base, Operand(spill_offset + core_spill_size)); |
| 212 | base = new_base; |
| 213 | spill_offset = -core_spill_size; |
| 214 | int64_t new_max_ls_pair_offset = fp_spill_size - 2 * reg_size; |
| 215 | DCHECK(masm->IsImmLSPair(spill_offset, ls_access_size)); |
| 216 | DCHECK(masm->IsImmLSPair(new_max_ls_pair_offset, ls_access_size)); |
| 217 | } |
| 218 | |
| 219 | if (is_save) { |
| 220 | __ StoreCPURegList(core_list, MemOperand(base, spill_offset)); |
| 221 | __ StoreCPURegList(fp_list, MemOperand(base, spill_offset + core_spill_size)); |
| 222 | } else { |
| 223 | __ LoadCPURegList(core_list, MemOperand(base, spill_offset)); |
| 224 | __ LoadCPURegList(fp_list, MemOperand(base, spill_offset + core_spill_size)); |
| 225 | } |
| 226 | } |
| 227 | |
| 228 | void SlowPathCodeARM64::SaveLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) { |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 229 | size_t stack_offset = codegen->GetFirstRegisterSlotInSlowPath(); |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 230 | const uint32_t core_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ true); |
| 231 | for (uint32_t i : LowToHighBits(core_spills)) { |
| 232 | // If the register holds an object, update the stack mask. |
| 233 | if (locations->RegisterContainsObject(i)) { |
| 234 | locations->SetStackBit(stack_offset / kVRegSize); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 235 | } |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 236 | DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 237 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 238 | saved_core_stack_offsets_[i] = stack_offset; |
| 239 | stack_offset += kXRegSizeInBytes; |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 240 | } |
| 241 | |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 242 | const uint32_t fp_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ false); |
| 243 | for (uint32_t i : LowToHighBits(fp_spills)) { |
| 244 | DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 245 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 246 | saved_fpu_stack_offsets_[i] = stack_offset; |
| 247 | stack_offset += kDRegSizeInBytes; |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 248 | } |
| 249 | |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 250 | SaveRestoreLiveRegistersHelper(codegen, |
| 251 | locations, |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 252 | codegen->GetFirstRegisterSlotInSlowPath(), true /* is_save */); |
| 253 | } |
| 254 | |
| 255 | void SlowPathCodeARM64::RestoreLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 256 | SaveRestoreLiveRegistersHelper(codegen, |
| 257 | locations, |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 258 | codegen->GetFirstRegisterSlotInSlowPath(), false /* is_save */); |
| 259 | } |
| 260 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 261 | class BoundsCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 262 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 263 | explicit BoundsCheckSlowPathARM64(HBoundsCheck* instruction) : SlowPathCodeARM64(instruction) {} |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 264 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 265 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 266 | LocationSummary* locations = instruction_->GetLocations(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 267 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 268 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 269 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 270 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 271 | // Live registers will be restored in the catch block if caught. |
| 272 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 273 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 274 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 275 | // move resolver. |
| 276 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 277 | codegen->EmitParallelMoves(locations->InAt(0), |
| 278 | LocationFrom(calling_convention.GetRegisterAt(0)), |
| 279 | DataType::Type::kInt32, |
| 280 | locations->InAt(1), |
| 281 | LocationFrom(calling_convention.GetRegisterAt(1)), |
| 282 | DataType::Type::kInt32); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 283 | QuickEntrypointEnum entrypoint = instruction_->AsBoundsCheck()->IsStringCharAt() |
| 284 | ? kQuickThrowStringBounds |
| 285 | : kQuickThrowArrayBounds; |
| 286 | arm64_codegen->InvokeRuntime(entrypoint, instruction_, instruction_->GetDexPc(), this); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 287 | CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>(); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 288 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 289 | } |
| 290 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 291 | bool IsFatal() const OVERRIDE { return true; } |
| 292 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 293 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathARM64"; } |
| 294 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 295 | private: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 296 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathARM64); |
| 297 | }; |
| 298 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 299 | class DivZeroCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 300 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 301 | explicit DivZeroCheckSlowPathARM64(HDivZeroCheck* instruction) : SlowPathCodeARM64(instruction) {} |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 302 | |
| 303 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 304 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 305 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 306 | arm64_codegen->InvokeRuntime(kQuickThrowDivZero, instruction_, instruction_->GetDexPc(), this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 307 | CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 308 | } |
| 309 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 310 | bool IsFatal() const OVERRIDE { return true; } |
| 311 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 312 | const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathARM64"; } |
| 313 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 314 | private: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 315 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathARM64); |
| 316 | }; |
| 317 | |
| 318 | class LoadClassSlowPathARM64 : public SlowPathCodeARM64 { |
| 319 | public: |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 320 | LoadClassSlowPathARM64(HLoadClass* cls, HInstruction* at) |
| 321 | : SlowPathCodeARM64(at), cls_(cls) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 322 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 323 | DCHECK_EQ(instruction_->IsLoadClass(), cls_ == instruction_); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 324 | } |
| 325 | |
| 326 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 327 | LocationSummary* locations = instruction_->GetLocations(); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 328 | Location out = locations->Out(); |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 329 | const uint32_t dex_pc = instruction_->GetDexPc(); |
| 330 | bool must_resolve_type = instruction_->IsLoadClass() && cls_->MustResolveTypeOnSlowPath(); |
| 331 | bool must_do_clinit = instruction_->IsClinitCheck() || cls_->MustGenerateClinitCheck(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 332 | |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 333 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 334 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 335 | SaveLiveRegisters(codegen, locations); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 336 | |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 337 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 338 | if (must_resolve_type) { |
| 339 | DCHECK(IsSameDexFile(cls_->GetDexFile(), arm64_codegen->GetGraph()->GetDexFile())); |
| 340 | dex::TypeIndex type_index = cls_->GetTypeIndex(); |
| 341 | __ Mov(calling_convention.GetRegisterAt(0).W(), type_index.index_); |
Vladimir Marko | 9d47925 | 2018-07-24 11:35:20 +0100 | [diff] [blame] | 342 | arm64_codegen->InvokeRuntime(kQuickResolveType, instruction_, dex_pc, this); |
| 343 | CheckEntrypointTypes<kQuickResolveType, void*, uint32_t>(); |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 344 | // If we also must_do_clinit, the resolved type is now in the correct register. |
| 345 | } else { |
| 346 | DCHECK(must_do_clinit); |
| 347 | Location source = instruction_->IsLoadClass() ? out : locations->InAt(0); |
| 348 | arm64_codegen->MoveLocation(LocationFrom(calling_convention.GetRegisterAt(0)), |
| 349 | source, |
| 350 | cls_->GetType()); |
| 351 | } |
| 352 | if (must_do_clinit) { |
| 353 | arm64_codegen->InvokeRuntime(kQuickInitializeStaticStorage, instruction_, dex_pc, this); |
| 354 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, mirror::Class*>(); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 355 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 356 | |
| 357 | // Move the class to the desired location. |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 358 | if (out.IsValid()) { |
| 359 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 360 | DataType::Type type = instruction_->GetType(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 361 | arm64_codegen->MoveLocation(out, calling_convention.GetReturnLocation(type), type); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 362 | } |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 363 | RestoreLiveRegisters(codegen, locations); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 364 | __ B(GetExitLabel()); |
| 365 | } |
| 366 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 367 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathARM64"; } |
| 368 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 369 | private: |
| 370 | // The class this slow path will load. |
| 371 | HLoadClass* const cls_; |
| 372 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 373 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathARM64); |
| 374 | }; |
| 375 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 376 | class LoadStringSlowPathARM64 : public SlowPathCodeARM64 { |
| 377 | public: |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 378 | explicit LoadStringSlowPathARM64(HLoadString* instruction) |
| 379 | : SlowPathCodeARM64(instruction) {} |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 380 | |
| 381 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 382 | LocationSummary* locations = instruction_->GetLocations(); |
| 383 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 384 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 385 | |
| 386 | __ Bind(GetEntryLabel()); |
| 387 | SaveLiveRegisters(codegen, locations); |
| 388 | |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 389 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 390 | const dex::StringIndex string_index = instruction_->AsLoadString()->GetStringIndex(); |
| 391 | __ Mov(calling_convention.GetRegisterAt(0).W(), string_index.index_); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 392 | arm64_codegen->InvokeRuntime(kQuickResolveString, instruction_, instruction_->GetDexPc(), this); |
| 393 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 394 | DataType::Type type = instruction_->GetType(); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 395 | arm64_codegen->MoveLocation(locations->Out(), calling_convention.GetReturnLocation(type), type); |
| 396 | |
| 397 | RestoreLiveRegisters(codegen, locations); |
| 398 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 399 | __ B(GetExitLabel()); |
| 400 | } |
| 401 | |
| 402 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathARM64"; } |
| 403 | |
| 404 | private: |
| 405 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathARM64); |
| 406 | }; |
| 407 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 408 | class NullCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 409 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 410 | explicit NullCheckSlowPathARM64(HNullCheck* instr) : SlowPathCodeARM64(instr) {} |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 411 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 412 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 413 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 414 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 415 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 416 | // Live registers will be restored in the catch block if caught. |
| 417 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 418 | } |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 419 | arm64_codegen->InvokeRuntime(kQuickThrowNullPointer, |
| 420 | instruction_, |
| 421 | instruction_->GetDexPc(), |
| 422 | this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 423 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 424 | } |
| 425 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 426 | bool IsFatal() const OVERRIDE { return true; } |
| 427 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 428 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathARM64"; } |
| 429 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 430 | private: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 431 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathARM64); |
| 432 | }; |
| 433 | |
| 434 | class SuspendCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 435 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 436 | SuspendCheckSlowPathARM64(HSuspendCheck* instruction, HBasicBlock* successor) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 437 | : SlowPathCodeARM64(instruction), successor_(successor) {} |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 438 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 439 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Artem Serov | 7957d95 | 2017-04-04 15:44:09 +0100 | [diff] [blame] | 440 | LocationSummary* locations = instruction_->GetLocations(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 441 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 442 | __ Bind(GetEntryLabel()); |
Artem Serov | 7957d95 | 2017-04-04 15:44:09 +0100 | [diff] [blame] | 443 | SaveLiveRegisters(codegen, locations); // Only saves live 128-bit regs for SIMD. |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 444 | arm64_codegen->InvokeRuntime(kQuickTestSuspend, instruction_, instruction_->GetDexPc(), this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 445 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
Artem Serov | 7957d95 | 2017-04-04 15:44:09 +0100 | [diff] [blame] | 446 | RestoreLiveRegisters(codegen, locations); // Only restores live 128-bit regs for SIMD. |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 447 | if (successor_ == nullptr) { |
| 448 | __ B(GetReturnLabel()); |
| 449 | } else { |
| 450 | __ B(arm64_codegen->GetLabelOf(successor_)); |
| 451 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 452 | } |
| 453 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 454 | vixl::aarch64::Label* GetReturnLabel() { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 455 | DCHECK(successor_ == nullptr); |
| 456 | return &return_label_; |
| 457 | } |
| 458 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 459 | HBasicBlock* GetSuccessor() const { |
| 460 | return successor_; |
| 461 | } |
| 462 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 463 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathARM64"; } |
| 464 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 465 | private: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 466 | // If not null, the block to branch to after the suspend check. |
| 467 | HBasicBlock* const successor_; |
| 468 | |
| 469 | // 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] | 470 | vixl::aarch64::Label return_label_; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 471 | |
| 472 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathARM64); |
| 473 | }; |
| 474 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 475 | class TypeCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 476 | public: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 477 | TypeCheckSlowPathARM64(HInstruction* instruction, bool is_fatal) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 478 | : SlowPathCodeARM64(instruction), is_fatal_(is_fatal) {} |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 479 | |
| 480 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 481 | LocationSummary* locations = instruction_->GetLocations(); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 482 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 483 | DCHECK(instruction_->IsCheckCast() |
| 484 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 485 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 486 | uint32_t dex_pc = instruction_->GetDexPc(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 487 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 488 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 489 | |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 490 | if (!is_fatal_ || instruction_->CanThrowIntoCatchBlock()) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 491 | SaveLiveRegisters(codegen, locations); |
| 492 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 493 | |
| 494 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 495 | // move resolver. |
| 496 | InvokeRuntimeCallingConvention calling_convention; |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 497 | codegen->EmitParallelMoves(locations->InAt(0), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 498 | LocationFrom(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 499 | DataType::Type::kReference, |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 500 | locations->InAt(1), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 501 | LocationFrom(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 502 | DataType::Type::kReference); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 503 | if (instruction_->IsInstanceOf()) { |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 504 | arm64_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, instruction_, dex_pc, this); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 505 | CheckEntrypointTypes<kQuickInstanceofNonTrivial, size_t, mirror::Object*, mirror::Class*>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 506 | DataType::Type ret_type = instruction_->GetType(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 507 | Location ret_loc = calling_convention.GetReturnLocation(ret_type); |
| 508 | arm64_codegen->MoveLocation(locations->Out(), ret_loc, ret_type); |
| 509 | } else { |
| 510 | DCHECK(instruction_->IsCheckCast()); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 511 | arm64_codegen->InvokeRuntime(kQuickCheckInstanceOf, instruction_, dex_pc, this); |
| 512 | CheckEntrypointTypes<kQuickCheckInstanceOf, void, mirror::Object*, mirror::Class*>(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 513 | } |
| 514 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 515 | if (!is_fatal_) { |
| 516 | RestoreLiveRegisters(codegen, locations); |
| 517 | __ B(GetExitLabel()); |
| 518 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 519 | } |
| 520 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 521 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathARM64"; } |
Roland Levillain | f41f956 | 2016-09-14 19:26:48 +0100 | [diff] [blame] | 522 | bool IsFatal() const OVERRIDE { return is_fatal_; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 523 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 524 | private: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 525 | const bool is_fatal_; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 526 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 527 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathARM64); |
| 528 | }; |
| 529 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 530 | class DeoptimizationSlowPathARM64 : public SlowPathCodeARM64 { |
| 531 | public: |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 532 | explicit DeoptimizationSlowPathARM64(HDeoptimize* instruction) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 533 | : SlowPathCodeARM64(instruction) {} |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 534 | |
| 535 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 536 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 537 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 538 | LocationSummary* locations = instruction_->GetLocations(); |
| 539 | SaveLiveRegisters(codegen, locations); |
| 540 | InvokeRuntimeCallingConvention calling_convention; |
| 541 | __ Mov(calling_convention.GetRegisterAt(0), |
| 542 | static_cast<uint32_t>(instruction_->AsDeoptimize()->GetDeoptimizationKind())); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 543 | arm64_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 544 | CheckEntrypointTypes<kQuickDeoptimize, void, DeoptimizationKind>(); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 545 | } |
| 546 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 547 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathARM64"; } |
| 548 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 549 | private: |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 550 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathARM64); |
| 551 | }; |
| 552 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 553 | class ArraySetSlowPathARM64 : public SlowPathCodeARM64 { |
| 554 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 555 | explicit ArraySetSlowPathARM64(HInstruction* instruction) : SlowPathCodeARM64(instruction) {} |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 556 | |
| 557 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 558 | LocationSummary* locations = instruction_->GetLocations(); |
| 559 | __ Bind(GetEntryLabel()); |
| 560 | SaveLiveRegisters(codegen, locations); |
| 561 | |
| 562 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 563 | HParallelMove parallel_move(codegen->GetGraph()->GetAllocator()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 564 | parallel_move.AddMove( |
| 565 | locations->InAt(0), |
| 566 | LocationFrom(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 567 | DataType::Type::kReference, |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 568 | nullptr); |
| 569 | parallel_move.AddMove( |
| 570 | locations->InAt(1), |
| 571 | LocationFrom(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 572 | DataType::Type::kInt32, |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 573 | nullptr); |
| 574 | parallel_move.AddMove( |
| 575 | locations->InAt(2), |
| 576 | LocationFrom(calling_convention.GetRegisterAt(2)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 577 | DataType::Type::kReference, |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 578 | nullptr); |
| 579 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 580 | |
| 581 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 582 | arm64_codegen->InvokeRuntime(kQuickAputObject, instruction_, instruction_->GetDexPc(), this); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 583 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
| 584 | RestoreLiveRegisters(codegen, locations); |
| 585 | __ B(GetExitLabel()); |
| 586 | } |
| 587 | |
| 588 | const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathARM64"; } |
| 589 | |
| 590 | private: |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 591 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathARM64); |
| 592 | }; |
| 593 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 594 | void JumpTableARM64::EmitTable(CodeGeneratorARM64* codegen) { |
| 595 | uint32_t num_entries = switch_instr_->GetNumEntries(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 596 | DCHECK_GE(num_entries, kPackedSwitchCompareJumpThreshold); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 597 | |
| 598 | // We are about to use the assembler to place literals directly. Make sure we have enough |
| 599 | // underlying code buffer and we have generated the jump table with right size. |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 600 | EmissionCheckScope scope(codegen->GetVIXLAssembler(), |
| 601 | num_entries * sizeof(int32_t), |
| 602 | CodeBufferCheckScope::kExactSize); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 603 | |
| 604 | __ Bind(&table_start_); |
| 605 | const ArenaVector<HBasicBlock*>& successors = switch_instr_->GetBlock()->GetSuccessors(); |
| 606 | for (uint32_t i = 0; i < num_entries; i++) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 607 | vixl::aarch64::Label* target_label = codegen->GetLabelOf(successors[i]); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 608 | DCHECK(target_label->IsBound()); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 609 | ptrdiff_t jump_offset = target_label->GetLocation() - table_start_.GetLocation(); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 610 | DCHECK_GT(jump_offset, std::numeric_limits<int32_t>::min()); |
| 611 | DCHECK_LE(jump_offset, std::numeric_limits<int32_t>::max()); |
| 612 | Literal<int32_t> literal(jump_offset); |
| 613 | __ place(&literal); |
| 614 | } |
| 615 | } |
| 616 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 617 | // Abstract base class for read barrier slow paths marking a reference |
| 618 | // `ref`. |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 619 | // |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 620 | // Argument `entrypoint` must be a register location holding the read |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 621 | // barrier marking runtime entry point to be invoked or an empty |
| 622 | // location; in the latter case, the read barrier marking runtime |
| 623 | // entry point will be loaded by the slow path code itself. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 624 | class ReadBarrierMarkSlowPathBaseARM64 : public SlowPathCodeARM64 { |
| 625 | protected: |
| 626 | ReadBarrierMarkSlowPathBaseARM64(HInstruction* instruction, Location ref, Location entrypoint) |
| 627 | : SlowPathCodeARM64(instruction), ref_(ref), entrypoint_(entrypoint) { |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 628 | DCHECK(kEmitCompilerReadBarrier); |
| 629 | } |
| 630 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 631 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathBaseARM64"; } |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 632 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 633 | // Generate assembly code calling the read barrier marking runtime |
| 634 | // entry point (ReadBarrierMarkRegX). |
| 635 | void GenerateReadBarrierMarkRuntimeCall(CodeGenerator* codegen) { |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 636 | // No need to save live registers; it's taken care of by the |
| 637 | // entrypoint. Also, there is no need to update the stack mask, |
| 638 | // as this runtime call will not trigger a garbage collection. |
| 639 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 640 | DCHECK_NE(ref_.reg(), LR); |
| 641 | DCHECK_NE(ref_.reg(), WSP); |
| 642 | DCHECK_NE(ref_.reg(), WZR); |
| 643 | // IP0 is used internally by the ReadBarrierMarkRegX entry point |
| 644 | // as a temporary, it cannot be the entry point's input/output. |
| 645 | DCHECK_NE(ref_.reg(), IP0); |
| 646 | DCHECK(0 <= ref_.reg() && ref_.reg() < kNumberOfWRegisters) << ref_.reg(); |
| 647 | // "Compact" slow path, saving two moves. |
| 648 | // |
| 649 | // Instead of using the standard runtime calling convention (input |
| 650 | // and output in W0): |
| 651 | // |
| 652 | // W0 <- ref |
| 653 | // W0 <- ReadBarrierMark(W0) |
| 654 | // ref <- W0 |
| 655 | // |
| 656 | // we just use rX (the register containing `ref`) as input and output |
| 657 | // of a dedicated entrypoint: |
| 658 | // |
| 659 | // rX <- ReadBarrierMarkRegX(rX) |
| 660 | // |
| 661 | if (entrypoint_.IsValid()) { |
| 662 | arm64_codegen->ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction_, this); |
| 663 | __ Blr(XRegisterFrom(entrypoint_)); |
| 664 | } else { |
| 665 | // Entrypoint is not already loaded, load from the thread. |
| 666 | int32_t entry_point_offset = |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 667 | Thread::ReadBarrierMarkEntryPointsOffset<kArm64PointerSize>(ref_.reg()); |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 668 | // This runtime call does not require a stack map. |
| 669 | arm64_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
| 670 | } |
| 671 | } |
| 672 | |
| 673 | // The location (register) of the marked object reference. |
| 674 | const Location ref_; |
| 675 | |
| 676 | // The location of the entrypoint if it is already loaded. |
| 677 | const Location entrypoint_; |
| 678 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 679 | private: |
| 680 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathBaseARM64); |
| 681 | }; |
| 682 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 683 | // Slow path marking an object reference `ref` during a read |
| 684 | // barrier. The field `obj.field` in the object `obj` holding this |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 685 | // reference does not get updated by this slow path after marking. |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 686 | // |
| 687 | // This means that after the execution of this slow path, `ref` will |
| 688 | // always be up-to-date, but `obj.field` may not; i.e., after the |
| 689 | // flip, `ref` will be a to-space reference, but `obj.field` will |
| 690 | // probably still be a from-space reference (unless it gets updated by |
| 691 | // another thread, or if another thread installed another object |
| 692 | // reference (different from `ref`) in `obj.field`). |
| 693 | // |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 694 | // Argument `entrypoint` must be a register location holding the read |
| 695 | // barrier marking runtime entry point to be invoked or an empty |
| 696 | // location; in the latter case, the read barrier marking runtime |
| 697 | // entry point will be loaded by the slow path code itself. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 698 | class ReadBarrierMarkSlowPathARM64 : public ReadBarrierMarkSlowPathBaseARM64 { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 699 | public: |
| 700 | ReadBarrierMarkSlowPathARM64(HInstruction* instruction, |
| 701 | Location ref, |
| 702 | Location entrypoint = Location::NoLocation()) |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 703 | : ReadBarrierMarkSlowPathBaseARM64(instruction, ref, entrypoint) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 704 | DCHECK(kEmitCompilerReadBarrier); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 705 | } |
| 706 | |
| 707 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathARM64"; } |
| 708 | |
| 709 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 710 | LocationSummary* locations = instruction_->GetLocations(); |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 711 | DCHECK(locations->CanCall()); |
| 712 | DCHECK(ref_.IsRegister()) << ref_; |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 713 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_.reg())) << ref_.reg(); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 714 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 715 | << "Unexpected instruction in read barrier marking slow path: " |
| 716 | << instruction_->DebugName(); |
| 717 | |
| 718 | __ Bind(GetEntryLabel()); |
| 719 | GenerateReadBarrierMarkRuntimeCall(codegen); |
| 720 | __ B(GetExitLabel()); |
| 721 | } |
| 722 | |
| 723 | private: |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 724 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathARM64); |
| 725 | }; |
| 726 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 727 | // Slow path loading `obj`'s lock word, loading a reference from |
| 728 | // object `*(obj + offset + (index << scale_factor))` into `ref`, and |
| 729 | // marking `ref` if `obj` is gray according to the lock word (Baker |
| 730 | // read barrier). The field `obj.field` in the object `obj` holding |
| 731 | // this reference does not get updated by this slow path after marking |
| 732 | // (see LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM64 |
| 733 | // below for that). |
| 734 | // |
| 735 | // This means that after the execution of this slow path, `ref` will |
| 736 | // always be up-to-date, but `obj.field` may not; i.e., after the |
| 737 | // flip, `ref` will be a to-space reference, but `obj.field` will |
| 738 | // probably still be a from-space reference (unless it gets updated by |
| 739 | // another thread, or if another thread installed another object |
| 740 | // reference (different from `ref`) in `obj.field`). |
| 741 | // |
| 742 | // Argument `entrypoint` must be a register location holding the read |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 743 | // barrier marking runtime entry point to be invoked or an empty |
| 744 | // location; in the latter case, the read barrier marking runtime |
| 745 | // entry point will be loaded by the slow path code itself. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 746 | class LoadReferenceWithBakerReadBarrierSlowPathARM64 : public ReadBarrierMarkSlowPathBaseARM64 { |
| 747 | public: |
| 748 | LoadReferenceWithBakerReadBarrierSlowPathARM64(HInstruction* instruction, |
| 749 | Location ref, |
| 750 | Register obj, |
| 751 | uint32_t offset, |
| 752 | Location index, |
| 753 | size_t scale_factor, |
| 754 | bool needs_null_check, |
| 755 | bool use_load_acquire, |
| 756 | Register temp, |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 757 | Location entrypoint = Location::NoLocation()) |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 758 | : ReadBarrierMarkSlowPathBaseARM64(instruction, ref, entrypoint), |
| 759 | obj_(obj), |
| 760 | offset_(offset), |
| 761 | index_(index), |
| 762 | scale_factor_(scale_factor), |
| 763 | needs_null_check_(needs_null_check), |
| 764 | use_load_acquire_(use_load_acquire), |
| 765 | temp_(temp) { |
| 766 | DCHECK(kEmitCompilerReadBarrier); |
| 767 | DCHECK(kUseBakerReadBarrier); |
| 768 | } |
| 769 | |
| 770 | const char* GetDescription() const OVERRIDE { |
| 771 | return "LoadReferenceWithBakerReadBarrierSlowPathARM64"; |
| 772 | } |
| 773 | |
| 774 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 775 | LocationSummary* locations = instruction_->GetLocations(); |
| 776 | DCHECK(locations->CanCall()); |
| 777 | DCHECK(ref_.IsRegister()) << ref_; |
| 778 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_.reg())) << ref_.reg(); |
| 779 | DCHECK(obj_.IsW()); |
| 780 | DCHECK_NE(ref_.reg(), LocationFrom(temp_).reg()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 781 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 782 | instruction_->IsStaticFieldGet() || |
| 783 | instruction_->IsArrayGet() || |
| 784 | instruction_->IsArraySet() || |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 785 | instruction_->IsInstanceOf() || |
| 786 | instruction_->IsCheckCast() || |
| 787 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()) || |
| 788 | (instruction_->IsInvokeStaticOrDirect() && instruction_->GetLocations()->Intrinsified())) |
| 789 | << "Unexpected instruction in read barrier marking slow path: " |
| 790 | << instruction_->DebugName(); |
| 791 | // The read barrier instrumentation of object ArrayGet |
| 792 | // instructions does not support the HIntermediateAddress |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 793 | // instruction. |
| 794 | DCHECK(!(instruction_->IsArrayGet() && |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 795 | instruction_->AsArrayGet()->GetArray()->IsIntermediateAddress())); |
| 796 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 797 | // Temporary register `temp_`, used to store the lock word, must |
| 798 | // not be IP0 nor IP1, as we may use them to emit the reference |
| 799 | // load (in the call to GenerateRawReferenceLoad below), and we |
| 800 | // need the lock word to still be in `temp_` after the reference |
| 801 | // load. |
| 802 | DCHECK_NE(LocationFrom(temp_).reg(), IP0); |
| 803 | DCHECK_NE(LocationFrom(temp_).reg(), IP1); |
| 804 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 805 | __ Bind(GetEntryLabel()); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 806 | |
| 807 | // When using MaybeGenerateReadBarrierSlow, the read barrier call is |
| 808 | // inserted after the original load. However, in fast path based |
| 809 | // Baker's read barriers, we need to perform the load of |
| 810 | // mirror::Object::monitor_ *before* the original reference load. |
| 811 | // This load-load ordering is required by the read barrier. |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 812 | // The slow path (for Baker's algorithm) should look like: |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 813 | // |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 814 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 815 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 816 | // HeapReference<mirror::Object> ref = *src; // Original reference load. |
| 817 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 818 | // if (is_gray) { |
| 819 | // ref = entrypoint(ref); // ref = ReadBarrier::Mark(ref); // Runtime entry point call. |
| 820 | // } |
Roland Levillain | d966ce7 | 2017-02-09 16:20:14 +0000 | [diff] [blame] | 821 | // |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 822 | // Note: the original implementation in ReadBarrier::Barrier is |
| 823 | // slightly more complex as it performs additional checks that we do |
| 824 | // not do here for performance reasons. |
| 825 | |
| 826 | // /* int32_t */ monitor = obj->monitor_ |
| 827 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 828 | __ Ldr(temp_, HeapOperand(obj_, monitor_offset)); |
| 829 | if (needs_null_check_) { |
| 830 | codegen->MaybeRecordImplicitNullCheck(instruction_); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 831 | } |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 832 | // /* LockWord */ lock_word = LockWord(monitor) |
| 833 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 834 | "art::LockWord and int32_t have different sizes."); |
| 835 | |
| 836 | // Introduce a dependency on the lock_word including rb_state, |
| 837 | // to prevent load-load reordering, and without using |
| 838 | // a memory barrier (which would be more expensive). |
| 839 | // `obj` is unchanged by this operation, but its value now depends |
| 840 | // on `temp`. |
| 841 | __ Add(obj_.X(), obj_.X(), Operand(temp_.X(), LSR, 32)); |
| 842 | |
| 843 | // The actual reference load. |
| 844 | // A possible implicit null check has already been handled above. |
| 845 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 846 | arm64_codegen->GenerateRawReferenceLoad(instruction_, |
| 847 | ref_, |
| 848 | obj_, |
| 849 | offset_, |
| 850 | index_, |
| 851 | scale_factor_, |
| 852 | /* needs_null_check */ false, |
| 853 | use_load_acquire_); |
| 854 | |
| 855 | // Mark the object `ref` when `obj` is gray. |
| 856 | // |
| 857 | // if (rb_state == ReadBarrier::GrayState()) |
| 858 | // ref = ReadBarrier::Mark(ref); |
| 859 | // |
| 860 | // Given the numeric representation, it's enough to check the low bit of the rb_state. |
| 861 | static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0"); |
| 862 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
| 863 | __ Tbz(temp_, LockWord::kReadBarrierStateShift, GetExitLabel()); |
| 864 | GenerateReadBarrierMarkRuntimeCall(codegen); |
| 865 | |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 866 | __ B(GetExitLabel()); |
| 867 | } |
| 868 | |
| 869 | private: |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 870 | // The register containing the object holding the marked object reference field. |
| 871 | Register obj_; |
| 872 | // The offset, index and scale factor to access the reference in `obj_`. |
| 873 | uint32_t offset_; |
| 874 | Location index_; |
| 875 | size_t scale_factor_; |
| 876 | // Is a null check required? |
| 877 | bool needs_null_check_; |
| 878 | // Should this reference load use Load-Acquire semantics? |
| 879 | bool use_load_acquire_; |
| 880 | // A temporary register used to hold the lock word of `obj_`. |
| 881 | Register temp_; |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 882 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 883 | DISALLOW_COPY_AND_ASSIGN(LoadReferenceWithBakerReadBarrierSlowPathARM64); |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 884 | }; |
| 885 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 886 | // Slow path loading `obj`'s lock word, loading a reference from |
| 887 | // object `*(obj + offset + (index << scale_factor))` into `ref`, and |
| 888 | // marking `ref` if `obj` is gray according to the lock word (Baker |
| 889 | // read barrier). If needed, this slow path also atomically updates |
| 890 | // the field `obj.field` in the object `obj` holding this reference |
| 891 | // after marking (contrary to |
| 892 | // LoadReferenceWithBakerReadBarrierSlowPathARM64 above, which never |
| 893 | // tries to update `obj.field`). |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 894 | // |
| 895 | // This means that after the execution of this slow path, both `ref` |
| 896 | // and `obj.field` will be up-to-date; i.e., after the flip, both will |
| 897 | // hold the same to-space reference (unless another thread installed |
| 898 | // another object reference (different from `ref`) in `obj.field`). |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 899 | // |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 900 | // Argument `entrypoint` must be a register location holding the read |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 901 | // barrier marking runtime entry point to be invoked or an empty |
| 902 | // location; in the latter case, the read barrier marking runtime |
| 903 | // entry point will be loaded by the slow path code itself. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 904 | class LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM64 |
| 905 | : public ReadBarrierMarkSlowPathBaseARM64 { |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 906 | public: |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 907 | LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM64( |
| 908 | HInstruction* instruction, |
| 909 | Location ref, |
| 910 | Register obj, |
| 911 | uint32_t offset, |
| 912 | Location index, |
| 913 | size_t scale_factor, |
| 914 | bool needs_null_check, |
| 915 | bool use_load_acquire, |
| 916 | Register temp, |
| 917 | Location entrypoint = Location::NoLocation()) |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 918 | : ReadBarrierMarkSlowPathBaseARM64(instruction, ref, entrypoint), |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 919 | obj_(obj), |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 920 | offset_(offset), |
| 921 | index_(index), |
| 922 | scale_factor_(scale_factor), |
| 923 | needs_null_check_(needs_null_check), |
| 924 | use_load_acquire_(use_load_acquire), |
Roland Levillain | 35345a5 | 2017-02-27 14:32:08 +0000 | [diff] [blame] | 925 | temp_(temp) { |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 926 | DCHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 927 | DCHECK(kUseBakerReadBarrier); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 928 | } |
| 929 | |
| 930 | const char* GetDescription() const OVERRIDE { |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 931 | return "LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM64"; |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 932 | } |
| 933 | |
| 934 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 935 | LocationSummary* locations = instruction_->GetLocations(); |
| 936 | Register ref_reg = WRegisterFrom(ref_); |
| 937 | DCHECK(locations->CanCall()); |
| 938 | DCHECK(ref_.IsRegister()) << ref_; |
| 939 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_.reg())) << ref_.reg(); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 940 | DCHECK(obj_.IsW()); |
| 941 | DCHECK_NE(ref_.reg(), LocationFrom(temp_).reg()); |
| 942 | |
| 943 | // This slow path is only used by the UnsafeCASObject intrinsic at the moment. |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 944 | DCHECK((instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
| 945 | << "Unexpected instruction in read barrier marking and field updating slow path: " |
| 946 | << instruction_->DebugName(); |
| 947 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 948 | DCHECK_EQ(instruction_->AsInvoke()->GetIntrinsic(), Intrinsics::kUnsafeCASObject); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 949 | DCHECK_EQ(offset_, 0u); |
| 950 | DCHECK_EQ(scale_factor_, 0u); |
| 951 | DCHECK_EQ(use_load_acquire_, false); |
| 952 | // The location of the offset of the marked reference field within `obj_`. |
| 953 | Location field_offset = index_; |
| 954 | DCHECK(field_offset.IsRegister()) << field_offset; |
| 955 | |
| 956 | // Temporary register `temp_`, used to store the lock word, must |
| 957 | // not be IP0 nor IP1, as we may use them to emit the reference |
| 958 | // load (in the call to GenerateRawReferenceLoad below), and we |
| 959 | // need the lock word to still be in `temp_` after the reference |
| 960 | // load. |
| 961 | DCHECK_NE(LocationFrom(temp_).reg(), IP0); |
| 962 | DCHECK_NE(LocationFrom(temp_).reg(), IP1); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 963 | |
| 964 | __ Bind(GetEntryLabel()); |
| 965 | |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 966 | // The implementation is similar to LoadReferenceWithBakerReadBarrierSlowPathARM64's: |
| 967 | // |
| 968 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 969 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 970 | // HeapReference<mirror::Object> ref = *src; // Original reference load. |
| 971 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 972 | // if (is_gray) { |
| 973 | // old_ref = ref; |
| 974 | // ref = entrypoint(ref); // ref = ReadBarrier::Mark(ref); // Runtime entry point call. |
| 975 | // compareAndSwapObject(obj, field_offset, old_ref, ref); |
| 976 | // } |
| 977 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 978 | // /* int32_t */ monitor = obj->monitor_ |
| 979 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 980 | __ Ldr(temp_, HeapOperand(obj_, monitor_offset)); |
| 981 | if (needs_null_check_) { |
| 982 | codegen->MaybeRecordImplicitNullCheck(instruction_); |
| 983 | } |
| 984 | // /* LockWord */ lock_word = LockWord(monitor) |
| 985 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 986 | "art::LockWord and int32_t have different sizes."); |
| 987 | |
| 988 | // Introduce a dependency on the lock_word including rb_state, |
| 989 | // to prevent load-load reordering, and without using |
| 990 | // a memory barrier (which would be more expensive). |
| 991 | // `obj` is unchanged by this operation, but its value now depends |
| 992 | // on `temp`. |
| 993 | __ Add(obj_.X(), obj_.X(), Operand(temp_.X(), LSR, 32)); |
| 994 | |
| 995 | // The actual reference load. |
| 996 | // A possible implicit null check has already been handled above. |
| 997 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 998 | arm64_codegen->GenerateRawReferenceLoad(instruction_, |
| 999 | ref_, |
| 1000 | obj_, |
| 1001 | offset_, |
| 1002 | index_, |
| 1003 | scale_factor_, |
| 1004 | /* needs_null_check */ false, |
| 1005 | use_load_acquire_); |
| 1006 | |
| 1007 | // Mark the object `ref` when `obj` is gray. |
| 1008 | // |
| 1009 | // if (rb_state == ReadBarrier::GrayState()) |
| 1010 | // ref = ReadBarrier::Mark(ref); |
| 1011 | // |
| 1012 | // Given the numeric representation, it's enough to check the low bit of the rb_state. |
| 1013 | static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0"); |
| 1014 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
| 1015 | __ Tbz(temp_, LockWord::kReadBarrierStateShift, GetExitLabel()); |
| 1016 | |
| 1017 | // Save the old value of the reference before marking it. |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1018 | // Note that we cannot use IP to save the old reference, as IP is |
| 1019 | // used internally by the ReadBarrierMarkRegX entry point, and we |
| 1020 | // need the old reference after the call to that entry point. |
| 1021 | DCHECK_NE(LocationFrom(temp_).reg(), IP0); |
| 1022 | __ Mov(temp_.W(), ref_reg); |
| 1023 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1024 | GenerateReadBarrierMarkRuntimeCall(codegen); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1025 | |
| 1026 | // If the new reference is different from the old reference, |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1027 | // update the field in the holder (`*(obj_ + field_offset)`). |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1028 | // |
| 1029 | // Note that this field could also hold a different object, if |
| 1030 | // another thread had concurrently changed it. In that case, the |
| 1031 | // LDXR/CMP/BNE sequence of instructions in the compare-and-set |
| 1032 | // (CAS) operation below would abort the CAS, leaving the field |
| 1033 | // as-is. |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1034 | __ Cmp(temp_.W(), ref_reg); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1035 | __ B(eq, GetExitLabel()); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1036 | |
| 1037 | // Update the the holder's field atomically. This may fail if |
| 1038 | // mutator updates before us, but it's OK. This is achieved |
| 1039 | // using a strong compare-and-set (CAS) operation with relaxed |
| 1040 | // memory synchronization ordering, where the expected value is |
| 1041 | // the old reference and the desired value is the new reference. |
| 1042 | |
| 1043 | MacroAssembler* masm = arm64_codegen->GetVIXLAssembler(); |
| 1044 | UseScratchRegisterScope temps(masm); |
| 1045 | |
| 1046 | // Convenience aliases. |
| 1047 | Register base = obj_.W(); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1048 | Register offset = XRegisterFrom(field_offset); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1049 | Register expected = temp_.W(); |
| 1050 | Register value = ref_reg; |
| 1051 | Register tmp_ptr = temps.AcquireX(); // Pointer to actual memory. |
| 1052 | Register tmp_value = temps.AcquireW(); // Value in memory. |
| 1053 | |
| 1054 | __ Add(tmp_ptr, base.X(), Operand(offset)); |
| 1055 | |
| 1056 | if (kPoisonHeapReferences) { |
| 1057 | arm64_codegen->GetAssembler()->PoisonHeapReference(expected); |
| 1058 | if (value.Is(expected)) { |
| 1059 | // Do not poison `value`, as it is the same register as |
| 1060 | // `expected`, which has just been poisoned. |
| 1061 | } else { |
| 1062 | arm64_codegen->GetAssembler()->PoisonHeapReference(value); |
| 1063 | } |
| 1064 | } |
| 1065 | |
| 1066 | // do { |
| 1067 | // tmp_value = [tmp_ptr] - expected; |
| 1068 | // } while (tmp_value == 0 && failure([tmp_ptr] <- r_new_value)); |
| 1069 | |
Roland Levillain | 24a4d11 | 2016-10-26 13:10:46 +0100 | [diff] [blame] | 1070 | vixl::aarch64::Label loop_head, comparison_failed, exit_loop; |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1071 | __ Bind(&loop_head); |
| 1072 | __ Ldxr(tmp_value, MemOperand(tmp_ptr)); |
| 1073 | __ Cmp(tmp_value, expected); |
Roland Levillain | 24a4d11 | 2016-10-26 13:10:46 +0100 | [diff] [blame] | 1074 | __ B(&comparison_failed, ne); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1075 | __ Stxr(tmp_value, value, MemOperand(tmp_ptr)); |
| 1076 | __ Cbnz(tmp_value, &loop_head); |
Roland Levillain | 24a4d11 | 2016-10-26 13:10:46 +0100 | [diff] [blame] | 1077 | __ B(&exit_loop); |
| 1078 | __ Bind(&comparison_failed); |
| 1079 | __ Clrex(); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1080 | __ Bind(&exit_loop); |
| 1081 | |
| 1082 | if (kPoisonHeapReferences) { |
| 1083 | arm64_codegen->GetAssembler()->UnpoisonHeapReference(expected); |
| 1084 | if (value.Is(expected)) { |
| 1085 | // Do not unpoison `value`, as it is the same register as |
| 1086 | // `expected`, which has just been unpoisoned. |
| 1087 | } else { |
| 1088 | arm64_codegen->GetAssembler()->UnpoisonHeapReference(value); |
| 1089 | } |
| 1090 | } |
| 1091 | |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1092 | __ B(GetExitLabel()); |
| 1093 | } |
| 1094 | |
| 1095 | private: |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1096 | // The register containing the object holding the marked object reference field. |
| 1097 | const Register obj_; |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1098 | // The offset, index and scale factor to access the reference in `obj_`. |
| 1099 | uint32_t offset_; |
| 1100 | Location index_; |
| 1101 | size_t scale_factor_; |
| 1102 | // Is a null check required? |
| 1103 | bool needs_null_check_; |
| 1104 | // Should this reference load use Load-Acquire semantics? |
| 1105 | bool use_load_acquire_; |
| 1106 | // A temporary register used to hold the lock word of `obj_`; and |
| 1107 | // also to hold the original reference value, when the reference is |
| 1108 | // marked. |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1109 | const Register temp_; |
| 1110 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1111 | DISALLOW_COPY_AND_ASSIGN(LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM64); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1112 | }; |
| 1113 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1114 | // Slow path generating a read barrier for a heap reference. |
| 1115 | class ReadBarrierForHeapReferenceSlowPathARM64 : public SlowPathCodeARM64 { |
| 1116 | public: |
| 1117 | ReadBarrierForHeapReferenceSlowPathARM64(HInstruction* instruction, |
| 1118 | Location out, |
| 1119 | Location ref, |
| 1120 | Location obj, |
| 1121 | uint32_t offset, |
| 1122 | Location index) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 1123 | : SlowPathCodeARM64(instruction), |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1124 | out_(out), |
| 1125 | ref_(ref), |
| 1126 | obj_(obj), |
| 1127 | offset_(offset), |
| 1128 | index_(index) { |
| 1129 | DCHECK(kEmitCompilerReadBarrier); |
| 1130 | // If `obj` is equal to `out` or `ref`, it means the initial object |
| 1131 | // has been overwritten by (or after) the heap object reference load |
| 1132 | // to be instrumented, e.g.: |
| 1133 | // |
| 1134 | // __ Ldr(out, HeapOperand(out, class_offset); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1135 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1136 | // |
| 1137 | // In that case, we have lost the information about the original |
| 1138 | // object, and the emitted read barrier cannot work properly. |
| 1139 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 1140 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 1141 | } |
| 1142 | |
| 1143 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 1144 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 1145 | LocationSummary* locations = instruction_->GetLocations(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1146 | DataType::Type type = DataType::Type::kReference; |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1147 | DCHECK(locations->CanCall()); |
| 1148 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(out_.reg())); |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 1149 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 1150 | instruction_->IsStaticFieldGet() || |
| 1151 | instruction_->IsArrayGet() || |
| 1152 | instruction_->IsInstanceOf() || |
| 1153 | instruction_->IsCheckCast() || |
Andreas Gampe | d9911ee | 2017-03-27 13:27:24 -0700 | [diff] [blame] | 1154 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1155 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 1156 | << instruction_->DebugName(); |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 1157 | // The read barrier instrumentation of object ArrayGet |
| 1158 | // instructions does not support the HIntermediateAddress |
| 1159 | // instruction. |
Roland Levillain | cd3d0fb | 2016-01-15 19:26:48 +0000 | [diff] [blame] | 1160 | DCHECK(!(instruction_->IsArrayGet() && |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 1161 | instruction_->AsArrayGet()->GetArray()->IsIntermediateAddress())); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1162 | |
| 1163 | __ Bind(GetEntryLabel()); |
| 1164 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1165 | SaveLiveRegisters(codegen, locations); |
| 1166 | |
| 1167 | // We may have to change the index's value, but as `index_` is a |
| 1168 | // constant member (like other "inputs" of this slow path), |
| 1169 | // introduce a copy of it, `index`. |
| 1170 | Location index = index_; |
| 1171 | if (index_.IsValid()) { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 1172 | // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1173 | if (instruction_->IsArrayGet()) { |
| 1174 | // Compute the actual memory offset and store it in `index`. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1175 | Register index_reg = RegisterFrom(index_, DataType::Type::kInt32); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1176 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_.reg())); |
| 1177 | if (codegen->IsCoreCalleeSaveRegister(index_.reg())) { |
| 1178 | // We are about to change the value of `index_reg` (see the |
| 1179 | // calls to vixl::MacroAssembler::Lsl and |
| 1180 | // vixl::MacroAssembler::Mov below), but it has |
| 1181 | // not been saved by the previous call to |
| 1182 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 1183 | // callee-save register -- |
| 1184 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 1185 | // callee-save registers, as it has been designed with the |
| 1186 | // assumption that callee-save registers are supposed to be |
| 1187 | // handled by the called function. So, as a callee-save |
| 1188 | // register, `index_reg` _would_ eventually be saved onto |
| 1189 | // the stack, but it would be too late: we would have |
| 1190 | // changed its value earlier. Therefore, we manually save |
| 1191 | // it here into another freely available register, |
| 1192 | // `free_reg`, chosen of course among the caller-save |
| 1193 | // registers (as a callee-save `free_reg` register would |
| 1194 | // exhibit the same problem). |
| 1195 | // |
| 1196 | // Note we could have requested a temporary register from |
| 1197 | // the register allocator instead; but we prefer not to, as |
| 1198 | // this is a slow path, and we know we can find a |
| 1199 | // caller-save register that is available. |
| 1200 | Register free_reg = FindAvailableCallerSaveRegister(codegen); |
| 1201 | __ Mov(free_reg.W(), index_reg); |
| 1202 | index_reg = free_reg; |
| 1203 | index = LocationFrom(index_reg); |
| 1204 | } else { |
| 1205 | // The initial register stored in `index_` has already been |
| 1206 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 1207 | // (as it is not a callee-save register), so we can freely |
| 1208 | // use it. |
| 1209 | } |
| 1210 | // Shifting the index value contained in `index_reg` by the scale |
| 1211 | // factor (2) cannot overflow in practice, as the runtime is |
| 1212 | // unable to allocate object arrays with a size larger than |
| 1213 | // 2^26 - 1 (that is, 2^28 - 4 bytes). |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1214 | __ Lsl(index_reg, index_reg, DataType::SizeShift(type)); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1215 | static_assert( |
| 1216 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 1217 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 1218 | __ Add(index_reg, index_reg, Operand(offset_)); |
| 1219 | } else { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 1220 | // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile |
| 1221 | // intrinsics, `index_` is not shifted by a scale factor of 2 |
| 1222 | // (as in the case of ArrayGet), as it is actually an offset |
| 1223 | // to an object field within an object. |
| 1224 | DCHECK(instruction_->IsInvoke()) << instruction_->DebugName(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1225 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 1226 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 1227 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 1228 | << instruction_->AsInvoke()->GetIntrinsic(); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1229 | DCHECK_EQ(offset_, 0u); |
Roland Levillain | a7426c6 | 2016-08-03 15:02:10 +0100 | [diff] [blame] | 1230 | DCHECK(index_.IsRegister()); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1231 | } |
| 1232 | } |
| 1233 | |
| 1234 | // We're moving two or three locations to locations that could |
| 1235 | // overlap, so we need a parallel move resolver. |
| 1236 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1237 | HParallelMove parallel_move(codegen->GetGraph()->GetAllocator()); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1238 | parallel_move.AddMove(ref_, |
| 1239 | LocationFrom(calling_convention.GetRegisterAt(0)), |
| 1240 | type, |
| 1241 | nullptr); |
| 1242 | parallel_move.AddMove(obj_, |
| 1243 | LocationFrom(calling_convention.GetRegisterAt(1)), |
| 1244 | type, |
| 1245 | nullptr); |
| 1246 | if (index.IsValid()) { |
| 1247 | parallel_move.AddMove(index, |
| 1248 | LocationFrom(calling_convention.GetRegisterAt(2)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1249 | DataType::Type::kInt32, |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1250 | nullptr); |
| 1251 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 1252 | } else { |
| 1253 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 1254 | arm64_codegen->MoveConstant(LocationFrom(calling_convention.GetRegisterAt(2)), offset_); |
| 1255 | } |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 1256 | arm64_codegen->InvokeRuntime(kQuickReadBarrierSlow, |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1257 | instruction_, |
| 1258 | instruction_->GetDexPc(), |
| 1259 | this); |
| 1260 | CheckEntrypointTypes< |
| 1261 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 1262 | arm64_codegen->MoveLocation(out_, calling_convention.GetReturnLocation(type), type); |
| 1263 | |
| 1264 | RestoreLiveRegisters(codegen, locations); |
| 1265 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1266 | __ B(GetExitLabel()); |
| 1267 | } |
| 1268 | |
| 1269 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForHeapReferenceSlowPathARM64"; } |
| 1270 | |
| 1271 | private: |
| 1272 | Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1273 | size_t ref = static_cast<int>(XRegisterFrom(ref_).GetCode()); |
| 1274 | size_t obj = static_cast<int>(XRegisterFrom(obj_).GetCode()); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1275 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 1276 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 1277 | return Register(VIXLRegCodeFromART(i), kXRegSize); |
| 1278 | } |
| 1279 | } |
| 1280 | // We shall never fail to find a free caller-save register, as |
| 1281 | // there are more than two core caller-save registers on ARM64 |
| 1282 | // (meaning it is possible to find one which is different from |
| 1283 | // `ref` and `obj`). |
| 1284 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 1285 | LOG(FATAL) << "Could not find a free register"; |
| 1286 | UNREACHABLE(); |
| 1287 | } |
| 1288 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1289 | const Location out_; |
| 1290 | const Location ref_; |
| 1291 | const Location obj_; |
| 1292 | const uint32_t offset_; |
| 1293 | // An additional location containing an index to an array. |
| 1294 | // Only used for HArrayGet and the UnsafeGetObject & |
| 1295 | // UnsafeGetObjectVolatile intrinsics. |
| 1296 | const Location index_; |
| 1297 | |
| 1298 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathARM64); |
| 1299 | }; |
| 1300 | |
| 1301 | // Slow path generating a read barrier for a GC root. |
| 1302 | class ReadBarrierForRootSlowPathARM64 : public SlowPathCodeARM64 { |
| 1303 | public: |
| 1304 | ReadBarrierForRootSlowPathARM64(HInstruction* instruction, Location out, Location root) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 1305 | : SlowPathCodeARM64(instruction), out_(out), root_(root) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1306 | DCHECK(kEmitCompilerReadBarrier); |
| 1307 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1308 | |
| 1309 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 1310 | LocationSummary* locations = instruction_->GetLocations(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1311 | DataType::Type type = DataType::Type::kReference; |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1312 | DCHECK(locations->CanCall()); |
| 1313 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(out_.reg())); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1314 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 1315 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 1316 | << instruction_->DebugName(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1317 | |
| 1318 | __ Bind(GetEntryLabel()); |
| 1319 | SaveLiveRegisters(codegen, locations); |
| 1320 | |
| 1321 | InvokeRuntimeCallingConvention calling_convention; |
| 1322 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 1323 | // The argument of the ReadBarrierForRootSlow is not a managed |
| 1324 | // reference (`mirror::Object*`), but a `GcRoot<mirror::Object>*`; |
| 1325 | // thus we need a 64-bit move here, and we cannot use |
| 1326 | // |
| 1327 | // arm64_codegen->MoveLocation( |
| 1328 | // LocationFrom(calling_convention.GetRegisterAt(0)), |
| 1329 | // root_, |
| 1330 | // type); |
| 1331 | // |
| 1332 | // which would emit a 32-bit move, as `type` is a (32-bit wide) |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1333 | // reference type (`DataType::Type::kReference`). |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1334 | __ Mov(calling_convention.GetRegisterAt(0), XRegisterFrom(out_)); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 1335 | arm64_codegen->InvokeRuntime(kQuickReadBarrierForRootSlow, |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1336 | instruction_, |
| 1337 | instruction_->GetDexPc(), |
| 1338 | this); |
| 1339 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 1340 | arm64_codegen->MoveLocation(out_, calling_convention.GetReturnLocation(type), type); |
| 1341 | |
| 1342 | RestoreLiveRegisters(codegen, locations); |
| 1343 | __ B(GetExitLabel()); |
| 1344 | } |
| 1345 | |
| 1346 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathARM64"; } |
| 1347 | |
| 1348 | private: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1349 | const Location out_; |
| 1350 | const Location root_; |
| 1351 | |
| 1352 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathARM64); |
| 1353 | }; |
| 1354 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1355 | #undef __ |
| 1356 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1357 | Location InvokeDexCallingConventionVisitorARM64::GetNextLocation(DataType::Type type) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1358 | Location next_location; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1359 | if (type == DataType::Type::kVoid) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1360 | LOG(FATAL) << "Unreachable type " << type; |
| 1361 | } |
| 1362 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1363 | if (DataType::IsFloatingPointType(type) && |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1364 | (float_index_ < calling_convention.GetNumberOfFpuRegisters())) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1365 | next_location = LocationFrom(calling_convention.GetFpuRegisterAt(float_index_++)); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1366 | } else if (!DataType::IsFloatingPointType(type) && |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1367 | (gp_index_ < calling_convention.GetNumberOfRegisters())) { |
| 1368 | next_location = LocationFrom(calling_convention.GetRegisterAt(gp_index_++)); |
| 1369 | } else { |
| 1370 | size_t stack_offset = calling_convention.GetStackOffsetOf(stack_index_); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1371 | next_location = DataType::Is64BitType(type) ? Location::DoubleStackSlot(stack_offset) |
| 1372 | : Location::StackSlot(stack_offset); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1373 | } |
| 1374 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1375 | // Space on the stack is reserved for all arguments. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1376 | stack_index_ += DataType::Is64BitType(type) ? 2 : 1; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1377 | return next_location; |
| 1378 | } |
| 1379 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1380 | Location InvokeDexCallingConventionVisitorARM64::GetMethodLocation() const { |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 1381 | return LocationFrom(kArtMethodRegister); |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1382 | } |
| 1383 | |
Serban Constantinescu | 579885a | 2015-02-22 20:51:33 +0000 | [diff] [blame] | 1384 | CodeGeneratorARM64::CodeGeneratorARM64(HGraph* graph, |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 1385 | const CompilerOptions& compiler_options, |
| 1386 | OptimizingCompilerStats* stats) |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1387 | : CodeGenerator(graph, |
| 1388 | kNumberOfAllocatableRegisters, |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1389 | kNumberOfAllocatableFPRegisters, |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 1390 | kNumberOfAllocatableRegisterPairs, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1391 | callee_saved_core_registers.GetList(), |
| 1392 | callee_saved_fp_registers.GetList(), |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 1393 | compiler_options, |
| 1394 | stats), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1395 | block_labels_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1396 | jump_tables_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1397 | location_builder_(graph, this), |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1398 | instruction_visitor_(graph, this), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1399 | move_resolver_(graph->GetAllocator(), this), |
| 1400 | assembler_(graph->GetAllocator()), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1401 | uint32_literals_(std::less<uint32_t>(), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1402 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 1403 | uint64_literals_(std::less<uint64_t>(), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1404 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1405 | boot_image_method_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1406 | method_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1407 | boot_image_type_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1408 | type_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1409 | boot_image_string_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1410 | string_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 1411 | boot_image_intrinsic_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1412 | baker_read_barrier_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 1413 | jit_string_patches_(StringReferenceValueComparator(), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1414 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 1415 | jit_class_patches_(TypeReferenceValueComparator(), |
Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 1416 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1417 | jit_baker_read_barrier_slow_paths_(std::less<uint32_t>(), |
| 1418 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1419 | // Save the link register (containing the return address) to mimic Quick. |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1420 | AddAllocatedRegister(LocationFrom(lr)); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1421 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1422 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1423 | #define __ GetVIXLAssembler()-> |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1424 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 1425 | void CodeGeneratorARM64::EmitJumpTables() { |
Alexandre Rames | c01a664 | 2016-04-15 11:54:06 +0100 | [diff] [blame] | 1426 | for (auto&& jump_table : jump_tables_) { |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 1427 | jump_table->EmitTable(this); |
| 1428 | } |
| 1429 | } |
| 1430 | |
Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 1431 | void CodeGeneratorARM64::Finalize(CodeAllocator* allocator) { |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 1432 | EmitJumpTables(); |
Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 1433 | |
| 1434 | // Emit JIT baker read barrier slow paths. |
| 1435 | DCHECK(Runtime::Current()->UseJitCompilation() || jit_baker_read_barrier_slow_paths_.empty()); |
| 1436 | for (auto& entry : jit_baker_read_barrier_slow_paths_) { |
| 1437 | uint32_t encoded_data = entry.first; |
| 1438 | vixl::aarch64::Label* slow_path_entry = &entry.second.label; |
| 1439 | __ Bind(slow_path_entry); |
| 1440 | CompileBakerReadBarrierThunk(*GetAssembler(), encoded_data, /* debug_name */ nullptr); |
| 1441 | } |
| 1442 | |
Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 1443 | // Ensure we emit the literal pool. |
| 1444 | __ FinalizeCode(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1445 | |
Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 1446 | CodeGenerator::Finalize(allocator); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 1447 | |
| 1448 | // Verify Baker read barrier linker patches. |
| 1449 | if (kIsDebugBuild) { |
| 1450 | ArrayRef<const uint8_t> code = allocator->GetMemory(); |
| 1451 | for (const BakerReadBarrierPatchInfo& info : baker_read_barrier_patches_) { |
| 1452 | DCHECK(info.label.IsBound()); |
| 1453 | uint32_t literal_offset = info.label.GetLocation(); |
| 1454 | DCHECK_ALIGNED(literal_offset, 4u); |
| 1455 | |
| 1456 | auto GetInsn = [&code](uint32_t offset) { |
| 1457 | DCHECK_ALIGNED(offset, 4u); |
| 1458 | return |
| 1459 | (static_cast<uint32_t>(code[offset + 0]) << 0) + |
| 1460 | (static_cast<uint32_t>(code[offset + 1]) << 8) + |
| 1461 | (static_cast<uint32_t>(code[offset + 2]) << 16)+ |
| 1462 | (static_cast<uint32_t>(code[offset + 3]) << 24); |
| 1463 | }; |
| 1464 | |
| 1465 | const uint32_t encoded_data = info.custom_data; |
| 1466 | BakerReadBarrierKind kind = BakerReadBarrierKindField::Decode(encoded_data); |
| 1467 | // Check that the next instruction matches the expected LDR. |
| 1468 | switch (kind) { |
| 1469 | case BakerReadBarrierKind::kField: { |
| 1470 | DCHECK_GE(code.size() - literal_offset, 8u); |
| 1471 | uint32_t next_insn = GetInsn(literal_offset + 4u); |
| 1472 | // LDR (immediate) with correct base_reg. |
| 1473 | CheckValidReg(next_insn & 0x1fu); // Check destination register. |
| 1474 | const uint32_t base_reg = BakerReadBarrierFirstRegField::Decode(encoded_data); |
| 1475 | CHECK_EQ(next_insn & 0xffc003e0u, 0xb9400000u | (base_reg << 5)); |
| 1476 | break; |
| 1477 | } |
| 1478 | case BakerReadBarrierKind::kArray: { |
| 1479 | DCHECK_GE(code.size() - literal_offset, 8u); |
| 1480 | uint32_t next_insn = GetInsn(literal_offset + 4u); |
| 1481 | // LDR (register) with the correct base_reg, size=10 (32-bit), option=011 (extend = LSL), |
| 1482 | // and S=1 (shift amount = 2 for 32-bit version), i.e. LDR Wt, [Xn, Xm, LSL #2]. |
| 1483 | CheckValidReg(next_insn & 0x1fu); // Check destination register. |
| 1484 | const uint32_t base_reg = BakerReadBarrierFirstRegField::Decode(encoded_data); |
| 1485 | CHECK_EQ(next_insn & 0xffe0ffe0u, 0xb8607800u | (base_reg << 5)); |
| 1486 | CheckValidReg((next_insn >> 16) & 0x1f); // Check index register |
| 1487 | break; |
| 1488 | } |
| 1489 | case BakerReadBarrierKind::kGcRoot: { |
| 1490 | DCHECK_GE(literal_offset, 4u); |
| 1491 | uint32_t prev_insn = GetInsn(literal_offset - 4u); |
| 1492 | // LDR (immediate) with correct root_reg. |
| 1493 | const uint32_t root_reg = BakerReadBarrierFirstRegField::Decode(encoded_data); |
| 1494 | CHECK_EQ(prev_insn & 0xffc0001fu, 0xb9400000u | root_reg); |
| 1495 | break; |
| 1496 | } |
| 1497 | default: |
| 1498 | LOG(FATAL) << "Unexpected kind: " << static_cast<uint32_t>(kind); |
| 1499 | UNREACHABLE(); |
| 1500 | } |
| 1501 | } |
| 1502 | } |
Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 1503 | } |
| 1504 | |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1505 | void ParallelMoveResolverARM64::PrepareForEmitNativeCode() { |
| 1506 | // Note: There are 6 kinds of moves: |
| 1507 | // 1. constant -> GPR/FPR (non-cycle) |
| 1508 | // 2. constant -> stack (non-cycle) |
| 1509 | // 3. GPR/FPR -> GPR/FPR |
| 1510 | // 4. GPR/FPR -> stack |
| 1511 | // 5. stack -> GPR/FPR |
| 1512 | // 6. stack -> stack (non-cycle) |
| 1513 | // Case 1, 2 and 6 should never be included in a dependency cycle on ARM64. For case 3, 4, and 5 |
| 1514 | // VIXL uses at most 1 GPR. VIXL has 2 GPR and 1 FPR temps, and there should be no intersecting |
| 1515 | // cycles on ARM64, so we always have 1 GPR and 1 FPR available VIXL temps to resolve the |
| 1516 | // dependency. |
| 1517 | vixl_temps_.Open(GetVIXLAssembler()); |
| 1518 | } |
| 1519 | |
| 1520 | void ParallelMoveResolverARM64::FinishEmitNativeCode() { |
| 1521 | vixl_temps_.Close(); |
| 1522 | } |
| 1523 | |
| 1524 | Location ParallelMoveResolverARM64::AllocateScratchLocationFor(Location::Kind kind) { |
Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 1525 | DCHECK(kind == Location::kRegister || kind == Location::kFpuRegister |
| 1526 | || kind == Location::kStackSlot || kind == Location::kDoubleStackSlot |
| 1527 | || kind == Location::kSIMDStackSlot); |
| 1528 | kind = (kind == Location::kFpuRegister || kind == Location::kSIMDStackSlot) |
| 1529 | ? Location::kFpuRegister |
| 1530 | : Location::kRegister; |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1531 | Location scratch = GetScratchLocation(kind); |
| 1532 | if (!scratch.Equals(Location::NoLocation())) { |
| 1533 | return scratch; |
| 1534 | } |
| 1535 | // Allocate from VIXL temp registers. |
| 1536 | if (kind == Location::kRegister) { |
| 1537 | scratch = LocationFrom(vixl_temps_.AcquireX()); |
| 1538 | } else { |
Roland Levillain | 952b235 | 2017-05-03 19:49:14 +0100 | [diff] [blame] | 1539 | DCHECK_EQ(kind, Location::kFpuRegister); |
Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 1540 | scratch = LocationFrom(codegen_->GetGraph()->HasSIMD() |
| 1541 | ? vixl_temps_.AcquireVRegisterOfSize(kQRegSize) |
| 1542 | : vixl_temps_.AcquireD()); |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1543 | } |
| 1544 | AddScratchLocation(scratch); |
| 1545 | return scratch; |
| 1546 | } |
| 1547 | |
| 1548 | void ParallelMoveResolverARM64::FreeScratchLocation(Location loc) { |
| 1549 | if (loc.IsRegister()) { |
| 1550 | vixl_temps_.Release(XRegisterFrom(loc)); |
| 1551 | } else { |
| 1552 | DCHECK(loc.IsFpuRegister()); |
Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 1553 | vixl_temps_.Release(codegen_->GetGraph()->HasSIMD() ? QRegisterFrom(loc) : DRegisterFrom(loc)); |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1554 | } |
| 1555 | RemoveScratchLocation(loc); |
| 1556 | } |
| 1557 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1558 | void ParallelMoveResolverARM64::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 1559 | MoveOperands* move = moves_[index]; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1560 | codegen_->MoveLocation(move->GetDestination(), move->GetSource(), DataType::Type::kVoid); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1561 | } |
| 1562 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1563 | void CodeGeneratorARM64::GenerateFrameEntry() { |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1564 | MacroAssembler* masm = GetVIXLAssembler(); |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1565 | __ Bind(&frame_entry_label_); |
| 1566 | |
Nicolas Geoffray | 8d72832 | 2018-01-18 22:44:32 +0000 | [diff] [blame] | 1567 | if (GetCompilerOptions().CountHotnessInCompiledCode()) { |
| 1568 | UseScratchRegisterScope temps(masm); |
| 1569 | Register temp = temps.AcquireX(); |
| 1570 | __ Ldrh(temp, MemOperand(kArtMethodRegister, ArtMethod::HotnessCountOffset().Int32Value())); |
| 1571 | __ Add(temp, temp, 1); |
| 1572 | __ Strh(temp, MemOperand(kArtMethodRegister, ArtMethod::HotnessCountOffset().Int32Value())); |
| 1573 | } |
| 1574 | |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 1575 | bool do_overflow_check = |
| 1576 | FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kArm64) || !IsLeafMethod(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1577 | if (do_overflow_check) { |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1578 | UseScratchRegisterScope temps(masm); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1579 | Register temp = temps.AcquireX(); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1580 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 1581 | __ Sub(temp, sp, static_cast<int32_t>(GetStackOverflowReservedBytes(InstructionSet::kArm64))); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1582 | { |
| 1583 | // Ensure that between load and RecordPcInfo there are no pools emitted. |
| 1584 | ExactAssemblyScope eas(GetVIXLAssembler(), |
| 1585 | kInstructionSize, |
| 1586 | CodeBufferCheckScope::kExactSize); |
| 1587 | __ ldr(wzr, MemOperand(temp, 0)); |
| 1588 | RecordPcInfo(nullptr, 0); |
| 1589 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1590 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1591 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1592 | if (!HasEmptyFrame()) { |
| 1593 | int frame_size = GetFrameSize(); |
| 1594 | // Stack layout: |
| 1595 | // sp[frame_size - 8] : lr. |
| 1596 | // ... : other preserved core registers. |
| 1597 | // ... : other preserved fp registers. |
| 1598 | // ... : reserved frame space. |
| 1599 | // sp[0] : current method. |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1600 | |
| 1601 | // Save the current method if we need it. Note that we do not |
| 1602 | // do this in HCurrentMethod, as the instruction might have been removed |
| 1603 | // in the SSA graph. |
| 1604 | if (RequiresCurrentMethod()) { |
| 1605 | __ Str(kArtMethodRegister, MemOperand(sp, -frame_size, PreIndex)); |
Nicolas Geoffray | 9989b16 | 2016-10-13 13:42:30 +0100 | [diff] [blame] | 1606 | } else { |
| 1607 | __ Claim(frame_size); |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1608 | } |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1609 | GetAssembler()->cfi().AdjustCFAOffset(frame_size); |
Zheng Xu | 69a5030 | 2015-04-14 20:04:41 +0800 | [diff] [blame] | 1610 | GetAssembler()->SpillRegisters(GetFramePreservedCoreRegisters(), |
| 1611 | frame_size - GetCoreSpillSize()); |
| 1612 | GetAssembler()->SpillRegisters(GetFramePreservedFPRegisters(), |
| 1613 | frame_size - FrameEntrySpillSize()); |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 1614 | |
| 1615 | if (GetGraph()->HasShouldDeoptimizeFlag()) { |
| 1616 | // Initialize should_deoptimize flag to 0. |
| 1617 | Register wzr = Register(VIXLRegCodeFromART(WZR), kWRegSize); |
| 1618 | __ Str(wzr, MemOperand(sp, GetStackOffsetOfShouldDeoptimizeFlag())); |
| 1619 | } |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1620 | } |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 1621 | |
| 1622 | MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1623 | } |
| 1624 | |
| 1625 | void CodeGeneratorARM64::GenerateFrameExit() { |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1626 | GetAssembler()->cfi().RememberState(); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1627 | if (!HasEmptyFrame()) { |
| 1628 | int frame_size = GetFrameSize(); |
Zheng Xu | 69a5030 | 2015-04-14 20:04:41 +0800 | [diff] [blame] | 1629 | GetAssembler()->UnspillRegisters(GetFramePreservedFPRegisters(), |
| 1630 | frame_size - FrameEntrySpillSize()); |
| 1631 | GetAssembler()->UnspillRegisters(GetFramePreservedCoreRegisters(), |
| 1632 | frame_size - GetCoreSpillSize()); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1633 | __ Drop(frame_size); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1634 | GetAssembler()->cfi().AdjustCFAOffset(-frame_size); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1635 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1636 | __ Ret(); |
| 1637 | GetAssembler()->cfi().RestoreState(); |
| 1638 | GetAssembler()->cfi().DefCFAOffset(GetFrameSize()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1639 | } |
| 1640 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1641 | CPURegList CodeGeneratorARM64::GetFramePreservedCoreRegisters() const { |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1642 | DCHECK(ArtVixlRegCodeCoherentForRegSet(core_spill_mask_, GetNumberOfCoreRegisters(), 0, 0)); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1643 | return CPURegList(CPURegister::kRegister, kXRegSize, |
| 1644 | core_spill_mask_); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1645 | } |
| 1646 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1647 | CPURegList CodeGeneratorARM64::GetFramePreservedFPRegisters() const { |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1648 | DCHECK(ArtVixlRegCodeCoherentForRegSet(0, 0, fpu_spill_mask_, |
| 1649 | GetNumberOfFloatingPointRegisters())); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1650 | return CPURegList(CPURegister::kFPRegister, kDRegSize, |
| 1651 | fpu_spill_mask_); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1652 | } |
| 1653 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1654 | void CodeGeneratorARM64::Bind(HBasicBlock* block) { |
| 1655 | __ Bind(GetLabelOf(block)); |
| 1656 | } |
| 1657 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1658 | void CodeGeneratorARM64::MoveConstant(Location location, int32_t value) { |
| 1659 | DCHECK(location.IsRegister()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1660 | __ Mov(RegisterFrom(location, DataType::Type::kInt32), value); |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1661 | } |
| 1662 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1663 | void CodeGeneratorARM64::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1664 | if (location.IsRegister()) { |
| 1665 | locations->AddTemp(location); |
| 1666 | } else { |
| 1667 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1668 | } |
| 1669 | } |
| 1670 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1671 | void CodeGeneratorARM64::MarkGCCard(Register object, Register value, bool value_can_be_null) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1672 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1673 | Register card = temps.AcquireX(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1674 | Register temp = temps.AcquireW(); // Index within the CardTable - 32bit. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1675 | vixl::aarch64::Label done; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1676 | if (value_can_be_null) { |
| 1677 | __ Cbz(value, &done); |
| 1678 | } |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1679 | __ Ldr(card, MemOperand(tr, Thread::CardTableOffset<kArm64PointerSize>().Int32Value())); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1680 | __ Lsr(temp, object, gc::accounting::CardTable::kCardShift); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1681 | __ Strb(card, MemOperand(card, temp.X())); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1682 | if (value_can_be_null) { |
| 1683 | __ Bind(&done); |
| 1684 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1685 | } |
| 1686 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1687 | void CodeGeneratorARM64::SetupBlockedRegisters() const { |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1688 | // Blocked core registers: |
| 1689 | // lr : Runtime reserved. |
| 1690 | // tr : Runtime reserved. |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 1691 | // mr : Runtime reserved. |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1692 | // ip1 : VIXL core temp. |
| 1693 | // ip0 : VIXL core temp. |
| 1694 | // |
| 1695 | // Blocked fp registers: |
| 1696 | // d31 : VIXL fp temp. |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1697 | CPURegList reserved_core_registers = vixl_reserved_core_registers; |
| 1698 | reserved_core_registers.Combine(runtime_reserved_core_registers); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1699 | while (!reserved_core_registers.IsEmpty()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1700 | blocked_core_registers_[reserved_core_registers.PopLowestIndex().GetCode()] = true; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1701 | } |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1702 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1703 | CPURegList reserved_fp_registers = vixl_reserved_fp_registers; |
Zheng Xu | a3ec394 | 2015-02-15 18:39:46 +0800 | [diff] [blame] | 1704 | while (!reserved_fp_registers.IsEmpty()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1705 | blocked_fpu_registers_[reserved_fp_registers.PopLowestIndex().GetCode()] = true; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1706 | } |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1707 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1708 | if (GetGraph()->IsDebuggable()) { |
Nicolas Geoffray | ecf680d | 2015-10-05 11:15:37 +0100 | [diff] [blame] | 1709 | // Stubs do not save callee-save floating point registers. If the graph |
| 1710 | // is debuggable, we need to deal with these registers differently. For |
| 1711 | // now, just block them. |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1712 | CPURegList reserved_fp_registers_debuggable = callee_saved_fp_registers; |
| 1713 | while (!reserved_fp_registers_debuggable.IsEmpty()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1714 | blocked_fpu_registers_[reserved_fp_registers_debuggable.PopLowestIndex().GetCode()] = true; |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1715 | } |
| 1716 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1717 | } |
| 1718 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1719 | size_t CodeGeneratorARM64::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1720 | Register reg = Register(VIXLRegCodeFromART(reg_id), kXRegSize); |
| 1721 | __ Str(reg, MemOperand(sp, stack_index)); |
| 1722 | return kArm64WordSize; |
| 1723 | } |
| 1724 | |
| 1725 | size_t CodeGeneratorARM64::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1726 | Register reg = Register(VIXLRegCodeFromART(reg_id), kXRegSize); |
| 1727 | __ Ldr(reg, MemOperand(sp, stack_index)); |
| 1728 | return kArm64WordSize; |
| 1729 | } |
| 1730 | |
| 1731 | size_t CodeGeneratorARM64::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 1732 | FPRegister reg = FPRegister(reg_id, kDRegSize); |
| 1733 | __ Str(reg, MemOperand(sp, stack_index)); |
| 1734 | return kArm64WordSize; |
| 1735 | } |
| 1736 | |
| 1737 | size_t CodeGeneratorARM64::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 1738 | FPRegister reg = FPRegister(reg_id, kDRegSize); |
| 1739 | __ Ldr(reg, MemOperand(sp, stack_index)); |
| 1740 | return kArm64WordSize; |
| 1741 | } |
| 1742 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1743 | void CodeGeneratorARM64::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1744 | stream << XRegister(reg); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1745 | } |
| 1746 | |
| 1747 | void CodeGeneratorARM64::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1748 | stream << DRegister(reg); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1749 | } |
| 1750 | |
Vladimir Marko | a043111 | 2018-06-25 09:32:54 +0100 | [diff] [blame] | 1751 | const Arm64InstructionSetFeatures& CodeGeneratorARM64::GetInstructionSetFeatures() const { |
| 1752 | return *GetCompilerOptions().GetInstructionSetFeatures()->AsArm64InstructionSetFeatures(); |
| 1753 | } |
| 1754 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1755 | void CodeGeneratorARM64::MoveConstant(CPURegister destination, HConstant* constant) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1756 | if (constant->IsIntConstant()) { |
| 1757 | __ Mov(Register(destination), constant->AsIntConstant()->GetValue()); |
| 1758 | } else if (constant->IsLongConstant()) { |
| 1759 | __ Mov(Register(destination), constant->AsLongConstant()->GetValue()); |
| 1760 | } else if (constant->IsNullConstant()) { |
| 1761 | __ Mov(Register(destination), 0); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1762 | } else if (constant->IsFloatConstant()) { |
| 1763 | __ Fmov(FPRegister(destination), constant->AsFloatConstant()->GetValue()); |
| 1764 | } else { |
| 1765 | DCHECK(constant->IsDoubleConstant()); |
| 1766 | __ Fmov(FPRegister(destination), constant->AsDoubleConstant()->GetValue()); |
| 1767 | } |
| 1768 | } |
| 1769 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1770 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1771 | static bool CoherentConstantAndType(Location constant, DataType::Type type) { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1772 | DCHECK(constant.IsConstant()); |
| 1773 | HConstant* cst = constant.GetConstant(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1774 | return (cst->IsIntConstant() && type == DataType::Type::kInt32) || |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1775 | // Null is mapped to a core W register, which we associate with kPrimInt. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1776 | (cst->IsNullConstant() && type == DataType::Type::kInt32) || |
| 1777 | (cst->IsLongConstant() && type == DataType::Type::kInt64) || |
| 1778 | (cst->IsFloatConstant() && type == DataType::Type::kFloat32) || |
| 1779 | (cst->IsDoubleConstant() && type == DataType::Type::kFloat64); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1780 | } |
| 1781 | |
Roland Levillain | 952b235 | 2017-05-03 19:49:14 +0100 | [diff] [blame] | 1782 | // Allocate a scratch register from the VIXL pool, querying first |
| 1783 | // the floating-point register pool, and then the core register |
| 1784 | // pool. This is essentially a reimplementation of |
Roland Levillain | 558dea1 | 2017-01-27 19:40:44 +0000 | [diff] [blame] | 1785 | // vixl::aarch64::UseScratchRegisterScope::AcquireCPURegisterOfSize |
| 1786 | // using a different allocation strategy. |
| 1787 | static CPURegister AcquireFPOrCoreCPURegisterOfSize(vixl::aarch64::MacroAssembler* masm, |
| 1788 | vixl::aarch64::UseScratchRegisterScope* temps, |
| 1789 | int size_in_bits) { |
| 1790 | return masm->GetScratchFPRegisterList()->IsEmpty() |
| 1791 | ? CPURegister(temps->AcquireRegisterOfSize(size_in_bits)) |
| 1792 | : CPURegister(temps->AcquireVRegisterOfSize(size_in_bits)); |
| 1793 | } |
| 1794 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1795 | void CodeGeneratorARM64::MoveLocation(Location destination, |
| 1796 | Location source, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1797 | DataType::Type dst_type) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1798 | if (source.Equals(destination)) { |
| 1799 | return; |
| 1800 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1801 | |
| 1802 | // A valid move can always be inferred from the destination and source |
| 1803 | // locations. When moving from and to a register, the argument type can be |
| 1804 | // used to generate 32bit instead of 64bit moves. In debug mode we also |
| 1805 | // checks the coherency of the locations and the type. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1806 | bool unspecified_type = (dst_type == DataType::Type::kVoid); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1807 | |
| 1808 | if (destination.IsRegister() || destination.IsFpuRegister()) { |
| 1809 | if (unspecified_type) { |
| 1810 | HConstant* src_cst = source.IsConstant() ? source.GetConstant() : nullptr; |
| 1811 | if (source.IsStackSlot() || |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1812 | (src_cst != nullptr && (src_cst->IsIntConstant() |
| 1813 | || src_cst->IsFloatConstant() |
| 1814 | || src_cst->IsNullConstant()))) { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1815 | // For stack slots and 32bit constants, a 64bit type is appropriate. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1816 | dst_type = destination.IsRegister() ? DataType::Type::kInt32 : DataType::Type::kFloat32; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1817 | } else { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1818 | // If the source is a double stack slot or a 64bit constant, a 64bit |
| 1819 | // type is appropriate. Else the source is a register, and since the |
| 1820 | // type has not been specified, we chose a 64bit type to force a 64bit |
| 1821 | // move. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1822 | dst_type = destination.IsRegister() ? DataType::Type::kInt64 : DataType::Type::kFloat64; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1823 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1824 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1825 | DCHECK((destination.IsFpuRegister() && DataType::IsFloatingPointType(dst_type)) || |
| 1826 | (destination.IsRegister() && !DataType::IsFloatingPointType(dst_type))); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1827 | CPURegister dst = CPURegisterFrom(destination, dst_type); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1828 | if (source.IsStackSlot() || source.IsDoubleStackSlot()) { |
| 1829 | DCHECK(dst.Is64Bits() == source.IsDoubleStackSlot()); |
| 1830 | __ Ldr(dst, StackOperandFrom(source)); |
Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 1831 | } else if (source.IsSIMDStackSlot()) { |
| 1832 | __ Ldr(QRegisterFrom(destination), StackOperandFrom(source)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1833 | } else if (source.IsConstant()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1834 | DCHECK(CoherentConstantAndType(source, dst_type)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1835 | MoveConstant(dst, source.GetConstant()); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1836 | } else if (source.IsRegister()) { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1837 | if (destination.IsRegister()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1838 | __ Mov(Register(dst), RegisterFrom(source, dst_type)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1839 | } else { |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1840 | DCHECK(destination.IsFpuRegister()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1841 | DataType::Type source_type = DataType::Is64BitType(dst_type) |
| 1842 | ? DataType::Type::kInt64 |
| 1843 | : DataType::Type::kInt32; |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1844 | __ Fmov(FPRegisterFrom(destination, dst_type), RegisterFrom(source, source_type)); |
| 1845 | } |
| 1846 | } else { |
| 1847 | DCHECK(source.IsFpuRegister()); |
| 1848 | if (destination.IsRegister()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1849 | DataType::Type source_type = DataType::Is64BitType(dst_type) |
| 1850 | ? DataType::Type::kFloat64 |
| 1851 | : DataType::Type::kFloat32; |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1852 | __ Fmov(RegisterFrom(destination, dst_type), FPRegisterFrom(source, source_type)); |
| 1853 | } else { |
| 1854 | DCHECK(destination.IsFpuRegister()); |
Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 1855 | if (GetGraph()->HasSIMD()) { |
| 1856 | __ Mov(QRegisterFrom(destination), QRegisterFrom(source)); |
| 1857 | } else { |
| 1858 | __ Fmov(FPRegister(dst), FPRegisterFrom(source, dst_type)); |
| 1859 | } |
| 1860 | } |
| 1861 | } |
| 1862 | } else if (destination.IsSIMDStackSlot()) { |
| 1863 | if (source.IsFpuRegister()) { |
| 1864 | __ Str(QRegisterFrom(source), StackOperandFrom(destination)); |
| 1865 | } else { |
| 1866 | DCHECK(source.IsSIMDStackSlot()); |
| 1867 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 1868 | if (GetVIXLAssembler()->GetScratchFPRegisterList()->IsEmpty()) { |
| 1869 | Register temp = temps.AcquireX(); |
| 1870 | __ Ldr(temp, MemOperand(sp, source.GetStackIndex())); |
| 1871 | __ Str(temp, MemOperand(sp, destination.GetStackIndex())); |
| 1872 | __ Ldr(temp, MemOperand(sp, source.GetStackIndex() + kArm64WordSize)); |
| 1873 | __ Str(temp, MemOperand(sp, destination.GetStackIndex() + kArm64WordSize)); |
| 1874 | } else { |
| 1875 | FPRegister temp = temps.AcquireVRegisterOfSize(kQRegSize); |
| 1876 | __ Ldr(temp, StackOperandFrom(source)); |
| 1877 | __ Str(temp, StackOperandFrom(destination)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1878 | } |
| 1879 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1880 | } else { // The destination is not a register. It must be a stack slot. |
| 1881 | DCHECK(destination.IsStackSlot() || destination.IsDoubleStackSlot()); |
| 1882 | if (source.IsRegister() || source.IsFpuRegister()) { |
| 1883 | if (unspecified_type) { |
| 1884 | if (source.IsRegister()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1885 | dst_type = destination.IsStackSlot() ? DataType::Type::kInt32 : DataType::Type::kInt64; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1886 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1887 | dst_type = |
| 1888 | destination.IsStackSlot() ? DataType::Type::kFloat32 : DataType::Type::kFloat64; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1889 | } |
| 1890 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1891 | DCHECK((destination.IsDoubleStackSlot() == DataType::Is64BitType(dst_type)) && |
| 1892 | (source.IsFpuRegister() == DataType::IsFloatingPointType(dst_type))); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1893 | __ Str(CPURegisterFrom(source, dst_type), StackOperandFrom(destination)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1894 | } else if (source.IsConstant()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1895 | DCHECK(unspecified_type || CoherentConstantAndType(source, dst_type)) |
| 1896 | << source << " " << dst_type; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1897 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 1898 | HConstant* src_cst = source.GetConstant(); |
| 1899 | CPURegister temp; |
Alexandre Rames | b2b753c | 2016-08-02 13:45:28 +0100 | [diff] [blame] | 1900 | if (src_cst->IsZeroBitPattern()) { |
Scott Wakeling | 79db997 | 2017-01-19 14:08:42 +0000 | [diff] [blame] | 1901 | temp = (src_cst->IsLongConstant() || src_cst->IsDoubleConstant()) |
| 1902 | ? Register(xzr) |
| 1903 | : Register(wzr); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1904 | } else { |
Alexandre Rames | b2b753c | 2016-08-02 13:45:28 +0100 | [diff] [blame] | 1905 | if (src_cst->IsIntConstant()) { |
| 1906 | temp = temps.AcquireW(); |
| 1907 | } else if (src_cst->IsLongConstant()) { |
| 1908 | temp = temps.AcquireX(); |
| 1909 | } else if (src_cst->IsFloatConstant()) { |
| 1910 | temp = temps.AcquireS(); |
| 1911 | } else { |
| 1912 | DCHECK(src_cst->IsDoubleConstant()); |
| 1913 | temp = temps.AcquireD(); |
| 1914 | } |
| 1915 | MoveConstant(temp, src_cst); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1916 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1917 | __ Str(temp, StackOperandFrom(destination)); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1918 | } else { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1919 | DCHECK(source.IsStackSlot() || source.IsDoubleStackSlot()); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1920 | DCHECK(source.IsDoubleStackSlot() == destination.IsDoubleStackSlot()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1921 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Roland Levillain | 78b3d5d | 2017-01-04 10:27:50 +0000 | [diff] [blame] | 1922 | // Use any scratch register (a core or a floating-point one) |
| 1923 | // from VIXL scratch register pools as a temporary. |
| 1924 | // |
| 1925 | // We used to only use the FP scratch register pool, but in some |
| 1926 | // rare cases the only register from this pool (D31) would |
| 1927 | // already be used (e.g. within a ParallelMove instruction, when |
| 1928 | // a move is blocked by a another move requiring a scratch FP |
| 1929 | // register, which would reserve D31). To prevent this issue, we |
| 1930 | // ask for a scratch register of any type (core or FP). |
Roland Levillain | 558dea1 | 2017-01-27 19:40:44 +0000 | [diff] [blame] | 1931 | // |
| 1932 | // Also, we start by asking for a FP scratch register first, as the |
Roland Levillain | 952b235 | 2017-05-03 19:49:14 +0100 | [diff] [blame] | 1933 | // demand of scratch core registers is higher. This is why we |
Roland Levillain | 558dea1 | 2017-01-27 19:40:44 +0000 | [diff] [blame] | 1934 | // use AcquireFPOrCoreCPURegisterOfSize instead of |
| 1935 | // UseScratchRegisterScope::AcquireCPURegisterOfSize, which |
| 1936 | // allocates core scratch registers first. |
| 1937 | CPURegister temp = AcquireFPOrCoreCPURegisterOfSize( |
| 1938 | GetVIXLAssembler(), |
| 1939 | &temps, |
| 1940 | (destination.IsDoubleStackSlot() ? kXRegSize : kWRegSize)); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1941 | __ Ldr(temp, StackOperandFrom(source)); |
| 1942 | __ Str(temp, StackOperandFrom(destination)); |
| 1943 | } |
| 1944 | } |
| 1945 | } |
| 1946 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1947 | void CodeGeneratorARM64::Load(DataType::Type type, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1948 | CPURegister dst, |
| 1949 | const MemOperand& src) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1950 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1951 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1952 | case DataType::Type::kUint8: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1953 | __ Ldrb(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1954 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1955 | case DataType::Type::kInt8: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1956 | __ Ldrsb(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1957 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1958 | case DataType::Type::kUint16: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1959 | __ Ldrh(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1960 | break; |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1961 | case DataType::Type::kInt16: |
| 1962 | __ Ldrsh(Register(dst), src); |
| 1963 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1964 | case DataType::Type::kInt32: |
| 1965 | case DataType::Type::kReference: |
| 1966 | case DataType::Type::kInt64: |
| 1967 | case DataType::Type::kFloat32: |
| 1968 | case DataType::Type::kFloat64: |
| 1969 | DCHECK_EQ(dst.Is64Bits(), DataType::Is64BitType(type)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1970 | __ Ldr(dst, src); |
| 1971 | break; |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 1972 | case DataType::Type::kUint32: |
| 1973 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1974 | case DataType::Type::kVoid: |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1975 | LOG(FATAL) << "Unreachable type " << type; |
| 1976 | } |
| 1977 | } |
| 1978 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1979 | void CodeGeneratorARM64::LoadAcquire(HInstruction* instruction, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1980 | CPURegister dst, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1981 | const MemOperand& src, |
| 1982 | bool needs_null_check) { |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1983 | MacroAssembler* masm = GetVIXLAssembler(); |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1984 | UseScratchRegisterScope temps(masm); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1985 | Register temp_base = temps.AcquireX(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1986 | DataType::Type type = instruction->GetType(); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1987 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1988 | DCHECK(!src.IsPreIndex()); |
| 1989 | DCHECK(!src.IsPostIndex()); |
| 1990 | |
| 1991 | // TODO(vixl): Let the MacroAssembler handle MemOperand. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1992 | __ Add(temp_base, src.GetBaseRegister(), OperandFromMemOperand(src)); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1993 | { |
| 1994 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 1995 | MemOperand base = MemOperand(temp_base); |
| 1996 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1997 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1998 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1999 | case DataType::Type::kInt8: |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2000 | { |
| 2001 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 2002 | __ ldarb(Register(dst), base); |
| 2003 | if (needs_null_check) { |
| 2004 | MaybeRecordImplicitNullCheck(instruction); |
| 2005 | } |
| 2006 | } |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2007 | if (type == DataType::Type::kInt8) { |
| 2008 | __ Sbfx(Register(dst), Register(dst), 0, DataType::Size(type) * kBitsPerByte); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2009 | } |
| 2010 | break; |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2011 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2012 | case DataType::Type::kInt16: |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2013 | { |
| 2014 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 2015 | __ ldarh(Register(dst), base); |
| 2016 | if (needs_null_check) { |
| 2017 | MaybeRecordImplicitNullCheck(instruction); |
| 2018 | } |
| 2019 | } |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2020 | if (type == DataType::Type::kInt16) { |
| 2021 | __ Sbfx(Register(dst), Register(dst), 0, DataType::Size(type) * kBitsPerByte); |
| 2022 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2023 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2024 | case DataType::Type::kInt32: |
| 2025 | case DataType::Type::kReference: |
| 2026 | case DataType::Type::kInt64: |
| 2027 | DCHECK_EQ(dst.Is64Bits(), DataType::Is64BitType(type)); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2028 | { |
| 2029 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 2030 | __ ldar(Register(dst), base); |
| 2031 | if (needs_null_check) { |
| 2032 | MaybeRecordImplicitNullCheck(instruction); |
| 2033 | } |
| 2034 | } |
| 2035 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2036 | case DataType::Type::kFloat32: |
| 2037 | case DataType::Type::kFloat64: { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2038 | DCHECK(dst.IsFPRegister()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2039 | DCHECK_EQ(dst.Is64Bits(), DataType::Is64BitType(type)); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2040 | |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2041 | Register temp = dst.Is64Bits() ? temps.AcquireX() : temps.AcquireW(); |
| 2042 | { |
| 2043 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 2044 | __ ldar(temp, base); |
| 2045 | if (needs_null_check) { |
| 2046 | MaybeRecordImplicitNullCheck(instruction); |
| 2047 | } |
| 2048 | } |
| 2049 | __ Fmov(FPRegister(dst), temp); |
| 2050 | break; |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2051 | } |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 2052 | case DataType::Type::kUint32: |
| 2053 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2054 | case DataType::Type::kVoid: |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2055 | LOG(FATAL) << "Unreachable type " << type; |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2056 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2057 | } |
| 2058 | } |
| 2059 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2060 | void CodeGeneratorARM64::Store(DataType::Type type, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2061 | CPURegister src, |
| 2062 | const MemOperand& dst) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2063 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2064 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2065 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2066 | case DataType::Type::kInt8: |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2067 | __ Strb(Register(src), dst); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2068 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2069 | case DataType::Type::kUint16: |
| 2070 | case DataType::Type::kInt16: |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2071 | __ Strh(Register(src), dst); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2072 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2073 | case DataType::Type::kInt32: |
| 2074 | case DataType::Type::kReference: |
| 2075 | case DataType::Type::kInt64: |
| 2076 | case DataType::Type::kFloat32: |
| 2077 | case DataType::Type::kFloat64: |
| 2078 | DCHECK_EQ(src.Is64Bits(), DataType::Is64BitType(type)); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2079 | __ Str(src, dst); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2080 | break; |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 2081 | case DataType::Type::kUint32: |
| 2082 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2083 | case DataType::Type::kVoid: |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2084 | LOG(FATAL) << "Unreachable type " << type; |
| 2085 | } |
| 2086 | } |
| 2087 | |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2088 | void CodeGeneratorARM64::StoreRelease(HInstruction* instruction, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2089 | DataType::Type type, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2090 | CPURegister src, |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2091 | const MemOperand& dst, |
| 2092 | bool needs_null_check) { |
| 2093 | MacroAssembler* masm = GetVIXLAssembler(); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2094 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2095 | Register temp_base = temps.AcquireX(); |
| 2096 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2097 | DCHECK(!dst.IsPreIndex()); |
| 2098 | DCHECK(!dst.IsPostIndex()); |
| 2099 | |
| 2100 | // TODO(vixl): Let the MacroAssembler handle this. |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 2101 | Operand op = OperandFromMemOperand(dst); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2102 | __ Add(temp_base, dst.GetBaseRegister(), op); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2103 | MemOperand base = MemOperand(temp_base); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2104 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2105 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2106 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2107 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2108 | case DataType::Type::kInt8: |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2109 | { |
| 2110 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 2111 | __ stlrb(Register(src), base); |
| 2112 | if (needs_null_check) { |
| 2113 | MaybeRecordImplicitNullCheck(instruction); |
| 2114 | } |
| 2115 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2116 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2117 | case DataType::Type::kUint16: |
| 2118 | case DataType::Type::kInt16: |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2119 | { |
| 2120 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 2121 | __ stlrh(Register(src), base); |
| 2122 | if (needs_null_check) { |
| 2123 | MaybeRecordImplicitNullCheck(instruction); |
| 2124 | } |
| 2125 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2126 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2127 | case DataType::Type::kInt32: |
| 2128 | case DataType::Type::kReference: |
| 2129 | case DataType::Type::kInt64: |
| 2130 | DCHECK_EQ(src.Is64Bits(), DataType::Is64BitType(type)); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2131 | { |
| 2132 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 2133 | __ stlr(Register(src), base); |
| 2134 | if (needs_null_check) { |
| 2135 | MaybeRecordImplicitNullCheck(instruction); |
| 2136 | } |
| 2137 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2138 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2139 | case DataType::Type::kFloat32: |
| 2140 | case DataType::Type::kFloat64: { |
| 2141 | DCHECK_EQ(src.Is64Bits(), DataType::Is64BitType(type)); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 2142 | Register temp_src; |
| 2143 | if (src.IsZero()) { |
| 2144 | // The zero register is used to avoid synthesizing zero constants. |
| 2145 | temp_src = Register(src); |
| 2146 | } else { |
| 2147 | DCHECK(src.IsFPRegister()); |
| 2148 | temp_src = src.Is64Bits() ? temps.AcquireX() : temps.AcquireW(); |
| 2149 | __ Fmov(temp_src, FPRegister(src)); |
| 2150 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2151 | { |
| 2152 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 2153 | __ stlr(temp_src, base); |
| 2154 | if (needs_null_check) { |
| 2155 | MaybeRecordImplicitNullCheck(instruction); |
| 2156 | } |
| 2157 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2158 | break; |
| 2159 | } |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 2160 | case DataType::Type::kUint32: |
| 2161 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2162 | case DataType::Type::kVoid: |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2163 | LOG(FATAL) << "Unreachable type " << type; |
| 2164 | } |
| 2165 | } |
| 2166 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 2167 | void CodeGeneratorARM64::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 2168 | HInstruction* instruction, |
| 2169 | uint32_t dex_pc, |
| 2170 | SlowPathCode* slow_path) { |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 2171 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2172 | |
| 2173 | __ Ldr(lr, MemOperand(tr, GetThreadOffset<kArm64PointerSize>(entrypoint).Int32Value())); |
| 2174 | { |
| 2175 | // Ensure the pc position is recorded immediately after the `blr` instruction. |
| 2176 | ExactAssemblyScope eas(GetVIXLAssembler(), kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 2177 | __ blr(lr); |
| 2178 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 2179 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 2180 | } |
Serban Constantinescu | da8ffec | 2016-03-09 12:02:11 +0000 | [diff] [blame] | 2181 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2182 | } |
| 2183 | |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 2184 | void CodeGeneratorARM64::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 2185 | HInstruction* instruction, |
| 2186 | SlowPathCode* slow_path) { |
| 2187 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 2188 | __ Ldr(lr, MemOperand(tr, entry_point_offset)); |
| 2189 | __ Blr(lr); |
| 2190 | } |
| 2191 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2192 | void InstructionCodeGeneratorARM64::GenerateClassInitializationCheck(SlowPathCodeARM64* slow_path, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2193 | Register class_reg) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2194 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2195 | Register temp = temps.AcquireW(); |
Vladimir Marko | dc682aa | 2018-01-04 18:42:57 +0000 | [diff] [blame] | 2196 | constexpr size_t status_lsb_position = SubtypeCheckBits::BitStructSizeOf(); |
| 2197 | const size_t status_byte_offset = |
| 2198 | mirror::Class::StatusOffset().SizeValue() + (status_lsb_position / kBitsPerByte); |
| 2199 | constexpr uint32_t shifted_initialized_value = |
| 2200 | enum_cast<uint32_t>(ClassStatus::kInitialized) << (status_lsb_position % kBitsPerByte); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2201 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2202 | // 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] | 2203 | // TODO(vixl): Let the MacroAssembler handle MemOperand. |
Vladimir Marko | dc682aa | 2018-01-04 18:42:57 +0000 | [diff] [blame] | 2204 | __ Add(temp, class_reg, status_byte_offset); |
Igor Murashkin | 86083f7 | 2017-10-27 10:59:04 -0700 | [diff] [blame] | 2205 | __ Ldarb(temp, HeapOperand(temp)); |
Vladimir Marko | dc682aa | 2018-01-04 18:42:57 +0000 | [diff] [blame] | 2206 | __ Cmp(temp, shifted_initialized_value); |
Vladimir Marko | 2c64a83 | 2018-01-04 11:31:56 +0000 | [diff] [blame] | 2207 | __ B(lo, slow_path->GetEntryLabel()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2208 | __ Bind(slow_path->GetExitLabel()); |
| 2209 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2210 | |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 2211 | void InstructionCodeGeneratorARM64::GenerateBitstringTypeCheckCompare( |
| 2212 | HTypeCheckInstruction* check, vixl::aarch64::Register temp) { |
| 2213 | uint32_t path_to_root = check->GetBitstringPathToRoot(); |
| 2214 | uint32_t mask = check->GetBitstringMask(); |
| 2215 | DCHECK(IsPowerOfTwo(mask + 1)); |
| 2216 | size_t mask_bits = WhichPowerOf2(mask + 1); |
| 2217 | |
| 2218 | if (mask_bits == 16u) { |
| 2219 | // Load only the bitstring part of the status word. |
| 2220 | __ Ldrh(temp, HeapOperand(temp, mirror::Class::StatusOffset())); |
| 2221 | } else { |
| 2222 | // /* uint32_t */ temp = temp->status_ |
| 2223 | __ Ldr(temp, HeapOperand(temp, mirror::Class::StatusOffset())); |
| 2224 | // Extract the bitstring bits. |
| 2225 | __ Ubfx(temp, temp, 0, mask_bits); |
| 2226 | } |
| 2227 | // Compare the bitstring bits to `path_to_root`. |
| 2228 | __ Cmp(temp, path_to_root); |
| 2229 | } |
| 2230 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2231 | void CodeGeneratorARM64::GenerateMemoryBarrier(MemBarrierKind kind) { |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2232 | BarrierType type = BarrierAll; |
| 2233 | |
| 2234 | switch (kind) { |
| 2235 | case MemBarrierKind::kAnyAny: |
| 2236 | case MemBarrierKind::kAnyStore: { |
| 2237 | type = BarrierAll; |
| 2238 | break; |
| 2239 | } |
| 2240 | case MemBarrierKind::kLoadAny: { |
| 2241 | type = BarrierReads; |
| 2242 | break; |
| 2243 | } |
| 2244 | case MemBarrierKind::kStoreStore: { |
| 2245 | type = BarrierWrites; |
| 2246 | break; |
| 2247 | } |
| 2248 | default: |
| 2249 | LOG(FATAL) << "Unexpected memory barrier " << kind; |
| 2250 | } |
| 2251 | __ Dmb(InnerShareable, type); |
| 2252 | } |
| 2253 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2254 | void InstructionCodeGeneratorARM64::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 2255 | HBasicBlock* successor) { |
| 2256 | SuspendCheckSlowPathARM64* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 2257 | down_cast<SuspendCheckSlowPathARM64*>(instruction->GetSlowPath()); |
| 2258 | if (slow_path == nullptr) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 2259 | slow_path = |
| 2260 | new (codegen_->GetScopedAllocator()) SuspendCheckSlowPathARM64(instruction, successor); |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 2261 | instruction->SetSlowPath(slow_path); |
| 2262 | codegen_->AddSlowPath(slow_path); |
| 2263 | if (successor != nullptr) { |
| 2264 | DCHECK(successor->IsLoopHeader()); |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 2265 | } |
| 2266 | } else { |
| 2267 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 2268 | } |
| 2269 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2270 | UseScratchRegisterScope temps(codegen_->GetVIXLAssembler()); |
| 2271 | Register temp = temps.AcquireW(); |
| 2272 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 2273 | __ Ldrh(temp, MemOperand(tr, Thread::ThreadFlagsOffset<kArm64PointerSize>().SizeValue())); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2274 | if (successor == nullptr) { |
| 2275 | __ Cbnz(temp, slow_path->GetEntryLabel()); |
| 2276 | __ Bind(slow_path->GetReturnLabel()); |
| 2277 | } else { |
| 2278 | __ Cbz(temp, codegen_->GetLabelOf(successor)); |
| 2279 | __ B(slow_path->GetEntryLabel()); |
| 2280 | // slow_path will return to GetLabelOf(successor). |
| 2281 | } |
| 2282 | } |
| 2283 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2284 | InstructionCodeGeneratorARM64::InstructionCodeGeneratorARM64(HGraph* graph, |
| 2285 | CodeGeneratorARM64* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 2286 | : InstructionCodeGenerator(graph, codegen), |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2287 | assembler_(codegen->GetAssembler()), |
| 2288 | codegen_(codegen) {} |
| 2289 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2290 | void LocationsBuilderARM64::HandleBinaryOp(HBinaryOperation* instr) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2291 | DCHECK_EQ(instr->InputCount(), 2U); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2292 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instr); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2293 | DataType::Type type = instr->GetResultType(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2294 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2295 | case DataType::Type::kInt32: |
| 2296 | case DataType::Type::kInt64: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2297 | locations->SetInAt(0, Location::RequiresRegister()); |
Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 2298 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instr->InputAt(1), instr)); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 2299 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2300 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2301 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2302 | case DataType::Type::kFloat32: |
| 2303 | case DataType::Type::kFloat64: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2304 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2305 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2306 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2307 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2308 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2309 | default: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2310 | LOG(FATAL) << "Unexpected " << instr->DebugName() << " type " << type; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2311 | } |
| 2312 | } |
| 2313 | |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2314 | void LocationsBuilderARM64::HandleFieldGet(HInstruction* instruction, |
| 2315 | const FieldInfo& field_info) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2316 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 2317 | |
| 2318 | bool object_field_get_with_read_barrier = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2319 | kEmitCompilerReadBarrier && (instruction->GetType() == DataType::Type::kReference); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2320 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2321 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, |
| 2322 | object_field_get_with_read_barrier |
| 2323 | ? LocationSummary::kCallOnSlowPath |
| 2324 | : LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 2325 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 2326 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Roland Levillain | d0b5183 | 2017-01-26 19:04:23 +0000 | [diff] [blame] | 2327 | // We need a temporary register for the read barrier marking slow |
| 2328 | // path in CodeGeneratorARM64::GenerateFieldLoadWithBakerReadBarrier. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2329 | if (kBakerReadBarrierLinkTimeThunksEnableForFields && |
| 2330 | !Runtime::Current()->UseJitCompilation() && |
| 2331 | !field_info.IsVolatile()) { |
| 2332 | // If link-time thunks for the Baker read barrier are enabled, for AOT |
| 2333 | // non-volatile loads we need a temporary only if the offset is too big. |
| 2334 | if (field_info.GetFieldOffset().Uint32Value() >= kReferenceLoadMinFarOffset) { |
| 2335 | locations->AddTemp(FixedTempLocation()); |
| 2336 | } |
| 2337 | } else { |
| 2338 | locations->AddTemp(Location::RequiresRegister()); |
| 2339 | } |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 2340 | } |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2341 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2342 | if (DataType::IsFloatingPointType(instruction->GetType())) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2343 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2344 | } else { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2345 | // The output overlaps for an object field get when read barriers |
| 2346 | // are enabled: we do not want the load to overwrite the object's |
| 2347 | // location, as we need it to emit the read barrier. |
| 2348 | locations->SetOut( |
| 2349 | Location::RequiresRegister(), |
| 2350 | object_field_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2351 | } |
| 2352 | } |
| 2353 | |
| 2354 | void InstructionCodeGeneratorARM64::HandleFieldGet(HInstruction* instruction, |
| 2355 | const FieldInfo& field_info) { |
| 2356 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2357 | LocationSummary* locations = instruction->GetLocations(); |
| 2358 | Location base_loc = locations->InAt(0); |
| 2359 | Location out = locations->Out(); |
| 2360 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 2361 | DCHECK_EQ(DataType::Size(field_info.GetFieldType()), DataType::Size(instruction->GetType())); |
| 2362 | DataType::Type load_type = instruction->GetType(); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2363 | MemOperand field = HeapOperand(InputRegisterAt(instruction, 0), field_info.GetFieldOffset()); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2364 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2365 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier && |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 2366 | load_type == DataType::Type::kReference) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2367 | // Object FieldGet with Baker's read barrier case. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2368 | // /* HeapReference<Object> */ out = *(base + offset) |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2369 | Register base = RegisterFrom(base_loc, DataType::Type::kReference); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2370 | Location maybe_temp = |
| 2371 | (locations->GetTempCount() != 0) ? locations->GetTemp(0) : Location::NoLocation(); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2372 | // Note that potential implicit null checks are handled in this |
| 2373 | // CodeGeneratorARM64::GenerateFieldLoadWithBakerReadBarrier call. |
| 2374 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 2375 | instruction, |
| 2376 | out, |
| 2377 | base, |
| 2378 | offset, |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2379 | maybe_temp, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2380 | /* needs_null_check */ true, |
Serban Constantinescu | 4a6a67c | 2016-01-27 09:19:56 +0000 | [diff] [blame] | 2381 | field_info.IsVolatile()); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2382 | } else { |
| 2383 | // General case. |
| 2384 | if (field_info.IsVolatile()) { |
Serban Constantinescu | 4a6a67c | 2016-01-27 09:19:56 +0000 | [diff] [blame] | 2385 | // Note that a potential implicit null check is handled in this |
| 2386 | // CodeGeneratorARM64::LoadAcquire call. |
| 2387 | // NB: LoadAcquire will record the pc info if needed. |
| 2388 | codegen_->LoadAcquire( |
| 2389 | instruction, OutputCPURegister(instruction), field, /* needs_null_check */ true); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2390 | } else { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2391 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2392 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 2393 | codegen_->Load(load_type, OutputCPURegister(instruction), field); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2394 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2395 | } |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 2396 | if (load_type == DataType::Type::kReference) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2397 | // If read barriers are enabled, emit read barriers other than |
| 2398 | // Baker's using a slow path (and also unpoison the loaded |
| 2399 | // reference, if heap poisoning is enabled). |
| 2400 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 2401 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2402 | } |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2403 | } |
| 2404 | |
| 2405 | void LocationsBuilderARM64::HandleFieldSet(HInstruction* instruction) { |
| 2406 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2407 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2408 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 2409 | if (IsConstantZeroBitPattern(instruction->InputAt(1))) { |
| 2410 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2411 | } else if (DataType::IsFloatingPointType(instruction->InputAt(1)->GetType())) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2412 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2413 | } else { |
| 2414 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2415 | } |
| 2416 | } |
| 2417 | |
| 2418 | void InstructionCodeGeneratorARM64::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 2419 | const FieldInfo& field_info, |
| 2420 | bool value_can_be_null) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2421 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 2422 | |
| 2423 | Register obj = InputRegisterAt(instruction, 0); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 2424 | CPURegister value = InputCPURegisterOrZeroRegAt(instruction, 1); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2425 | CPURegister source = value; |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2426 | Offset offset = field_info.GetFieldOffset(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2427 | DataType::Type field_type = field_info.GetFieldType(); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2428 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2429 | { |
| 2430 | // We use a block to end the scratch scope before the write barrier, thus |
| 2431 | // freeing the temporary registers so they can be used in `MarkGCCard`. |
| 2432 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2433 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2434 | if (kPoisonHeapReferences && field_type == DataType::Type::kReference) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2435 | DCHECK(value.IsW()); |
| 2436 | Register temp = temps.AcquireW(); |
| 2437 | __ Mov(temp, value.W()); |
| 2438 | GetAssembler()->PoisonHeapReference(temp.W()); |
| 2439 | source = temp; |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2440 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2441 | |
| 2442 | if (field_info.IsVolatile()) { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2443 | codegen_->StoreRelease( |
| 2444 | instruction, field_type, source, HeapOperand(obj, offset), /* needs_null_check */ true); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2445 | } else { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2446 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2447 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2448 | codegen_->Store(field_type, source, HeapOperand(obj, offset)); |
| 2449 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2450 | } |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2451 | } |
| 2452 | |
| 2453 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 2454 | codegen_->MarkGCCard(obj, Register(value), value_can_be_null); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2455 | } |
| 2456 | } |
| 2457 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2458 | void InstructionCodeGeneratorARM64::HandleBinaryOp(HBinaryOperation* instr) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2459 | DataType::Type type = instr->GetType(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2460 | |
| 2461 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2462 | case DataType::Type::kInt32: |
| 2463 | case DataType::Type::kInt64: { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2464 | Register dst = OutputRegister(instr); |
| 2465 | Register lhs = InputRegisterAt(instr, 0); |
| 2466 | Operand rhs = InputOperandAt(instr, 1); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2467 | if (instr->IsAdd()) { |
| 2468 | __ Add(dst, lhs, rhs); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2469 | } else if (instr->IsAnd()) { |
| 2470 | __ And(dst, lhs, rhs); |
| 2471 | } else if (instr->IsOr()) { |
| 2472 | __ Orr(dst, lhs, rhs); |
| 2473 | } else if (instr->IsSub()) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2474 | __ Sub(dst, lhs, rhs); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 2475 | } else if (instr->IsRor()) { |
| 2476 | if (rhs.IsImmediate()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2477 | uint32_t shift = rhs.GetImmediate() & (lhs.GetSizeInBits() - 1); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 2478 | __ Ror(dst, lhs, shift); |
| 2479 | } else { |
| 2480 | // Ensure shift distance is in the same size register as the result. If |
| 2481 | // we are rotating a long and the shift comes in a w register originally, |
| 2482 | // we don't need to sxtw for use as an x since the shift distances are |
| 2483 | // all & reg_bits - 1. |
| 2484 | __ Ror(dst, lhs, RegisterFrom(instr->GetLocations()->InAt(1), type)); |
| 2485 | } |
Petre-Ionut Tudor | 2227fe4 | 2018-04-20 17:12:05 +0100 | [diff] [blame] | 2486 | } else if (instr->IsMin() || instr->IsMax()) { |
| 2487 | __ Cmp(lhs, rhs); |
| 2488 | __ Csel(dst, lhs, rhs, instr->IsMin() ? lt : gt); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2489 | } else { |
| 2490 | DCHECK(instr->IsXor()); |
| 2491 | __ Eor(dst, lhs, rhs); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2492 | } |
| 2493 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2494 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2495 | case DataType::Type::kFloat32: |
| 2496 | case DataType::Type::kFloat64: { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2497 | FPRegister dst = OutputFPRegister(instr); |
| 2498 | FPRegister lhs = InputFPRegisterAt(instr, 0); |
| 2499 | FPRegister rhs = InputFPRegisterAt(instr, 1); |
| 2500 | if (instr->IsAdd()) { |
| 2501 | __ Fadd(dst, lhs, rhs); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2502 | } else if (instr->IsSub()) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2503 | __ Fsub(dst, lhs, rhs); |
Petre-Ionut Tudor | 2227fe4 | 2018-04-20 17:12:05 +0100 | [diff] [blame] | 2504 | } else if (instr->IsMin()) { |
| 2505 | __ Fmin(dst, lhs, rhs); |
| 2506 | } else if (instr->IsMax()) { |
| 2507 | __ Fmax(dst, lhs, rhs); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2508 | } else { |
| 2509 | LOG(FATAL) << "Unexpected floating-point binary operation"; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2510 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2511 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2512 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2513 | default: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2514 | LOG(FATAL) << "Unexpected binary operation type " << type; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2515 | } |
| 2516 | } |
| 2517 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2518 | void LocationsBuilderARM64::HandleShift(HBinaryOperation* instr) { |
| 2519 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr()); |
| 2520 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2521 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instr); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2522 | DataType::Type type = instr->GetResultType(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2523 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2524 | case DataType::Type::kInt32: |
| 2525 | case DataType::Type::kInt64: { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2526 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2527 | locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1))); |
Artem Serov | 87c9705 | 2016-09-23 13:34:31 +0100 | [diff] [blame] | 2528 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2529 | break; |
| 2530 | } |
| 2531 | default: |
| 2532 | LOG(FATAL) << "Unexpected shift type " << type; |
| 2533 | } |
| 2534 | } |
| 2535 | |
| 2536 | void InstructionCodeGeneratorARM64::HandleShift(HBinaryOperation* instr) { |
| 2537 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr()); |
| 2538 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2539 | DataType::Type type = instr->GetType(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2540 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2541 | case DataType::Type::kInt32: |
| 2542 | case DataType::Type::kInt64: { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2543 | Register dst = OutputRegister(instr); |
| 2544 | Register lhs = InputRegisterAt(instr, 0); |
| 2545 | Operand rhs = InputOperandAt(instr, 1); |
| 2546 | if (rhs.IsImmediate()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2547 | uint32_t shift_value = rhs.GetImmediate() & |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2548 | (type == DataType::Type::kInt32 ? kMaxIntShiftDistance : kMaxLongShiftDistance); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2549 | if (instr->IsShl()) { |
| 2550 | __ Lsl(dst, lhs, shift_value); |
| 2551 | } else if (instr->IsShr()) { |
| 2552 | __ Asr(dst, lhs, shift_value); |
| 2553 | } else { |
| 2554 | __ Lsr(dst, lhs, shift_value); |
| 2555 | } |
| 2556 | } else { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2557 | Register rhs_reg = dst.IsX() ? rhs.GetRegister().X() : rhs.GetRegister().W(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2558 | |
| 2559 | if (instr->IsShl()) { |
| 2560 | __ Lsl(dst, lhs, rhs_reg); |
| 2561 | } else if (instr->IsShr()) { |
| 2562 | __ Asr(dst, lhs, rhs_reg); |
| 2563 | } else { |
| 2564 | __ Lsr(dst, lhs, rhs_reg); |
| 2565 | } |
| 2566 | } |
| 2567 | break; |
| 2568 | } |
| 2569 | default: |
| 2570 | LOG(FATAL) << "Unexpected shift operation type " << type; |
| 2571 | } |
| 2572 | } |
| 2573 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2574 | void LocationsBuilderARM64::VisitAdd(HAdd* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2575 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2576 | } |
| 2577 | |
| 2578 | void InstructionCodeGeneratorARM64::VisitAdd(HAdd* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2579 | HandleBinaryOp(instruction); |
| 2580 | } |
| 2581 | |
| 2582 | void LocationsBuilderARM64::VisitAnd(HAnd* instruction) { |
| 2583 | HandleBinaryOp(instruction); |
| 2584 | } |
| 2585 | |
| 2586 | void InstructionCodeGeneratorARM64::VisitAnd(HAnd* instruction) { |
| 2587 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2588 | } |
| 2589 | |
Artem Serov | 7fc6350 | 2016-02-09 17:15:29 +0000 | [diff] [blame] | 2590 | void LocationsBuilderARM64::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instr) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2591 | DCHECK(DataType::IsIntegralType(instr->GetType())) << instr->GetType(); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2592 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instr); |
Kevin Brodsky | 9ff0d20 | 2016-01-11 13:43:31 +0000 | [diff] [blame] | 2593 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2594 | // There is no immediate variant of negated bitwise instructions in AArch64. |
| 2595 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2596 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2597 | } |
| 2598 | |
Artem Serov | 7fc6350 | 2016-02-09 17:15:29 +0000 | [diff] [blame] | 2599 | void InstructionCodeGeneratorARM64::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instr) { |
Kevin Brodsky | 9ff0d20 | 2016-01-11 13:43:31 +0000 | [diff] [blame] | 2600 | Register dst = OutputRegister(instr); |
| 2601 | Register lhs = InputRegisterAt(instr, 0); |
| 2602 | Register rhs = InputRegisterAt(instr, 1); |
| 2603 | |
| 2604 | switch (instr->GetOpKind()) { |
| 2605 | case HInstruction::kAnd: |
| 2606 | __ Bic(dst, lhs, rhs); |
| 2607 | break; |
| 2608 | case HInstruction::kOr: |
| 2609 | __ Orn(dst, lhs, rhs); |
| 2610 | break; |
| 2611 | case HInstruction::kXor: |
| 2612 | __ Eon(dst, lhs, rhs); |
| 2613 | break; |
| 2614 | default: |
| 2615 | LOG(FATAL) << "Unreachable"; |
| 2616 | } |
| 2617 | } |
| 2618 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2619 | void LocationsBuilderARM64::VisitDataProcWithShifterOp( |
| 2620 | HDataProcWithShifterOp* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2621 | DCHECK(instruction->GetType() == DataType::Type::kInt32 || |
| 2622 | instruction->GetType() == DataType::Type::kInt64); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2623 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2624 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2625 | if (instruction->GetInstrKind() == HInstruction::kNeg) { |
| 2626 | locations->SetInAt(0, Location::ConstantLocation(instruction->InputAt(0)->AsConstant())); |
| 2627 | } else { |
| 2628 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2629 | } |
| 2630 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2631 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2632 | } |
| 2633 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2634 | void InstructionCodeGeneratorARM64::VisitDataProcWithShifterOp( |
| 2635 | HDataProcWithShifterOp* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2636 | DataType::Type type = instruction->GetType(); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2637 | HInstruction::InstructionKind kind = instruction->GetInstrKind(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2638 | DCHECK(type == DataType::Type::kInt32 || type == DataType::Type::kInt64); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2639 | Register out = OutputRegister(instruction); |
| 2640 | Register left; |
| 2641 | if (kind != HInstruction::kNeg) { |
| 2642 | left = InputRegisterAt(instruction, 0); |
| 2643 | } |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2644 | // If this `HDataProcWithShifterOp` was created by merging a type conversion as the |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2645 | // shifter operand operation, the IR generating `right_reg` (input to the type |
| 2646 | // conversion) can have a different type from the current instruction's type, |
| 2647 | // so we manually indicate the type. |
| 2648 | Register right_reg = RegisterFrom(instruction->GetLocations()->InAt(1), type); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2649 | Operand right_operand(0); |
| 2650 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2651 | HDataProcWithShifterOp::OpKind op_kind = instruction->GetOpKind(); |
| 2652 | if (HDataProcWithShifterOp::IsExtensionOp(op_kind)) { |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2653 | right_operand = Operand(right_reg, helpers::ExtendFromOpKind(op_kind)); |
| 2654 | } else { |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2655 | right_operand = Operand(right_reg, |
| 2656 | helpers::ShiftFromOpKind(op_kind), |
| 2657 | instruction->GetShiftAmount()); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2658 | } |
| 2659 | |
| 2660 | // Logical binary operations do not support extension operations in the |
| 2661 | // operand. Note that VIXL would still manage if it was passed by generating |
| 2662 | // the extension as a separate instruction. |
| 2663 | // `HNeg` also does not support extension. See comments in `ShifterOperandSupportsExtension()`. |
| 2664 | DCHECK(!right_operand.IsExtendedRegister() || |
| 2665 | (kind != HInstruction::kAnd && kind != HInstruction::kOr && kind != HInstruction::kXor && |
| 2666 | kind != HInstruction::kNeg)); |
| 2667 | switch (kind) { |
| 2668 | case HInstruction::kAdd: |
| 2669 | __ Add(out, left, right_operand); |
| 2670 | break; |
| 2671 | case HInstruction::kAnd: |
| 2672 | __ And(out, left, right_operand); |
| 2673 | break; |
| 2674 | case HInstruction::kNeg: |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2675 | DCHECK(instruction->InputAt(0)->AsConstant()->IsArithmeticZero()); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2676 | __ Neg(out, right_operand); |
| 2677 | break; |
| 2678 | case HInstruction::kOr: |
| 2679 | __ Orr(out, left, right_operand); |
| 2680 | break; |
| 2681 | case HInstruction::kSub: |
| 2682 | __ Sub(out, left, right_operand); |
| 2683 | break; |
| 2684 | case HInstruction::kXor: |
| 2685 | __ Eor(out, left, right_operand); |
| 2686 | break; |
| 2687 | default: |
| 2688 | LOG(FATAL) << "Unexpected operation kind: " << kind; |
| 2689 | UNREACHABLE(); |
| 2690 | } |
| 2691 | } |
| 2692 | |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2693 | void LocationsBuilderARM64::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2694 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2695 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2696 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2697 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->GetOffset(), instruction)); |
Artem Serov | 87c9705 | 2016-09-23 13:34:31 +0100 | [diff] [blame] | 2698 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2699 | } |
| 2700 | |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 2701 | void InstructionCodeGeneratorARM64::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2702 | __ Add(OutputRegister(instruction), |
| 2703 | InputRegisterAt(instruction, 0), |
| 2704 | Operand(InputOperandAt(instruction, 1))); |
| 2705 | } |
| 2706 | |
Artem Serov | e1811ed | 2017-04-27 16:50:47 +0100 | [diff] [blame] | 2707 | void LocationsBuilderARM64::VisitIntermediateAddressIndex(HIntermediateAddressIndex* instruction) { |
| 2708 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2709 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Artem Serov | e1811ed | 2017-04-27 16:50:47 +0100 | [diff] [blame] | 2710 | |
| 2711 | HIntConstant* shift = instruction->GetShift()->AsIntConstant(); |
| 2712 | |
| 2713 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2714 | // For byte case we don't need to shift the index variable so we can encode the data offset into |
| 2715 | // ADD instruction. For other cases we prefer the data_offset to be in register; that will hoist |
| 2716 | // data offset constant generation out of the loop and reduce the critical path length in the |
| 2717 | // loop. |
| 2718 | locations->SetInAt(1, shift->GetValue() == 0 |
| 2719 | ? Location::ConstantLocation(instruction->GetOffset()->AsIntConstant()) |
| 2720 | : Location::RequiresRegister()); |
| 2721 | locations->SetInAt(2, Location::ConstantLocation(shift)); |
| 2722 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2723 | } |
| 2724 | |
| 2725 | void InstructionCodeGeneratorARM64::VisitIntermediateAddressIndex( |
| 2726 | HIntermediateAddressIndex* instruction) { |
| 2727 | Register index_reg = InputRegisterAt(instruction, 0); |
Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 2728 | uint32_t shift = Int64FromLocation(instruction->GetLocations()->InAt(2)); |
Artem Serov | e1811ed | 2017-04-27 16:50:47 +0100 | [diff] [blame] | 2729 | uint32_t offset = instruction->GetOffset()->AsIntConstant()->GetValue(); |
| 2730 | |
| 2731 | if (shift == 0) { |
| 2732 | __ Add(OutputRegister(instruction), index_reg, offset); |
| 2733 | } else { |
| 2734 | Register offset_reg = InputRegisterAt(instruction, 1); |
| 2735 | __ Add(OutputRegister(instruction), offset_reg, Operand(index_reg, LSL, shift)); |
| 2736 | } |
| 2737 | } |
| 2738 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2739 | void LocationsBuilderARM64::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2740 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2741 | new (GetGraph()->GetAllocator()) LocationSummary(instr, LocationSummary::kNoCall); |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2742 | HInstruction* accumulator = instr->InputAt(HMultiplyAccumulate::kInputAccumulatorIndex); |
| 2743 | if (instr->GetOpKind() == HInstruction::kSub && |
| 2744 | accumulator->IsConstant() && |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2745 | accumulator->AsConstant()->IsArithmeticZero()) { |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2746 | // Don't allocate register for Mneg instruction. |
| 2747 | } else { |
| 2748 | locations->SetInAt(HMultiplyAccumulate::kInputAccumulatorIndex, |
| 2749 | Location::RequiresRegister()); |
| 2750 | } |
| 2751 | locations->SetInAt(HMultiplyAccumulate::kInputMulLeftIndex, Location::RequiresRegister()); |
| 2752 | locations->SetInAt(HMultiplyAccumulate::kInputMulRightIndex, Location::RequiresRegister()); |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2753 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2754 | } |
| 2755 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2756 | void InstructionCodeGeneratorARM64::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2757 | Register res = OutputRegister(instr); |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2758 | Register mul_left = InputRegisterAt(instr, HMultiplyAccumulate::kInputMulLeftIndex); |
| 2759 | Register mul_right = InputRegisterAt(instr, HMultiplyAccumulate::kInputMulRightIndex); |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2760 | |
| 2761 | // Avoid emitting code that could trigger Cortex A53's erratum 835769. |
| 2762 | // This fixup should be carried out for all multiply-accumulate instructions: |
| 2763 | // madd, msub, smaddl, smsubl, umaddl and umsubl. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2764 | if (instr->GetType() == DataType::Type::kInt64 && |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2765 | codegen_->GetInstructionSetFeatures().NeedFixCortexA53_835769()) { |
| 2766 | MacroAssembler* masm = down_cast<CodeGeneratorARM64*>(codegen_)->GetVIXLAssembler(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2767 | vixl::aarch64::Instruction* prev = |
| 2768 | masm->GetCursorAddress<vixl::aarch64::Instruction*>() - kInstructionSize; |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2769 | if (prev->IsLoadOrStore()) { |
| 2770 | // Make sure we emit only exactly one nop. |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2771 | ExactAssemblyScope scope(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2772 | __ nop(); |
| 2773 | } |
| 2774 | } |
| 2775 | |
| 2776 | if (instr->GetOpKind() == HInstruction::kAdd) { |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2777 | Register accumulator = InputRegisterAt(instr, HMultiplyAccumulate::kInputAccumulatorIndex); |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2778 | __ Madd(res, mul_left, mul_right, accumulator); |
| 2779 | } else { |
| 2780 | DCHECK(instr->GetOpKind() == HInstruction::kSub); |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2781 | HInstruction* accum_instr = instr->InputAt(HMultiplyAccumulate::kInputAccumulatorIndex); |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2782 | if (accum_instr->IsConstant() && accum_instr->AsConstant()->IsArithmeticZero()) { |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2783 | __ Mneg(res, mul_left, mul_right); |
| 2784 | } else { |
| 2785 | Register accumulator = InputRegisterAt(instr, HMultiplyAccumulate::kInputAccumulatorIndex); |
| 2786 | __ Msub(res, mul_left, mul_right, accumulator); |
| 2787 | } |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2788 | } |
| 2789 | } |
| 2790 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2791 | void LocationsBuilderARM64::VisitArrayGet(HArrayGet* instruction) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2792 | bool object_array_get_with_read_barrier = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2793 | kEmitCompilerReadBarrier && (instruction->GetType() == DataType::Type::kReference); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2794 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2795 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, |
| 2796 | object_array_get_with_read_barrier |
| 2797 | ? LocationSummary::kCallOnSlowPath |
| 2798 | : LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 2799 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 2800 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 2801 | // We need a temporary register for the read barrier marking slow |
| 2802 | // path in CodeGeneratorARM64::GenerateArrayLoadWithBakerReadBarrier. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2803 | if (kBakerReadBarrierLinkTimeThunksEnableForFields && |
| 2804 | !Runtime::Current()->UseJitCompilation() && |
| 2805 | instruction->GetIndex()->IsConstant()) { |
| 2806 | // Array loads with constant index are treated as field loads. |
| 2807 | // If link-time thunks for the Baker read barrier are enabled, for AOT |
| 2808 | // constant index loads we need a temporary only if the offset is too big. |
| 2809 | uint32_t offset = CodeGenerator::GetArrayDataOffset(instruction); |
| 2810 | uint32_t index = instruction->GetIndex()->AsIntConstant()->GetValue(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2811 | offset += index << DataType::SizeShift(DataType::Type::kReference); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2812 | if (offset >= kReferenceLoadMinFarOffset) { |
| 2813 | locations->AddTemp(FixedTempLocation()); |
| 2814 | } |
| 2815 | } else { |
| 2816 | locations->AddTemp(Location::RequiresRegister()); |
| 2817 | } |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 2818 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2819 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2820 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2821 | if (DataType::IsFloatingPointType(instruction->GetType())) { |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 2822 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 2823 | } else { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2824 | // The output overlaps in the case of an object array get with |
| 2825 | // read barriers enabled: we do not want the move to overwrite the |
| 2826 | // array's location, as we need it to emit the read barrier. |
| 2827 | locations->SetOut( |
| 2828 | Location::RequiresRegister(), |
| 2829 | object_array_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 2830 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2831 | } |
| 2832 | |
| 2833 | void InstructionCodeGeneratorARM64::VisitArrayGet(HArrayGet* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2834 | DataType::Type type = instruction->GetType(); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2835 | Register obj = InputRegisterAt(instruction, 0); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2836 | LocationSummary* locations = instruction->GetLocations(); |
| 2837 | Location index = locations->InAt(1); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2838 | Location out = locations->Out(); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 2839 | uint32_t offset = CodeGenerator::GetArrayDataOffset(instruction); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2840 | const bool maybe_compressed_char_at = mirror::kUseStringCompression && |
| 2841 | instruction->IsStringCharAt(); |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 2842 | MacroAssembler* masm = GetVIXLAssembler(); |
| 2843 | UseScratchRegisterScope temps(masm); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2844 | |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 2845 | // The read barrier instrumentation of object ArrayGet instructions |
| 2846 | // does not support the HIntermediateAddress instruction. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2847 | DCHECK(!((type == DataType::Type::kReference) && |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 2848 | instruction->GetArray()->IsIntermediateAddress() && |
| 2849 | kEmitCompilerReadBarrier)); |
| 2850 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2851 | if (type == DataType::Type::kReference && kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2852 | // Object ArrayGet with Baker's read barrier case. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2853 | // Note that a potential implicit null check is handled in the |
| 2854 | // CodeGeneratorARM64::GenerateArrayLoadWithBakerReadBarrier call. |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 2855 | DCHECK(!instruction->CanDoImplicitNullCheckOn(instruction->InputAt(0))); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2856 | if (index.IsConstant()) { |
| 2857 | // Array load with a constant index can be treated as a field load. |
Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 2858 | offset += Int64FromLocation(index) << DataType::SizeShift(type); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2859 | Location maybe_temp = |
| 2860 | (locations->GetTempCount() != 0) ? locations->GetTemp(0) : Location::NoLocation(); |
| 2861 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 2862 | out, |
| 2863 | obj.W(), |
| 2864 | offset, |
| 2865 | maybe_temp, |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 2866 | /* needs_null_check */ false, |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2867 | /* use_load_acquire */ false); |
| 2868 | } else { |
| 2869 | Register temp = WRegisterFrom(locations->GetTemp(0)); |
| 2870 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 2871 | instruction, out, obj.W(), offset, index, temp, /* needs_null_check */ false); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2872 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2873 | } else { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2874 | // General case. |
| 2875 | MemOperand source = HeapOperand(obj); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2876 | Register length; |
| 2877 | if (maybe_compressed_char_at) { |
| 2878 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| 2879 | length = temps.AcquireW(); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2880 | { |
| 2881 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2882 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 2883 | |
| 2884 | if (instruction->GetArray()->IsIntermediateAddress()) { |
| 2885 | DCHECK_LT(count_offset, offset); |
| 2886 | int64_t adjusted_offset = |
| 2887 | static_cast<int64_t>(count_offset) - static_cast<int64_t>(offset); |
| 2888 | // Note that `adjusted_offset` is negative, so this will be a LDUR. |
| 2889 | __ Ldr(length, MemOperand(obj.X(), adjusted_offset)); |
| 2890 | } else { |
| 2891 | __ Ldr(length, HeapOperand(obj, count_offset)); |
| 2892 | } |
| 2893 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 2894 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2895 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2896 | if (index.IsConstant()) { |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2897 | if (maybe_compressed_char_at) { |
| 2898 | vixl::aarch64::Label uncompressed_load, done; |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 2899 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 2900 | "Expecting 0=compressed, 1=uncompressed"); |
| 2901 | __ Tbnz(length.W(), 0, &uncompressed_load); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2902 | __ Ldrb(Register(OutputCPURegister(instruction)), |
Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 2903 | HeapOperand(obj, offset + Int64FromLocation(index))); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2904 | __ B(&done); |
| 2905 | __ Bind(&uncompressed_load); |
| 2906 | __ Ldrh(Register(OutputCPURegister(instruction)), |
Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 2907 | HeapOperand(obj, offset + (Int64FromLocation(index) << 1))); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2908 | __ Bind(&done); |
| 2909 | } else { |
Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 2910 | offset += Int64FromLocation(index) << DataType::SizeShift(type); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2911 | source = HeapOperand(obj, offset); |
| 2912 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2913 | } else { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2914 | Register temp = temps.AcquireSameSizeAs(obj); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2915 | if (instruction->GetArray()->IsIntermediateAddress()) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2916 | // We do not need to compute the intermediate address from the array: the |
| 2917 | // input instruction has done it already. See the comment in |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2918 | // `TryExtractArrayAccessAddress()`. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2919 | if (kIsDebugBuild) { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2920 | HIntermediateAddress* tmp = instruction->GetArray()->AsIntermediateAddress(); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2921 | DCHECK_EQ(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64(), offset); |
| 2922 | } |
| 2923 | temp = obj; |
| 2924 | } else { |
| 2925 | __ Add(temp, obj, offset); |
| 2926 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2927 | if (maybe_compressed_char_at) { |
| 2928 | vixl::aarch64::Label uncompressed_load, done; |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 2929 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 2930 | "Expecting 0=compressed, 1=uncompressed"); |
| 2931 | __ Tbnz(length.W(), 0, &uncompressed_load); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2932 | __ Ldrb(Register(OutputCPURegister(instruction)), |
| 2933 | HeapOperand(temp, XRegisterFrom(index), LSL, 0)); |
| 2934 | __ B(&done); |
| 2935 | __ Bind(&uncompressed_load); |
| 2936 | __ Ldrh(Register(OutputCPURegister(instruction)), |
| 2937 | HeapOperand(temp, XRegisterFrom(index), LSL, 1)); |
| 2938 | __ Bind(&done); |
| 2939 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2940 | source = HeapOperand(temp, XRegisterFrom(index), LSL, DataType::SizeShift(type)); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2941 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2942 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2943 | if (!maybe_compressed_char_at) { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2944 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2945 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2946 | codegen_->Load(type, OutputCPURegister(instruction), source); |
| 2947 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2948 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2949 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2950 | if (type == DataType::Type::kReference) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2951 | static_assert( |
| 2952 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 2953 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 2954 | Location obj_loc = locations->InAt(0); |
| 2955 | if (index.IsConstant()) { |
| 2956 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, obj_loc, offset); |
| 2957 | } else { |
| 2958 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, obj_loc, offset, index); |
| 2959 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2960 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2961 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2962 | } |
| 2963 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2964 | void LocationsBuilderARM64::VisitArrayLength(HArrayLength* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2965 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2966 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 2967 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2968 | } |
| 2969 | |
| 2970 | void InstructionCodeGeneratorARM64::VisitArrayLength(HArrayLength* instruction) { |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 2971 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2972 | vixl::aarch64::Register out = OutputRegister(instruction); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2973 | { |
| 2974 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2975 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 2976 | __ Ldr(out, HeapOperand(InputRegisterAt(instruction, 0), offset)); |
| 2977 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2978 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2979 | // Mask out compression flag from String's array length. |
| 2980 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 2981 | __ Lsr(out.W(), out.W(), 1u); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2982 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2983 | } |
| 2984 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2985 | void LocationsBuilderARM64::VisitArraySet(HArraySet* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2986 | DataType::Type value_type = instruction->GetComponentType(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2987 | |
| 2988 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2989 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2990 | instruction, |
Vladimir Marko | 8d49fd7 | 2016-08-25 15:20:47 +0100 | [diff] [blame] | 2991 | may_need_runtime_call_for_type_check ? |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2992 | LocationSummary::kCallOnSlowPath : |
| 2993 | LocationSummary::kNoCall); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2994 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2995 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 2996 | if (IsConstantZeroBitPattern(instruction->InputAt(2))) { |
| 2997 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2998 | } else if (DataType::IsFloatingPointType(value_type)) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2999 | locations->SetInAt(2, Location::RequiresFpuRegister()); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3000 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3001 | locations->SetInAt(2, Location::RequiresRegister()); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3002 | } |
| 3003 | } |
| 3004 | |
| 3005 | void InstructionCodeGeneratorARM64::VisitArraySet(HArraySet* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3006 | DataType::Type value_type = instruction->GetComponentType(); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 3007 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3008 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3009 | bool needs_write_barrier = |
| 3010 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 3011 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3012 | Register array = InputRegisterAt(instruction, 0); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 3013 | CPURegister value = InputCPURegisterOrZeroRegAt(instruction, 2); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3014 | CPURegister source = value; |
| 3015 | Location index = locations->InAt(1); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3016 | size_t offset = mirror::Array::DataOffset(DataType::Size(value_type)).Uint32Value(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3017 | MemOperand destination = HeapOperand(array); |
| 3018 | MacroAssembler* masm = GetVIXLAssembler(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3019 | |
| 3020 | if (!needs_write_barrier) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3021 | DCHECK(!may_need_runtime_call_for_type_check); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3022 | if (index.IsConstant()) { |
Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 3023 | offset += Int64FromLocation(index) << DataType::SizeShift(value_type); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3024 | destination = HeapOperand(array, offset); |
| 3025 | } else { |
| 3026 | UseScratchRegisterScope temps(masm); |
| 3027 | Register temp = temps.AcquireSameSizeAs(array); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 3028 | if (instruction->GetArray()->IsIntermediateAddress()) { |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 3029 | // We do not need to compute the intermediate address from the array: the |
| 3030 | // input instruction has done it already. See the comment in |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 3031 | // `TryExtractArrayAccessAddress()`. |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 3032 | if (kIsDebugBuild) { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 3033 | HIntermediateAddress* tmp = instruction->GetArray()->AsIntermediateAddress(); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 3034 | DCHECK(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64() == offset); |
| 3035 | } |
| 3036 | temp = array; |
| 3037 | } else { |
| 3038 | __ Add(temp, array, offset); |
| 3039 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3040 | destination = HeapOperand(temp, |
| 3041 | XRegisterFrom(index), |
| 3042 | LSL, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3043 | DataType::SizeShift(value_type)); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3044 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 3045 | { |
| 3046 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 3047 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 3048 | codegen_->Store(value_type, value, destination); |
| 3049 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 3050 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3051 | } else { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 3052 | DCHECK(!instruction->GetArray()->IsIntermediateAddress()); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3053 | vixl::aarch64::Label done; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3054 | SlowPathCodeARM64* slow_path = nullptr; |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 3055 | { |
| 3056 | // We use a block to end the scratch scope before the write barrier, thus |
| 3057 | // freeing the temporary registers so they can be used in `MarkGCCard`. |
| 3058 | UseScratchRegisterScope temps(masm); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3059 | Register temp = temps.AcquireSameSizeAs(array); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 3060 | if (index.IsConstant()) { |
Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 3061 | offset += Int64FromLocation(index) << DataType::SizeShift(value_type); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3062 | destination = HeapOperand(array, offset); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 3063 | } else { |
Alexandre Rames | 82000b0 | 2015-07-07 11:34:16 +0100 | [diff] [blame] | 3064 | destination = HeapOperand(temp, |
| 3065 | XRegisterFrom(index), |
| 3066 | LSL, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3067 | DataType::SizeShift(value_type)); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 3068 | } |
| 3069 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3070 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 3071 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 3072 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 3073 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3074 | if (may_need_runtime_call_for_type_check) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 3075 | slow_path = new (codegen_->GetScopedAllocator()) ArraySetSlowPathARM64(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3076 | codegen_->AddSlowPath(slow_path); |
| 3077 | if (instruction->GetValueCanBeNull()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3078 | vixl::aarch64::Label non_zero; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3079 | __ Cbnz(Register(value), &non_zero); |
| 3080 | if (!index.IsConstant()) { |
| 3081 | __ Add(temp, array, offset); |
| 3082 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 3083 | { |
| 3084 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools |
| 3085 | // emitted. |
| 3086 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 3087 | __ Str(wzr, destination); |
| 3088 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 3089 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3090 | __ B(&done); |
| 3091 | __ Bind(&non_zero); |
| 3092 | } |
| 3093 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 3094 | // Note that when Baker read barriers are enabled, the type |
| 3095 | // checks are performed without read barriers. This is fine, |
| 3096 | // even in the case where a class object is in the from-space |
| 3097 | // after the flip, as a comparison involving such a type would |
| 3098 | // not produce a false positive; it may of course produce a |
| 3099 | // false negative, in which case we would take the ArraySet |
| 3100 | // slow path. |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 3101 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 3102 | Register temp2 = temps.AcquireSameSizeAs(array); |
| 3103 | // /* HeapReference<Class> */ temp = array->klass_ |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 3104 | { |
| 3105 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 3106 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 3107 | __ Ldr(temp, HeapOperand(array, class_offset)); |
| 3108 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 3109 | } |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 3110 | GetAssembler()->MaybeUnpoisonHeapReference(temp); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 3111 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 3112 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| 3113 | __ Ldr(temp, HeapOperand(temp, component_offset)); |
| 3114 | // /* HeapReference<Class> */ temp2 = value->klass_ |
| 3115 | __ Ldr(temp2, HeapOperand(Register(value), class_offset)); |
| 3116 | // If heap poisoning is enabled, no need to unpoison `temp` |
| 3117 | // nor `temp2`, as we are comparing two poisoned references. |
| 3118 | __ Cmp(temp, temp2); |
| 3119 | temps.Release(temp2); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 3120 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 3121 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 3122 | vixl::aarch64::Label do_put; |
| 3123 | __ B(eq, &do_put); |
| 3124 | // If heap poisoning is enabled, the `temp` reference has |
| 3125 | // not been unpoisoned yet; unpoison it now. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3126 | GetAssembler()->MaybeUnpoisonHeapReference(temp); |
| 3127 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 3128 | // /* HeapReference<Class> */ temp = temp->super_class_ |
| 3129 | __ Ldr(temp, HeapOperand(temp, super_offset)); |
| 3130 | // If heap poisoning is enabled, no need to unpoison |
| 3131 | // `temp`, as we are comparing against null below. |
| 3132 | __ Cbnz(temp, slow_path->GetEntryLabel()); |
| 3133 | __ Bind(&do_put); |
| 3134 | } else { |
| 3135 | __ B(ne, slow_path->GetEntryLabel()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3136 | } |
| 3137 | } |
| 3138 | |
| 3139 | if (kPoisonHeapReferences) { |
Nicolas Geoffray | a8a0fe2 | 2015-10-01 15:50:27 +0100 | [diff] [blame] | 3140 | Register temp2 = temps.AcquireSameSizeAs(array); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3141 | DCHECK(value.IsW()); |
Nicolas Geoffray | a8a0fe2 | 2015-10-01 15:50:27 +0100 | [diff] [blame] | 3142 | __ Mov(temp2, value.W()); |
| 3143 | GetAssembler()->PoisonHeapReference(temp2); |
| 3144 | source = temp2; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3145 | } |
| 3146 | |
| 3147 | if (!index.IsConstant()) { |
| 3148 | __ Add(temp, array, offset); |
Vladimir Marko | d1ef873 | 2017-04-18 13:55:13 +0100 | [diff] [blame] | 3149 | } else { |
| 3150 | // We no longer need the `temp` here so release it as the store below may |
| 3151 | // need a scratch register (if the constant index makes the offset too large) |
| 3152 | // and the poisoned `source` could be using the other scratch register. |
| 3153 | temps.Release(temp); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3154 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 3155 | { |
| 3156 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 3157 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 3158 | __ Str(source, destination); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3159 | |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 3160 | if (!may_need_runtime_call_for_type_check) { |
| 3161 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 3162 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3163 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3164 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3165 | |
| 3166 | codegen_->MarkGCCard(array, value.W(), instruction->GetValueCanBeNull()); |
| 3167 | |
| 3168 | if (done.IsLinked()) { |
| 3169 | __ Bind(&done); |
| 3170 | } |
| 3171 | |
| 3172 | if (slow_path != nullptr) { |
| 3173 | __ Bind(slow_path->GetExitLabel()); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 3174 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3175 | } |
| 3176 | } |
| 3177 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3178 | void LocationsBuilderARM64::VisitBoundsCheck(HBoundsCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3179 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 3180 | InvokeRuntimeCallingConvention calling_convention; |
| 3181 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0).GetCode())); |
| 3182 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1).GetCode())); |
| 3183 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3184 | locations->SetInAt(0, Location::RequiresRegister()); |
Serban Constantinescu | 760d8ef | 2015-03-28 18:09:56 +0000 | [diff] [blame] | 3185 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->InputAt(1), instruction)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3186 | } |
| 3187 | |
| 3188 | void InstructionCodeGeneratorARM64::VisitBoundsCheck(HBoundsCheck* instruction) { |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 3189 | BoundsCheckSlowPathARM64* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 3190 | new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathARM64(instruction); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3191 | codegen_->AddSlowPath(slow_path); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3192 | __ Cmp(InputRegisterAt(instruction, 0), InputOperandAt(instruction, 1)); |
| 3193 | __ B(slow_path->GetEntryLabel(), hs); |
| 3194 | } |
| 3195 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3196 | void LocationsBuilderARM64::VisitClinitCheck(HClinitCheck* check) { |
| 3197 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3198 | new (GetGraph()->GetAllocator()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3199 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3200 | if (check->HasUses()) { |
| 3201 | locations->SetOut(Location::SameAsFirstInput()); |
| 3202 | } |
Vladimir Marko | 3232dbb | 2018-07-25 15:42:46 +0100 | [diff] [blame] | 3203 | // Rely on the type initialization to save everything we need. |
| 3204 | locations->SetCustomSlowPathCallerSaves(OneRegInReferenceOutSaveEverythingCallerSaves()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3205 | } |
| 3206 | |
| 3207 | void InstructionCodeGeneratorARM64::VisitClinitCheck(HClinitCheck* check) { |
| 3208 | // We assume the class is not null. |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 3209 | SlowPathCodeARM64* slow_path = |
| 3210 | new (codegen_->GetScopedAllocator()) LoadClassSlowPathARM64(check->GetLoadClass(), check); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3211 | codegen_->AddSlowPath(slow_path); |
| 3212 | GenerateClassInitializationCheck(slow_path, InputRegisterAt(check, 0)); |
| 3213 | } |
| 3214 | |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3215 | static bool IsFloatingPointZeroConstant(HInstruction* inst) { |
| 3216 | return (inst->IsFloatConstant() && (inst->AsFloatConstant()->IsArithmeticZero())) |
| 3217 | || (inst->IsDoubleConstant() && (inst->AsDoubleConstant()->IsArithmeticZero())); |
| 3218 | } |
| 3219 | |
| 3220 | void InstructionCodeGeneratorARM64::GenerateFcmp(HInstruction* instruction) { |
| 3221 | FPRegister lhs_reg = InputFPRegisterAt(instruction, 0); |
| 3222 | Location rhs_loc = instruction->GetLocations()->InAt(1); |
| 3223 | if (rhs_loc.IsConstant()) { |
| 3224 | // 0.0 is the only immediate that can be encoded directly in |
| 3225 | // an FCMP instruction. |
| 3226 | // |
| 3227 | // Both the JLS (section 15.20.1) and the JVMS (section 6.5) |
| 3228 | // specify that in a floating-point comparison, positive zero |
| 3229 | // and negative zero are considered equal, so we can use the |
| 3230 | // literal 0.0 for both cases here. |
| 3231 | // |
| 3232 | // Note however that some methods (Float.equal, Float.compare, |
| 3233 | // Float.compareTo, Double.equal, Double.compare, |
| 3234 | // Double.compareTo, Math.max, Math.min, StrictMath.max, |
| 3235 | // StrictMath.min) consider 0.0 to be (strictly) greater than |
| 3236 | // -0.0. So if we ever translate calls to these methods into a |
| 3237 | // HCompare instruction, we must handle the -0.0 case with |
| 3238 | // care here. |
| 3239 | DCHECK(IsFloatingPointZeroConstant(rhs_loc.GetConstant())); |
| 3240 | __ Fcmp(lhs_reg, 0.0); |
| 3241 | } else { |
| 3242 | __ Fcmp(lhs_reg, InputFPRegisterAt(instruction, 1)); |
| 3243 | } |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3244 | } |
| 3245 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3246 | void LocationsBuilderARM64::VisitCompare(HCompare* compare) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3247 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3248 | new (GetGraph()->GetAllocator()) LocationSummary(compare, LocationSummary::kNoCall); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3249 | DataType::Type in_type = compare->InputAt(0)->GetType(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3250 | switch (in_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3251 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3252 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3253 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3254 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3255 | case DataType::Type::kInt16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3256 | case DataType::Type::kInt32: |
| 3257 | case DataType::Type::kInt64: { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3258 | locations->SetInAt(0, Location::RequiresRegister()); |
Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 3259 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(compare->InputAt(1), compare)); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3260 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3261 | break; |
| 3262 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3263 | case DataType::Type::kFloat32: |
| 3264 | case DataType::Type::kFloat64: { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3265 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3266 | locations->SetInAt(1, |
| 3267 | IsFloatingPointZeroConstant(compare->InputAt(1)) |
| 3268 | ? Location::ConstantLocation(compare->InputAt(1)->AsConstant()) |
| 3269 | : Location::RequiresFpuRegister()); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3270 | locations->SetOut(Location::RequiresRegister()); |
| 3271 | break; |
| 3272 | } |
| 3273 | default: |
| 3274 | LOG(FATAL) << "Unexpected type for compare operation " << in_type; |
| 3275 | } |
| 3276 | } |
| 3277 | |
| 3278 | void InstructionCodeGeneratorARM64::VisitCompare(HCompare* compare) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3279 | DataType::Type in_type = compare->InputAt(0)->GetType(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3280 | |
| 3281 | // 0 if: left == right |
| 3282 | // 1 if: left > right |
| 3283 | // -1 if: left < right |
| 3284 | switch (in_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3285 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3286 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3287 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3288 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3289 | case DataType::Type::kInt16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3290 | case DataType::Type::kInt32: |
| 3291 | case DataType::Type::kInt64: { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3292 | Register result = OutputRegister(compare); |
| 3293 | Register left = InputRegisterAt(compare, 0); |
| 3294 | Operand right = InputOperandAt(compare, 1); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3295 | __ Cmp(left, right); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 3296 | __ Cset(result, ne); // result == +1 if NE or 0 otherwise |
| 3297 | __ Cneg(result, result, lt); // result == -1 if LT or unchanged otherwise |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3298 | break; |
| 3299 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3300 | case DataType::Type::kFloat32: |
| 3301 | case DataType::Type::kFloat64: { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3302 | Register result = OutputRegister(compare); |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3303 | GenerateFcmp(compare); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3304 | __ Cset(result, ne); |
| 3305 | __ Cneg(result, result, ARM64FPCondition(kCondLT, compare->IsGtBias())); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3306 | break; |
| 3307 | } |
| 3308 | default: |
| 3309 | LOG(FATAL) << "Unimplemented compare type " << in_type; |
| 3310 | } |
| 3311 | } |
| 3312 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3313 | void LocationsBuilderARM64::HandleCondition(HCondition* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3314 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3315 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3316 | if (DataType::IsFloatingPointType(instruction->InputAt(0)->GetType())) { |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3317 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3318 | locations->SetInAt(1, |
| 3319 | IsFloatingPointZeroConstant(instruction->InputAt(1)) |
| 3320 | ? Location::ConstantLocation(instruction->InputAt(1)->AsConstant()) |
| 3321 | : Location::RequiresFpuRegister()); |
| 3322 | } else { |
| 3323 | // Integer cases. |
| 3324 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3325 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->InputAt(1), instruction)); |
| 3326 | } |
| 3327 | |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3328 | if (!instruction->IsEmittedAtUseSite()) { |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 3329 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3330 | } |
| 3331 | } |
| 3332 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3333 | void InstructionCodeGeneratorARM64::HandleCondition(HCondition* instruction) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3334 | if (instruction->IsEmittedAtUseSite()) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3335 | return; |
| 3336 | } |
| 3337 | |
| 3338 | LocationSummary* locations = instruction->GetLocations(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3339 | Register res = RegisterFrom(locations->Out(), instruction->GetType()); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3340 | IfCondition if_cond = instruction->GetCondition(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3341 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3342 | if (DataType::IsFloatingPointType(instruction->InputAt(0)->GetType())) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3343 | GenerateFcmp(instruction); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3344 | __ Cset(res, ARM64FPCondition(if_cond, instruction->IsGtBias())); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3345 | } else { |
| 3346 | // Integer cases. |
| 3347 | Register lhs = InputRegisterAt(instruction, 0); |
| 3348 | Operand rhs = InputOperandAt(instruction, 1); |
| 3349 | __ Cmp(lhs, rhs); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3350 | __ Cset(res, ARM64Condition(if_cond)); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3351 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3352 | } |
| 3353 | |
| 3354 | #define FOR_EACH_CONDITION_INSTRUCTION(M) \ |
| 3355 | M(Equal) \ |
| 3356 | M(NotEqual) \ |
| 3357 | M(LessThan) \ |
| 3358 | M(LessThanOrEqual) \ |
| 3359 | M(GreaterThan) \ |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3360 | M(GreaterThanOrEqual) \ |
| 3361 | M(Below) \ |
| 3362 | M(BelowOrEqual) \ |
| 3363 | M(Above) \ |
| 3364 | M(AboveOrEqual) |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3365 | #define DEFINE_CONDITION_VISITORS(Name) \ |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3366 | void LocationsBuilderARM64::Visit##Name(H##Name* comp) { HandleCondition(comp); } \ |
| 3367 | void InstructionCodeGeneratorARM64::Visit##Name(H##Name* comp) { HandleCondition(comp); } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3368 | FOR_EACH_CONDITION_INSTRUCTION(DEFINE_CONDITION_VISITORS) |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3369 | #undef DEFINE_CONDITION_VISITORS |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3370 | #undef FOR_EACH_CONDITION_INSTRUCTION |
| 3371 | |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 3372 | void InstructionCodeGeneratorARM64::GenerateIntDivForPower2Denom(HDiv* instruction) { |
Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 3373 | int64_t imm = Int64FromLocation(instruction->GetLocations()->InAt(1)); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3374 | uint64_t abs_imm = static_cast<uint64_t>(AbsOrMin(imm)); |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 3375 | DCHECK(IsPowerOfTwo(abs_imm)) << abs_imm; |
| 3376 | |
| 3377 | Register out = OutputRegister(instruction); |
| 3378 | Register dividend = InputRegisterAt(instruction, 0); |
Evgeny Astigeevich | a3234e9 | 2018-06-19 23:26:15 +0100 | [diff] [blame] | 3379 | |
| 3380 | if (abs_imm == 2) { |
| 3381 | int bits = DataType::Size(instruction->GetResultType()) * kBitsPerByte; |
| 3382 | __ Add(out, dividend, Operand(dividend, LSR, bits - 1)); |
| 3383 | } else { |
| 3384 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 3385 | Register temp = temps.AcquireSameSizeAs(out); |
| 3386 | __ Add(temp, dividend, abs_imm - 1); |
| 3387 | __ Cmp(dividend, 0); |
| 3388 | __ Csel(out, temp, dividend, lt); |
| 3389 | } |
| 3390 | |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3391 | int ctz_imm = CTZ(abs_imm); |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 3392 | if (imm > 0) { |
| 3393 | __ Asr(out, out, ctz_imm); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3394 | } else { |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 3395 | __ Neg(out, Operand(out, ASR, ctz_imm)); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3396 | } |
| 3397 | } |
| 3398 | |
| 3399 | void InstructionCodeGeneratorARM64::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 3400 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3401 | |
| 3402 | LocationSummary* locations = instruction->GetLocations(); |
| 3403 | Location second = locations->InAt(1); |
| 3404 | DCHECK(second.IsConstant()); |
| 3405 | |
| 3406 | Register out = OutputRegister(instruction); |
| 3407 | Register dividend = InputRegisterAt(instruction, 0); |
| 3408 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 3409 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3410 | DataType::Type type = instruction->GetResultType(); |
| 3411 | DCHECK(type == DataType::Type::kInt32 || type == DataType::Type::kInt64); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3412 | |
| 3413 | int64_t magic; |
| 3414 | int shift; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3415 | CalculateMagicAndShiftForDivRem( |
| 3416 | imm, type == DataType::Type::kInt64 /* is_long */, &magic, &shift); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3417 | |
| 3418 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 3419 | Register temp = temps.AcquireSameSizeAs(out); |
| 3420 | |
| 3421 | // temp = get_high(dividend * magic) |
| 3422 | __ Mov(temp, magic); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3423 | if (type == DataType::Type::kInt64) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3424 | __ Smulh(temp, dividend, temp); |
| 3425 | } else { |
| 3426 | __ Smull(temp.X(), dividend, temp); |
| 3427 | __ Lsr(temp.X(), temp.X(), 32); |
| 3428 | } |
| 3429 | |
| 3430 | if (imm > 0 && magic < 0) { |
| 3431 | __ Add(temp, temp, dividend); |
| 3432 | } else if (imm < 0 && magic > 0) { |
| 3433 | __ Sub(temp, temp, dividend); |
| 3434 | } |
| 3435 | |
| 3436 | if (shift != 0) { |
| 3437 | __ Asr(temp, temp, shift); |
| 3438 | } |
| 3439 | |
| 3440 | if (instruction->IsDiv()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3441 | __ Sub(out, temp, Operand(temp, ASR, type == DataType::Type::kInt64 ? 63 : 31)); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3442 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3443 | __ Sub(temp, temp, Operand(temp, ASR, type == DataType::Type::kInt64 ? 63 : 31)); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3444 | // TODO: Strength reduction for msub. |
| 3445 | Register temp_imm = temps.AcquireSameSizeAs(out); |
| 3446 | __ Mov(temp_imm, imm); |
| 3447 | __ Msub(out, temp, temp_imm, dividend); |
| 3448 | } |
| 3449 | } |
| 3450 | |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 3451 | void InstructionCodeGeneratorARM64::GenerateIntDivForConstDenom(HDiv *instruction) { |
Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 3452 | int64_t imm = Int64FromLocation(instruction->GetLocations()->InAt(1)); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3453 | |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 3454 | if (imm == 0) { |
| 3455 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 3456 | return; |
| 3457 | } |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3458 | |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 3459 | if (IsPowerOfTwo(AbsOrMin(imm))) { |
| 3460 | GenerateIntDivForPower2Denom(instruction); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3461 | } else { |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 3462 | // Cases imm == -1 or imm == 1 are handled by InstructionSimplifier. |
| 3463 | DCHECK(imm < -2 || imm > 2) << imm; |
| 3464 | GenerateDivRemWithAnyConstant(instruction); |
| 3465 | } |
| 3466 | } |
| 3467 | |
| 3468 | void InstructionCodeGeneratorARM64::GenerateIntDiv(HDiv *instruction) { |
| 3469 | DCHECK(DataType::IsIntOrLongType(instruction->GetResultType())) |
| 3470 | << instruction->GetResultType(); |
| 3471 | |
| 3472 | if (instruction->GetLocations()->InAt(1).IsConstant()) { |
| 3473 | GenerateIntDivForConstDenom(instruction); |
| 3474 | } else { |
| 3475 | Register out = OutputRegister(instruction); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3476 | Register dividend = InputRegisterAt(instruction, 0); |
| 3477 | Register divisor = InputRegisterAt(instruction, 1); |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 3478 | __ Sdiv(out, dividend, divisor); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3479 | } |
| 3480 | } |
| 3481 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3482 | void LocationsBuilderARM64::VisitDiv(HDiv* div) { |
| 3483 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3484 | new (GetGraph()->GetAllocator()) LocationSummary(div, LocationSummary::kNoCall); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3485 | switch (div->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3486 | case DataType::Type::kInt32: |
| 3487 | case DataType::Type::kInt64: |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3488 | locations->SetInAt(0, Location::RequiresRegister()); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3489 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3490 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3491 | break; |
| 3492 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3493 | case DataType::Type::kFloat32: |
| 3494 | case DataType::Type::kFloat64: |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3495 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3496 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3497 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3498 | break; |
| 3499 | |
| 3500 | default: |
| 3501 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3502 | } |
| 3503 | } |
| 3504 | |
| 3505 | void InstructionCodeGeneratorARM64::VisitDiv(HDiv* div) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3506 | DataType::Type type = div->GetResultType(); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3507 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3508 | case DataType::Type::kInt32: |
| 3509 | case DataType::Type::kInt64: |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 3510 | GenerateIntDiv(div); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3511 | break; |
| 3512 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3513 | case DataType::Type::kFloat32: |
| 3514 | case DataType::Type::kFloat64: |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3515 | __ Fdiv(OutputFPRegister(div), InputFPRegisterAt(div, 0), InputFPRegisterAt(div, 1)); |
| 3516 | break; |
| 3517 | |
| 3518 | default: |
| 3519 | LOG(FATAL) << "Unexpected div type " << type; |
| 3520 | } |
| 3521 | } |
| 3522 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3523 | void LocationsBuilderARM64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3524 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3525 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3526 | } |
| 3527 | |
| 3528 | void InstructionCodeGeneratorARM64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 3529 | SlowPathCodeARM64* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 3530 | new (codegen_->GetScopedAllocator()) DivZeroCheckSlowPathARM64(instruction); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3531 | codegen_->AddSlowPath(slow_path); |
| 3532 | Location value = instruction->GetLocations()->InAt(0); |
| 3533 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3534 | DataType::Type type = instruction->GetType(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 3535 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3536 | if (!DataType::IsIntegralType(type)) { |
Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 3537 | LOG(FATAL) << "Unexpected type " << type << " for DivZeroCheck."; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 3538 | return; |
| 3539 | } |
| 3540 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3541 | if (value.IsConstant()) { |
Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 3542 | int64_t divisor = Int64FromLocation(value); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3543 | if (divisor == 0) { |
| 3544 | __ B(slow_path->GetEntryLabel()); |
| 3545 | } else { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 3546 | // A division by a non-null constant is valid. We don't need to perform |
| 3547 | // any check, so simply fall through. |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3548 | } |
| 3549 | } else { |
| 3550 | __ Cbz(InputRegisterAt(instruction, 0), slow_path->GetEntryLabel()); |
| 3551 | } |
| 3552 | } |
| 3553 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3554 | void LocationsBuilderARM64::VisitDoubleConstant(HDoubleConstant* constant) { |
| 3555 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3556 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3557 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3558 | } |
| 3559 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3560 | void InstructionCodeGeneratorARM64::VisitDoubleConstant( |
| 3561 | HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3562 | // Will be generated at use site. |
| 3563 | } |
| 3564 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3565 | void LocationsBuilderARM64::VisitExit(HExit* exit) { |
| 3566 | exit->SetLocations(nullptr); |
| 3567 | } |
| 3568 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3569 | void InstructionCodeGeneratorARM64::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3570 | } |
| 3571 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3572 | void LocationsBuilderARM64::VisitFloatConstant(HFloatConstant* constant) { |
| 3573 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3574 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3575 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3576 | } |
| 3577 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3578 | void InstructionCodeGeneratorARM64::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3579 | // Will be generated at use site. |
| 3580 | } |
| 3581 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3582 | void InstructionCodeGeneratorARM64::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Aart Bik | a8b8e9b | 2018-01-09 11:01:02 -0800 | [diff] [blame] | 3583 | if (successor->IsExitBlock()) { |
| 3584 | DCHECK(got->GetPrevious()->AlwaysThrows()); |
| 3585 | return; // no code needed |
| 3586 | } |
| 3587 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3588 | HBasicBlock* block = got->GetBlock(); |
| 3589 | HInstruction* previous = got->GetPrevious(); |
| 3590 | HLoopInformation* info = block->GetLoopInformation(); |
| 3591 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3592 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Nicolas Geoffray | 8d72832 | 2018-01-18 22:44:32 +0000 | [diff] [blame] | 3593 | if (codegen_->GetCompilerOptions().CountHotnessInCompiledCode()) { |
| 3594 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 3595 | Register temp1 = temps.AcquireX(); |
| 3596 | Register temp2 = temps.AcquireX(); |
| 3597 | __ Ldr(temp1, MemOperand(sp, 0)); |
| 3598 | __ Ldrh(temp2, MemOperand(temp1, ArtMethod::HotnessCountOffset().Int32Value())); |
| 3599 | __ Add(temp2, temp2, 1); |
| 3600 | __ Strh(temp2, MemOperand(temp1, ArtMethod::HotnessCountOffset().Int32Value())); |
| 3601 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3602 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 3603 | return; |
| 3604 | } |
| 3605 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 3606 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 3607 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3608 | } |
| 3609 | if (!codegen_->GoesToNextBlock(block, successor)) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3610 | __ B(codegen_->GetLabelOf(successor)); |
| 3611 | } |
| 3612 | } |
| 3613 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3614 | void LocationsBuilderARM64::VisitGoto(HGoto* got) { |
| 3615 | got->SetLocations(nullptr); |
| 3616 | } |
| 3617 | |
| 3618 | void InstructionCodeGeneratorARM64::VisitGoto(HGoto* got) { |
| 3619 | HandleGoto(got, got->GetSuccessor()); |
| 3620 | } |
| 3621 | |
| 3622 | void LocationsBuilderARM64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 3623 | try_boundary->SetLocations(nullptr); |
| 3624 | } |
| 3625 | |
| 3626 | void InstructionCodeGeneratorARM64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 3627 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 3628 | if (!successor->IsExitBlock()) { |
| 3629 | HandleGoto(try_boundary, successor); |
| 3630 | } |
| 3631 | } |
| 3632 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3633 | void InstructionCodeGeneratorARM64::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3634 | size_t condition_input_index, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3635 | vixl::aarch64::Label* true_target, |
| 3636 | vixl::aarch64::Label* false_target) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3637 | HInstruction* cond = instruction->InputAt(condition_input_index); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3638 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3639 | if (true_target == nullptr && false_target == nullptr) { |
| 3640 | // Nothing to do. The code always falls through. |
| 3641 | return; |
| 3642 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3643 | // Constant condition, statically compared against "true" (integer value 1). |
| 3644 | if (cond->AsIntConstant()->IsTrue()) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3645 | if (true_target != nullptr) { |
| 3646 | __ B(true_target); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3647 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3648 | } else { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3649 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3650 | if (false_target != nullptr) { |
| 3651 | __ B(false_target); |
| 3652 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3653 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3654 | return; |
| 3655 | } |
| 3656 | |
| 3657 | // The following code generates these patterns: |
| 3658 | // (1) true_target == nullptr && false_target != nullptr |
| 3659 | // - opposite condition true => branch to false_target |
| 3660 | // (2) true_target != nullptr && false_target == nullptr |
| 3661 | // - condition true => branch to true_target |
| 3662 | // (3) true_target != nullptr && false_target != nullptr |
| 3663 | // - condition true => branch to true_target |
| 3664 | // - branch to false_target |
| 3665 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3666 | // The condition instruction has been materialized, compare the output to 0. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3667 | Location cond_val = instruction->GetLocations()->InAt(condition_input_index); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3668 | DCHECK(cond_val.IsRegister()); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3669 | if (true_target == nullptr) { |
| 3670 | __ Cbz(InputRegisterAt(instruction, condition_input_index), false_target); |
| 3671 | } else { |
| 3672 | __ Cbnz(InputRegisterAt(instruction, condition_input_index), true_target); |
| 3673 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3674 | } else { |
| 3675 | // The condition instruction has not been materialized, use its inputs as |
| 3676 | // the comparison and its condition as the branch condition. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3677 | HCondition* condition = cond->AsCondition(); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3678 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3679 | DataType::Type type = condition->InputAt(0)->GetType(); |
| 3680 | if (DataType::IsFloatingPointType(type)) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3681 | GenerateFcmp(condition); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3682 | if (true_target == nullptr) { |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3683 | IfCondition opposite_condition = condition->GetOppositeCondition(); |
| 3684 | __ B(ARM64FPCondition(opposite_condition, condition->IsGtBias()), false_target); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3685 | } else { |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3686 | __ B(ARM64FPCondition(condition->GetCondition(), condition->IsGtBias()), true_target); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3687 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3688 | } else { |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3689 | // Integer cases. |
| 3690 | Register lhs = InputRegisterAt(condition, 0); |
| 3691 | Operand rhs = InputOperandAt(condition, 1); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3692 | |
| 3693 | Condition arm64_cond; |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3694 | vixl::aarch64::Label* non_fallthrough_target; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3695 | if (true_target == nullptr) { |
| 3696 | arm64_cond = ARM64Condition(condition->GetOppositeCondition()); |
| 3697 | non_fallthrough_target = false_target; |
| 3698 | } else { |
| 3699 | arm64_cond = ARM64Condition(condition->GetCondition()); |
| 3700 | non_fallthrough_target = true_target; |
| 3701 | } |
| 3702 | |
Aart Bik | 086d27e | 2016-01-20 17:02:00 -0800 | [diff] [blame] | 3703 | 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] | 3704 | rhs.IsImmediate() && (rhs.GetImmediate() == 0)) { |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3705 | switch (arm64_cond) { |
| 3706 | case eq: |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3707 | __ Cbz(lhs, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3708 | break; |
| 3709 | case ne: |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3710 | __ Cbnz(lhs, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3711 | break; |
| 3712 | case lt: |
| 3713 | // Test the sign bit and branch accordingly. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3714 | __ Tbnz(lhs, (lhs.IsX() ? kXRegSize : kWRegSize) - 1, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3715 | break; |
| 3716 | case ge: |
| 3717 | // Test the sign bit and branch accordingly. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3718 | __ Tbz(lhs, (lhs.IsX() ? kXRegSize : kWRegSize) - 1, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3719 | break; |
| 3720 | default: |
| 3721 | // Without the `static_cast` the compiler throws an error for |
| 3722 | // `-Werror=sign-promo`. |
| 3723 | LOG(FATAL) << "Unexpected condition: " << static_cast<int>(arm64_cond); |
| 3724 | } |
| 3725 | } else { |
| 3726 | __ Cmp(lhs, rhs); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3727 | __ B(arm64_cond, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3728 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3729 | } |
| 3730 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3731 | |
| 3732 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 3733 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 3734 | if (true_target != nullptr && false_target != nullptr) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3735 | __ B(false_target); |
| 3736 | } |
| 3737 | } |
| 3738 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3739 | void LocationsBuilderARM64::VisitIf(HIf* if_instr) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3740 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(if_instr); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3741 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3742 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3743 | } |
| 3744 | } |
| 3745 | |
| 3746 | void InstructionCodeGeneratorARM64::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3747 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 3748 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3749 | vixl::aarch64::Label* true_target = codegen_->GetLabelOf(true_successor); |
| 3750 | if (codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor)) { |
| 3751 | true_target = nullptr; |
| 3752 | } |
| 3753 | vixl::aarch64::Label* false_target = codegen_->GetLabelOf(false_successor); |
| 3754 | if (codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor)) { |
| 3755 | false_target = nullptr; |
| 3756 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3757 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3758 | } |
| 3759 | |
| 3760 | void LocationsBuilderARM64::VisitDeoptimize(HDeoptimize* deoptimize) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3761 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3762 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 3763 | InvokeRuntimeCallingConvention calling_convention; |
| 3764 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 3765 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0).GetCode())); |
| 3766 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3767 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3768 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3769 | } |
| 3770 | } |
| 3771 | |
| 3772 | void InstructionCodeGeneratorARM64::VisitDeoptimize(HDeoptimize* deoptimize) { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 3773 | SlowPathCodeARM64* slow_path = |
| 3774 | deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathARM64>(deoptimize); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3775 | GenerateTestAndBranch(deoptimize, |
| 3776 | /* condition_input_index */ 0, |
| 3777 | slow_path->GetEntryLabel(), |
| 3778 | /* false_target */ nullptr); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3779 | } |
| 3780 | |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 3781 | void LocationsBuilderARM64::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3782 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 3783 | LocationSummary(flag, LocationSummary::kNoCall); |
| 3784 | locations->SetOut(Location::RequiresRegister()); |
| 3785 | } |
| 3786 | |
| 3787 | void InstructionCodeGeneratorARM64::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 3788 | __ Ldr(OutputRegister(flag), |
| 3789 | MemOperand(sp, codegen_->GetStackOffsetOfShouldDeoptimizeFlag())); |
| 3790 | } |
| 3791 | |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3792 | static inline bool IsConditionOnFloatingPointValues(HInstruction* condition) { |
| 3793 | return condition->IsCondition() && |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3794 | DataType::IsFloatingPointType(condition->InputAt(0)->GetType()); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3795 | } |
| 3796 | |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3797 | static inline Condition GetConditionForSelect(HCondition* condition) { |
| 3798 | IfCondition cond = condition->AsCondition()->GetCondition(); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3799 | return IsConditionOnFloatingPointValues(condition) ? ARM64FPCondition(cond, condition->IsGtBias()) |
| 3800 | : ARM64Condition(cond); |
| 3801 | } |
| 3802 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3803 | void LocationsBuilderARM64::VisitSelect(HSelect* select) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3804 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(select); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3805 | if (DataType::IsFloatingPointType(select->GetType())) { |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3806 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3807 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3808 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3809 | } else { |
| 3810 | HConstant* cst_true_value = select->GetTrueValue()->AsConstant(); |
| 3811 | HConstant* cst_false_value = select->GetFalseValue()->AsConstant(); |
| 3812 | bool is_true_value_constant = cst_true_value != nullptr; |
| 3813 | bool is_false_value_constant = cst_false_value != nullptr; |
| 3814 | // Ask VIXL whether we should synthesize constants in registers. |
| 3815 | // We give an arbitrary register to VIXL when dealing with non-constant inputs. |
| 3816 | Operand true_op = is_true_value_constant ? |
| 3817 | Operand(Int64FromConstant(cst_true_value)) : Operand(x1); |
| 3818 | Operand false_op = is_false_value_constant ? |
| 3819 | Operand(Int64FromConstant(cst_false_value)) : Operand(x2); |
| 3820 | bool true_value_in_register = false; |
| 3821 | bool false_value_in_register = false; |
| 3822 | MacroAssembler::GetCselSynthesisInformation( |
| 3823 | x0, true_op, false_op, &true_value_in_register, &false_value_in_register); |
| 3824 | true_value_in_register |= !is_true_value_constant; |
| 3825 | false_value_in_register |= !is_false_value_constant; |
| 3826 | |
| 3827 | locations->SetInAt(1, true_value_in_register ? Location::RequiresRegister() |
| 3828 | : Location::ConstantLocation(cst_true_value)); |
| 3829 | locations->SetInAt(0, false_value_in_register ? Location::RequiresRegister() |
| 3830 | : Location::ConstantLocation(cst_false_value)); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3831 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3832 | } |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3833 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3834 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
| 3835 | locations->SetInAt(2, Location::RequiresRegister()); |
| 3836 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3837 | } |
| 3838 | |
| 3839 | void InstructionCodeGeneratorARM64::VisitSelect(HSelect* select) { |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3840 | HInstruction* cond = select->GetCondition(); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3841 | Condition csel_cond; |
| 3842 | |
| 3843 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 3844 | if (cond->IsCondition() && cond->GetNext() == select) { |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3845 | // Use the condition flags set by the previous instruction. |
| 3846 | csel_cond = GetConditionForSelect(cond->AsCondition()); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3847 | } else { |
| 3848 | __ Cmp(InputRegisterAt(select, 2), 0); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3849 | csel_cond = ne; |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3850 | } |
| 3851 | } else if (IsConditionOnFloatingPointValues(cond)) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3852 | GenerateFcmp(cond); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3853 | csel_cond = GetConditionForSelect(cond->AsCondition()); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3854 | } else { |
| 3855 | __ Cmp(InputRegisterAt(cond, 0), InputOperandAt(cond, 1)); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3856 | csel_cond = GetConditionForSelect(cond->AsCondition()); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3857 | } |
| 3858 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3859 | if (DataType::IsFloatingPointType(select->GetType())) { |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3860 | __ Fcsel(OutputFPRegister(select), |
| 3861 | InputFPRegisterAt(select, 1), |
| 3862 | InputFPRegisterAt(select, 0), |
| 3863 | csel_cond); |
| 3864 | } else { |
| 3865 | __ Csel(OutputRegister(select), |
| 3866 | InputOperandAt(select, 1), |
| 3867 | InputOperandAt(select, 0), |
| 3868 | csel_cond); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3869 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3870 | } |
| 3871 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 3872 | void LocationsBuilderARM64::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3873 | new (GetGraph()->GetAllocator()) LocationSummary(info); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 3874 | } |
| 3875 | |
David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 3876 | void InstructionCodeGeneratorARM64::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 3877 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 3878 | } |
| 3879 | |
| 3880 | void CodeGeneratorARM64::GenerateNop() { |
| 3881 | __ Nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 3882 | } |
| 3883 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3884 | void LocationsBuilderARM64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 3885 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3886 | } |
| 3887 | |
| 3888 | void InstructionCodeGeneratorARM64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 3889 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3890 | } |
| 3891 | |
| 3892 | void LocationsBuilderARM64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 3893 | HandleFieldSet(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3894 | } |
| 3895 | |
| 3896 | void InstructionCodeGeneratorARM64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3897 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3898 | } |
| 3899 | |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3900 | // Temp is used for read barrier. |
| 3901 | static size_t NumberOfInstanceOfTemps(TypeCheckKind type_check_kind) { |
| 3902 | if (kEmitCompilerReadBarrier && |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3903 | (kUseBakerReadBarrier || |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3904 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 3905 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 3906 | type_check_kind == TypeCheckKind::kArrayObjectCheck)) { |
| 3907 | return 1; |
| 3908 | } |
| 3909 | return 0; |
| 3910 | } |
| 3911 | |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 3912 | // Interface case has 3 temps, one for holding the number of interfaces, one for the current |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3913 | // interface pointer, one for loading the current interface. |
| 3914 | // The other checks have one temp for loading the object's class. |
| 3915 | static size_t NumberOfCheckCastTemps(TypeCheckKind type_check_kind) { |
| 3916 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { |
| 3917 | return 3; |
| 3918 | } |
| 3919 | return 1 + NumberOfInstanceOfTemps(type_check_kind); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3920 | } |
| 3921 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3922 | void LocationsBuilderARM64::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3923 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3924 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 3925 | bool baker_read_barrier_slow_path = false; |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3926 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3927 | case TypeCheckKind::kExactCheck: |
| 3928 | case TypeCheckKind::kAbstractClassCheck: |
| 3929 | case TypeCheckKind::kClassHierarchyCheck: |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3930 | case TypeCheckKind::kArrayObjectCheck: { |
| 3931 | bool needs_read_barrier = CodeGenerator::InstanceOfNeedsReadBarrier(instruction); |
| 3932 | call_kind = needs_read_barrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
| 3933 | baker_read_barrier_slow_path = kUseBakerReadBarrier && needs_read_barrier; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3934 | break; |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3935 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3936 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3937 | case TypeCheckKind::kUnresolvedCheck: |
| 3938 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3939 | call_kind = LocationSummary::kCallOnSlowPath; |
| 3940 | break; |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 3941 | case TypeCheckKind::kBitstringCheck: |
| 3942 | break; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3943 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3944 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3945 | LocationSummary* locations = |
| 3946 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 3947 | if (baker_read_barrier_slow_path) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3948 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 3949 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3950 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 3951 | if (type_check_kind == TypeCheckKind::kBitstringCheck) { |
| 3952 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
| 3953 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); |
| 3954 | locations->SetInAt(3, Location::ConstantLocation(instruction->InputAt(3)->AsConstant())); |
| 3955 | } else { |
| 3956 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3957 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3958 | // The "out" register is used as a temporary, so it overlaps with the inputs. |
| 3959 | // Note that TypeCheckSlowPathARM64 uses this register too. |
| 3960 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3961 | // Add temps if necessary for read barriers. |
| 3962 | locations->AddRegisterTemps(NumberOfInstanceOfTemps(type_check_kind)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3963 | } |
| 3964 | |
| 3965 | void InstructionCodeGeneratorARM64::VisitInstanceOf(HInstanceOf* instruction) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3966 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3967 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3968 | Location obj_loc = locations->InAt(0); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3969 | Register obj = InputRegisterAt(instruction, 0); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 3970 | Register cls = (type_check_kind == TypeCheckKind::kBitstringCheck) |
| 3971 | ? Register() |
| 3972 | : InputRegisterAt(instruction, 1); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3973 | Location out_loc = locations->Out(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3974 | Register out = OutputRegister(instruction); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3975 | const size_t num_temps = NumberOfInstanceOfTemps(type_check_kind); |
| 3976 | DCHECK_LE(num_temps, 1u); |
| 3977 | Location maybe_temp_loc = (num_temps >= 1) ? locations->GetTemp(0) : Location::NoLocation(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3978 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 3979 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 3980 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 3981 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3982 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3983 | vixl::aarch64::Label done, zero; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3984 | SlowPathCodeARM64* slow_path = nullptr; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3985 | |
| 3986 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 3987 | // Avoid null check if we know `obj` is not null. |
| 3988 | if (instruction->MustDoNullCheck()) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3989 | __ Cbz(obj, &zero); |
| 3990 | } |
| 3991 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3992 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3993 | case TypeCheckKind::kExactCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3994 | ReadBarrierOption read_barrier_option = |
| 3995 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 3996 | // /* HeapReference<Class> */ out = obj->klass_ |
| 3997 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3998 | out_loc, |
| 3999 | obj_loc, |
| 4000 | class_offset, |
| 4001 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 4002 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4003 | __ Cmp(out, cls); |
| 4004 | __ Cset(out, eq); |
| 4005 | if (zero.IsLinked()) { |
| 4006 | __ B(&done); |
| 4007 | } |
| 4008 | break; |
| 4009 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4010 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4011 | case TypeCheckKind::kAbstractClassCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 4012 | ReadBarrierOption read_barrier_option = |
| 4013 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 4014 | // /* HeapReference<Class> */ out = obj->klass_ |
| 4015 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4016 | out_loc, |
| 4017 | obj_loc, |
| 4018 | class_offset, |
| 4019 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 4020 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4021 | // If the class is abstract, we eagerly fetch the super class of the |
| 4022 | // object to avoid doing a comparison we know will fail. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4023 | vixl::aarch64::Label loop, success; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4024 | __ Bind(&loop); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4025 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4026 | GenerateReferenceLoadOneRegister(instruction, |
| 4027 | out_loc, |
| 4028 | super_offset, |
| 4029 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 4030 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4031 | // If `out` is null, we use it for the result, and jump to `done`. |
| 4032 | __ Cbz(out, &done); |
| 4033 | __ Cmp(out, cls); |
| 4034 | __ B(ne, &loop); |
| 4035 | __ Mov(out, 1); |
| 4036 | if (zero.IsLinked()) { |
| 4037 | __ B(&done); |
| 4038 | } |
| 4039 | break; |
| 4040 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4041 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4042 | case TypeCheckKind::kClassHierarchyCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 4043 | ReadBarrierOption read_barrier_option = |
| 4044 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 4045 | // /* HeapReference<Class> */ out = obj->klass_ |
| 4046 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4047 | out_loc, |
| 4048 | obj_loc, |
| 4049 | class_offset, |
| 4050 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 4051 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4052 | // Walk over the class hierarchy to find a match. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4053 | vixl::aarch64::Label loop, success; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4054 | __ Bind(&loop); |
| 4055 | __ Cmp(out, cls); |
| 4056 | __ B(eq, &success); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4057 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4058 | GenerateReferenceLoadOneRegister(instruction, |
| 4059 | out_loc, |
| 4060 | super_offset, |
| 4061 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 4062 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4063 | __ Cbnz(out, &loop); |
| 4064 | // If `out` is null, we use it for the result, and jump to `done`. |
| 4065 | __ B(&done); |
| 4066 | __ Bind(&success); |
| 4067 | __ Mov(out, 1); |
| 4068 | if (zero.IsLinked()) { |
| 4069 | __ B(&done); |
| 4070 | } |
| 4071 | break; |
| 4072 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4073 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4074 | case TypeCheckKind::kArrayObjectCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 4075 | ReadBarrierOption read_barrier_option = |
| 4076 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 4077 | // /* HeapReference<Class> */ out = obj->klass_ |
| 4078 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4079 | out_loc, |
| 4080 | obj_loc, |
| 4081 | class_offset, |
| 4082 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 4083 | read_barrier_option); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 4084 | // Do an exact check. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4085 | vixl::aarch64::Label exact_check; |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 4086 | __ Cmp(out, cls); |
| 4087 | __ B(eq, &exact_check); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4088 | // 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] | 4089 | // /* HeapReference<Class> */ out = out->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4090 | GenerateReferenceLoadOneRegister(instruction, |
| 4091 | out_loc, |
| 4092 | component_offset, |
| 4093 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 4094 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4095 | // If `out` is null, we use it for the result, and jump to `done`. |
| 4096 | __ Cbz(out, &done); |
| 4097 | __ Ldrh(out, HeapOperand(out, primitive_offset)); |
| 4098 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
| 4099 | __ Cbnz(out, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 4100 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4101 | __ Mov(out, 1); |
| 4102 | __ B(&done); |
| 4103 | break; |
| 4104 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4105 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4106 | case TypeCheckKind::kArrayCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 4107 | // No read barrier since the slow path will retry upon failure. |
| 4108 | // /* HeapReference<Class> */ out = obj->klass_ |
| 4109 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4110 | out_loc, |
| 4111 | obj_loc, |
| 4112 | class_offset, |
| 4113 | maybe_temp_loc, |
| 4114 | kWithoutReadBarrier); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4115 | __ Cmp(out, cls); |
| 4116 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 4117 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathARM64( |
| 4118 | instruction, /* is_fatal */ false); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4119 | codegen_->AddSlowPath(slow_path); |
| 4120 | __ B(ne, slow_path->GetEntryLabel()); |
| 4121 | __ Mov(out, 1); |
| 4122 | if (zero.IsLinked()) { |
| 4123 | __ B(&done); |
| 4124 | } |
| 4125 | break; |
| 4126 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4127 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 4128 | case TypeCheckKind::kUnresolvedCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4129 | case TypeCheckKind::kInterfaceCheck: { |
| 4130 | // Note that we indeed only call on slow path, but we always go |
| 4131 | // into the slow path for the unresolved and interface check |
| 4132 | // cases. |
| 4133 | // |
| 4134 | // We cannot directly call the InstanceofNonTrivial runtime |
| 4135 | // entry point without resorting to a type checking slow path |
| 4136 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 4137 | // require to assign fixed registers for the inputs of this |
| 4138 | // HInstanceOf instruction (following the runtime calling |
| 4139 | // convention), which might be cluttered by the potential first |
| 4140 | // read barrier emission at the beginning of this method. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 4141 | // |
| 4142 | // TODO: Introduce a new runtime entry point taking the object |
| 4143 | // to test (instead of its class) as argument, and let it deal |
| 4144 | // with the read barrier issues. This will let us refactor this |
| 4145 | // case of the `switch` code as it was previously (with a direct |
| 4146 | // call to the runtime not using a type checking slow path). |
| 4147 | // This should also be beneficial for the other cases above. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4148 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 4149 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathARM64( |
| 4150 | instruction, /* is_fatal */ false); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4151 | codegen_->AddSlowPath(slow_path); |
| 4152 | __ B(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4153 | if (zero.IsLinked()) { |
| 4154 | __ B(&done); |
| 4155 | } |
| 4156 | break; |
| 4157 | } |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 4158 | |
| 4159 | case TypeCheckKind::kBitstringCheck: { |
| 4160 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4161 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4162 | out_loc, |
| 4163 | obj_loc, |
| 4164 | class_offset, |
| 4165 | maybe_temp_loc, |
| 4166 | kWithoutReadBarrier); |
| 4167 | |
| 4168 | GenerateBitstringTypeCheckCompare(instruction, out); |
| 4169 | __ Cset(out, eq); |
| 4170 | if (zero.IsLinked()) { |
| 4171 | __ B(&done); |
| 4172 | } |
| 4173 | break; |
| 4174 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4175 | } |
| 4176 | |
| 4177 | if (zero.IsLinked()) { |
| 4178 | __ Bind(&zero); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4179 | __ Mov(out, 0); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4180 | } |
| 4181 | |
| 4182 | if (done.IsLinked()) { |
| 4183 | __ Bind(&done); |
| 4184 | } |
| 4185 | |
| 4186 | if (slow_path != nullptr) { |
| 4187 | __ Bind(slow_path->GetExitLabel()); |
| 4188 | } |
| 4189 | } |
| 4190 | |
| 4191 | void LocationsBuilderARM64::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4192 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 4193 | LocationSummary::CallKind call_kind = CodeGenerator::GetCheckCastCallKind(instruction); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4194 | LocationSummary* locations = |
| 4195 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4196 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 4197 | if (type_check_kind == TypeCheckKind::kBitstringCheck) { |
| 4198 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
| 4199 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); |
| 4200 | locations->SetInAt(3, Location::ConstantLocation(instruction->InputAt(3)->AsConstant())); |
| 4201 | } else { |
| 4202 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4203 | } |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4204 | // Add temps for read barriers and other uses. One is used by TypeCheckSlowPathARM64. |
| 4205 | locations->AddRegisterTemps(NumberOfCheckCastTemps(type_check_kind)); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4206 | } |
| 4207 | |
| 4208 | void InstructionCodeGeneratorARM64::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 4209 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4210 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4211 | Location obj_loc = locations->InAt(0); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4212 | Register obj = InputRegisterAt(instruction, 0); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 4213 | Register cls = (type_check_kind == TypeCheckKind::kBitstringCheck) |
| 4214 | ? Register() |
| 4215 | : InputRegisterAt(instruction, 1); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4216 | const size_t num_temps = NumberOfCheckCastTemps(type_check_kind); |
| 4217 | DCHECK_GE(num_temps, 1u); |
| 4218 | DCHECK_LE(num_temps, 3u); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4219 | Location temp_loc = locations->GetTemp(0); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4220 | Location maybe_temp2_loc = (num_temps >= 2) ? locations->GetTemp(1) : Location::NoLocation(); |
| 4221 | Location maybe_temp3_loc = (num_temps >= 3) ? locations->GetTemp(2) : Location::NoLocation(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4222 | Register temp = WRegisterFrom(temp_loc); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4223 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 4224 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 4225 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 4226 | const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 4227 | const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value(); |
| 4228 | const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value(); |
| 4229 | const uint32_t object_array_data_offset = |
| 4230 | mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4231 | |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 4232 | bool is_type_check_slow_path_fatal = CodeGenerator::IsTypeCheckSlowPathFatal(instruction); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4233 | SlowPathCodeARM64* type_check_slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 4234 | new (codegen_->GetScopedAllocator()) TypeCheckSlowPathARM64( |
| 4235 | instruction, is_type_check_slow_path_fatal); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4236 | codegen_->AddSlowPath(type_check_slow_path); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4237 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4238 | vixl::aarch64::Label done; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4239 | // Avoid null check if we know obj is not null. |
| 4240 | if (instruction->MustDoNullCheck()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4241 | __ Cbz(obj, &done); |
| 4242 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4243 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4244 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4245 | case TypeCheckKind::kExactCheck: |
| 4246 | case TypeCheckKind::kArrayCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4247 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4248 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4249 | temp_loc, |
| 4250 | obj_loc, |
| 4251 | class_offset, |
| 4252 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4253 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4254 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4255 | __ Cmp(temp, cls); |
| 4256 | // Jump to slow path for throwing the exception or doing a |
| 4257 | // more involved array check. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4258 | __ B(ne, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4259 | break; |
| 4260 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4261 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4262 | case TypeCheckKind::kAbstractClassCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4263 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4264 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4265 | temp_loc, |
| 4266 | obj_loc, |
| 4267 | class_offset, |
| 4268 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4269 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4270 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4271 | // If the class is abstract, we eagerly fetch the super class of the |
| 4272 | // object to avoid doing a comparison we know will fail. |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 4273 | vixl::aarch64::Label loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4274 | __ Bind(&loop); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4275 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4276 | GenerateReferenceLoadOneRegister(instruction, |
| 4277 | temp_loc, |
| 4278 | super_offset, |
| 4279 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4280 | kWithoutReadBarrier); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4281 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 4282 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 4283 | // exception. |
| 4284 | __ Cbz(temp, type_check_slow_path->GetEntryLabel()); |
| 4285 | // Otherwise, compare classes. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4286 | __ Cmp(temp, cls); |
| 4287 | __ B(ne, &loop); |
| 4288 | break; |
| 4289 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4290 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4291 | case TypeCheckKind::kClassHierarchyCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4292 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4293 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4294 | temp_loc, |
| 4295 | obj_loc, |
| 4296 | class_offset, |
| 4297 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4298 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4299 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4300 | // Walk over the class hierarchy to find a match. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4301 | vixl::aarch64::Label loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4302 | __ Bind(&loop); |
| 4303 | __ Cmp(temp, cls); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 4304 | __ B(eq, &done); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4305 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4306 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4307 | GenerateReferenceLoadOneRegister(instruction, |
| 4308 | temp_loc, |
| 4309 | super_offset, |
| 4310 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4311 | kWithoutReadBarrier); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4312 | |
| 4313 | // If the class reference currently in `temp` is not null, jump |
| 4314 | // back at the beginning of the loop. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4315 | __ Cbnz(temp, &loop); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4316 | // Otherwise, jump to the slow path to throw the exception. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4317 | __ B(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4318 | break; |
| 4319 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4320 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4321 | case TypeCheckKind::kArrayObjectCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4322 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4323 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4324 | temp_loc, |
| 4325 | obj_loc, |
| 4326 | class_offset, |
| 4327 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4328 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4329 | |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 4330 | // Do an exact check. |
| 4331 | __ Cmp(temp, cls); |
| 4332 | __ B(eq, &done); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4333 | |
| 4334 | // 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] | 4335 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4336 | GenerateReferenceLoadOneRegister(instruction, |
| 4337 | temp_loc, |
| 4338 | component_offset, |
| 4339 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4340 | kWithoutReadBarrier); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4341 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 4342 | // If the component type is null, jump to the slow path to throw the exception. |
| 4343 | __ Cbz(temp, type_check_slow_path->GetEntryLabel()); |
| 4344 | // Otherwise, the object is indeed an array. Further check that this component type is not a |
| 4345 | // primitive type. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4346 | __ Ldrh(temp, HeapOperand(temp, primitive_offset)); |
| 4347 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 4348 | __ Cbnz(temp, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4349 | break; |
| 4350 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4351 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 4352 | case TypeCheckKind::kUnresolvedCheck: |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4353 | // We always go into the type check slow path for the unresolved check cases. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4354 | // |
| 4355 | // We cannot directly call the CheckCast runtime entry point |
| 4356 | // without resorting to a type checking slow path here (i.e. by |
| 4357 | // calling InvokeRuntime directly), as it would require to |
| 4358 | // assign fixed registers for the inputs of this HInstanceOf |
| 4359 | // instruction (following the runtime calling convention), which |
| 4360 | // might be cluttered by the potential first read barrier |
| 4361 | // emission at the beginning of this method. |
| 4362 | __ B(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4363 | break; |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4364 | case TypeCheckKind::kInterfaceCheck: { |
| 4365 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4366 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4367 | temp_loc, |
| 4368 | obj_loc, |
| 4369 | class_offset, |
| 4370 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4371 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4372 | |
| 4373 | // /* HeapReference<Class> */ temp = temp->iftable_ |
| 4374 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4375 | temp_loc, |
| 4376 | temp_loc, |
| 4377 | iftable_offset, |
| 4378 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4379 | kWithoutReadBarrier); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 4380 | // Iftable is never null. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4381 | __ Ldr(WRegisterFrom(maybe_temp2_loc), HeapOperand(temp.W(), array_length_offset)); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 4382 | // Loop through the iftable and check if any class matches. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4383 | vixl::aarch64::Label start_loop; |
| 4384 | __ Bind(&start_loop); |
Mathieu Chartier | afbcdaf | 2016-11-14 10:50:29 -0800 | [diff] [blame] | 4385 | __ Cbz(WRegisterFrom(maybe_temp2_loc), type_check_slow_path->GetEntryLabel()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4386 | __ Ldr(WRegisterFrom(maybe_temp3_loc), HeapOperand(temp.W(), object_array_data_offset)); |
| 4387 | GetAssembler()->MaybeUnpoisonHeapReference(WRegisterFrom(maybe_temp3_loc)); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4388 | // Go to next interface. |
| 4389 | __ Add(temp, temp, 2 * kHeapReferenceSize); |
| 4390 | __ Sub(WRegisterFrom(maybe_temp2_loc), WRegisterFrom(maybe_temp2_loc), 2); |
Mathieu Chartier | afbcdaf | 2016-11-14 10:50:29 -0800 | [diff] [blame] | 4391 | // Compare the classes and continue the loop if they do not match. |
| 4392 | __ Cmp(cls, WRegisterFrom(maybe_temp3_loc)); |
| 4393 | __ B(ne, &start_loop); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4394 | break; |
| 4395 | } |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 4396 | |
| 4397 | case TypeCheckKind::kBitstringCheck: { |
| 4398 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4399 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4400 | temp_loc, |
| 4401 | obj_loc, |
| 4402 | class_offset, |
| 4403 | maybe_temp2_loc, |
| 4404 | kWithoutReadBarrier); |
| 4405 | |
| 4406 | GenerateBitstringTypeCheckCompare(instruction, temp); |
| 4407 | __ B(ne, type_check_slow_path->GetEntryLabel()); |
| 4408 | break; |
| 4409 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4410 | } |
Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame] | 4411 | __ Bind(&done); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4412 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4413 | __ Bind(type_check_slow_path->GetExitLabel()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4414 | } |
| 4415 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4416 | void LocationsBuilderARM64::VisitIntConstant(HIntConstant* constant) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4417 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(constant); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4418 | locations->SetOut(Location::ConstantLocation(constant)); |
| 4419 | } |
| 4420 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4421 | void InstructionCodeGeneratorARM64::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4422 | // Will be generated at use site. |
| 4423 | } |
| 4424 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 4425 | void LocationsBuilderARM64::VisitNullConstant(HNullConstant* constant) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4426 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(constant); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 4427 | locations->SetOut(Location::ConstantLocation(constant)); |
| 4428 | } |
| 4429 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4430 | void InstructionCodeGeneratorARM64::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 4431 | // Will be generated at use site. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 4432 | } |
| 4433 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4434 | void LocationsBuilderARM64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 4435 | // The trampoline uses the same calling convention as dex calling conventions, |
| 4436 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 4437 | // the method_idx. |
| 4438 | HandleInvoke(invoke); |
| 4439 | } |
| 4440 | |
| 4441 | void InstructionCodeGeneratorARM64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 4442 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 4443 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4444 | } |
| 4445 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4446 | void LocationsBuilderARM64::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 4447 | InvokeDexCallingConventionVisitorARM64 calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 4448 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4449 | } |
| 4450 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4451 | void LocationsBuilderARM64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 4452 | HandleInvoke(invoke); |
| 4453 | } |
| 4454 | |
| 4455 | void InstructionCodeGeneratorARM64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 4456 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4457 | LocationSummary* locations = invoke->GetLocations(); |
| 4458 | Register temp = XRegisterFrom(locations->GetTemp(0)); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4459 | Location receiver = locations->InAt(0); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4460 | Offset class_offset = mirror::Object::ClassOffset(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4461 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64PointerSize); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4462 | |
| 4463 | // The register ip1 is required to be used for the hidden argument in |
| 4464 | // art_quick_imt_conflict_trampoline, so prevent VIXL from using it. |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 4465 | MacroAssembler* masm = GetVIXLAssembler(); |
| 4466 | UseScratchRegisterScope scratch_scope(masm); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4467 | scratch_scope.Exclude(ip1); |
| 4468 | __ Mov(ip1, invoke->GetDexMethodIndex()); |
| 4469 | |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4470 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4471 | if (receiver.IsStackSlot()) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4472 | __ Ldr(temp.W(), StackOperandFrom(receiver)); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4473 | { |
| 4474 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 4475 | // /* HeapReference<Class> */ temp = temp->klass_ |
| 4476 | __ Ldr(temp.W(), HeapOperand(temp.W(), class_offset)); |
| 4477 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
| 4478 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4479 | } else { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4480 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4481 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4482 | __ Ldr(temp.W(), HeapOperandFrom(receiver, class_offset)); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4483 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4484 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4485 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4486 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 4487 | // emit a read barrier for the previous class reference load. |
| 4488 | // However this is not required in practice, as this is an |
| 4489 | // intermediate/temporary reference and because the current |
| 4490 | // concurrent copying collector keeps the from-space memory |
| 4491 | // intact/accessible until the end of the marking phase (the |
| 4492 | // concurrent copying collector may not in the future). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4493 | GetAssembler()->MaybeUnpoisonHeapReference(temp.W()); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 4494 | __ Ldr(temp, |
| 4495 | MemOperand(temp, mirror::Class::ImtPtrOffset(kArm64PointerSize).Uint32Value())); |
| 4496 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 4497 | invoke->GetImtIndex(), kArm64PointerSize)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4498 | // temp = temp->GetImtEntryAt(method_offset); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4499 | __ Ldr(temp, MemOperand(temp, method_offset)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4500 | // lr = temp->GetEntryPoint(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4501 | __ Ldr(lr, MemOperand(temp, entry_point.Int32Value())); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4502 | |
| 4503 | { |
| 4504 | // Ensure the pc position is recorded immediately after the `blr` instruction. |
| 4505 | ExactAssemblyScope eas(GetVIXLAssembler(), kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 4506 | |
| 4507 | // lr(); |
| 4508 | __ blr(lr); |
| 4509 | DCHECK(!codegen_->IsLeafMethod()); |
| 4510 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 4511 | } |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 4512 | |
| 4513 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4514 | } |
| 4515 | |
| 4516 | void LocationsBuilderARM64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4517 | IntrinsicLocationsBuilderARM64 intrinsic(GetGraph()->GetAllocator(), codegen_); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4518 | if (intrinsic.TryDispatch(invoke)) { |
| 4519 | return; |
| 4520 | } |
| 4521 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4522 | HandleInvoke(invoke); |
| 4523 | } |
| 4524 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 4525 | void LocationsBuilderARM64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 4526 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 4527 | // art::PrepareForRegisterAllocation. |
| 4528 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4529 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4530 | IntrinsicLocationsBuilderARM64 intrinsic(GetGraph()->GetAllocator(), codegen_); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4531 | if (intrinsic.TryDispatch(invoke)) { |
| 4532 | return; |
| 4533 | } |
| 4534 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4535 | HandleInvoke(invoke); |
| 4536 | } |
| 4537 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4538 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARM64* codegen) { |
| 4539 | if (invoke->GetLocations()->Intrinsified()) { |
| 4540 | IntrinsicCodeGeneratorARM64 intrinsic(codegen); |
| 4541 | intrinsic.Dispatch(invoke); |
| 4542 | return true; |
| 4543 | } |
| 4544 | return false; |
| 4545 | } |
| 4546 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4547 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorARM64::GetSupportedInvokeStaticOrDirectDispatch( |
| 4548 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4549 | HInvokeStaticOrDirect* invoke ATTRIBUTE_UNUSED) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 4550 | // On ARM64 we support all dispatch types. |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4551 | return desired_dispatch_info; |
| 4552 | } |
| 4553 | |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4554 | void CodeGeneratorARM64::GenerateStaticOrDirectCall( |
| 4555 | HInvokeStaticOrDirect* invoke, Location temp, SlowPathCode* slow_path) { |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4556 | // 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] | 4557 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 4558 | switch (invoke->GetMethodLoadKind()) { |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4559 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: { |
| 4560 | uint32_t offset = |
| 4561 | GetThreadOffset<kArm64PointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4562 | // temp = thread->string_init_entrypoint |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4563 | __ Ldr(XRegisterFrom(temp), MemOperand(tr, offset)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4564 | break; |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4565 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4566 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4567 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4568 | break; |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4569 | case HInvokeStaticOrDirect::MethodLoadKind::kBootImageLinkTimePcRelative: { |
| 4570 | DCHECK(GetCompilerOptions().IsBootImage()); |
| 4571 | // Add ADRP with its PC-relative method patch. |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4572 | vixl::aarch64::Label* adrp_label = NewBootImageMethodPatch(invoke->GetTargetMethod()); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4573 | EmitAdrpPlaceholder(adrp_label, XRegisterFrom(temp)); |
| 4574 | // Add ADD with its PC-relative method patch. |
| 4575 | vixl::aarch64::Label* add_label = |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4576 | NewBootImageMethodPatch(invoke->GetTargetMethod(), adrp_label); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4577 | EmitAddPlaceholder(add_label, XRegisterFrom(temp), XRegisterFrom(temp)); |
| 4578 | break; |
| 4579 | } |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4580 | case HInvokeStaticOrDirect::MethodLoadKind::kBootImageRelRo: { |
| 4581 | // Add ADRP with its PC-relative .data.bimg.rel.ro patch. |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 4582 | uint32_t boot_image_offset = GetBootImageOffset(invoke); |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4583 | vixl::aarch64::Label* adrp_label = NewBootImageRelRoPatch(boot_image_offset); |
| 4584 | EmitAdrpPlaceholder(adrp_label, XRegisterFrom(temp)); |
| 4585 | // Add LDR with its PC-relative .data.bimg.rel.ro patch. |
| 4586 | vixl::aarch64::Label* ldr_label = NewBootImageRelRoPatch(boot_image_offset, adrp_label); |
| 4587 | // Note: Boot image is in the low 4GiB and the entry is 32-bit, so emit a 32-bit load. |
| 4588 | EmitLdrOffsetPlaceholder(ldr_label, WRegisterFrom(temp), XRegisterFrom(temp)); |
| 4589 | break; |
| 4590 | } |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4591 | case HInvokeStaticOrDirect::MethodLoadKind::kBssEntry: { |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4592 | // Add ADRP with its PC-relative .bss entry patch. |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4593 | MethodReference target_method(&GetGraph()->GetDexFile(), invoke->GetDexMethodIndex()); |
| 4594 | vixl::aarch64::Label* adrp_label = NewMethodBssEntryPatch(target_method); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4595 | EmitAdrpPlaceholder(adrp_label, XRegisterFrom(temp)); |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4596 | // Add LDR with its PC-relative .bss entry patch. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4597 | vixl::aarch64::Label* ldr_label = |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4598 | NewMethodBssEntryPatch(target_method, adrp_label); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4599 | EmitLdrOffsetPlaceholder(ldr_label, XRegisterFrom(temp), XRegisterFrom(temp)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4600 | break; |
Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 4601 | } |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 4602 | case HInvokeStaticOrDirect::MethodLoadKind::kJitDirectAddress: |
| 4603 | // Load method address from literal pool. |
| 4604 | __ Ldr(XRegisterFrom(temp), DeduplicateUint64Literal(invoke->GetMethodAddress())); |
| 4605 | break; |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4606 | case HInvokeStaticOrDirect::MethodLoadKind::kRuntimeCall: { |
| 4607 | GenerateInvokeStaticOrDirectRuntimeCall(invoke, temp, slow_path); |
| 4608 | return; // No code pointer retrieval; the runtime performs the call directly. |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4609 | } |
| 4610 | } |
| 4611 | |
| 4612 | switch (invoke->GetCodePtrLocation()) { |
| 4613 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4614 | { |
| 4615 | // Use a scope to help guarantee that `RecordPcInfo()` records the correct pc. |
| 4616 | ExactAssemblyScope eas(GetVIXLAssembler(), |
| 4617 | kInstructionSize, |
| 4618 | CodeBufferCheckScope::kExactSize); |
| 4619 | __ bl(&frame_entry_label_); |
| 4620 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
| 4621 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4622 | break; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4623 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 4624 | // LR = callee_method->entry_point_from_quick_compiled_code_; |
| 4625 | __ Ldr(lr, MemOperand( |
Alexandre Rames | 6dc0174 | 2015-11-12 14:44:19 +0000 | [diff] [blame] | 4626 | XRegisterFrom(callee_method), |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4627 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64PointerSize).Int32Value())); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4628 | { |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4629 | // Use a scope to help guarantee that `RecordPcInfo()` records the correct pc. |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4630 | ExactAssemblyScope eas(GetVIXLAssembler(), |
| 4631 | kInstructionSize, |
| 4632 | CodeBufferCheckScope::kExactSize); |
| 4633 | // lr() |
| 4634 | __ blr(lr); |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4635 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4636 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4637 | break; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 4638 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4639 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4640 | DCHECK(!IsLeafMethod()); |
| 4641 | } |
| 4642 | |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4643 | void CodeGeneratorARM64::GenerateVirtualCall( |
| 4644 | HInvokeVirtual* invoke, Location temp_in, SlowPathCode* slow_path) { |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4645 | // Use the calling convention instead of the location of the receiver, as |
| 4646 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 4647 | // slow path, the arguments have been moved to the right place, so here we are |
| 4648 | // guaranteed that the receiver is the first register of the calling convention. |
| 4649 | InvokeDexCallingConvention calling_convention; |
| 4650 | Register receiver = calling_convention.GetRegisterAt(0); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4651 | Register temp = XRegisterFrom(temp_in); |
| 4652 | size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 4653 | invoke->GetVTableIndex(), kArm64PointerSize).SizeValue(); |
| 4654 | Offset class_offset = mirror::Object::ClassOffset(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4655 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64PointerSize); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4656 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4657 | DCHECK(receiver.IsRegister()); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4658 | |
| 4659 | { |
| 4660 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 4661 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 4662 | // /* HeapReference<Class> */ temp = receiver->klass_ |
| 4663 | __ Ldr(temp.W(), HeapOperandFrom(LocationFrom(receiver), class_offset)); |
| 4664 | MaybeRecordImplicitNullCheck(invoke); |
| 4665 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4666 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 4667 | // emit a read barrier for the previous class reference load. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4668 | // intermediate/temporary reference and because the current |
| 4669 | // concurrent copying collector keeps the from-space memory |
| 4670 | // intact/accessible until the end of the marking phase (the |
| 4671 | // concurrent copying collector may not in the future). |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4672 | GetAssembler()->MaybeUnpoisonHeapReference(temp.W()); |
| 4673 | // temp = temp->GetMethodAt(method_offset); |
| 4674 | __ Ldr(temp, MemOperand(temp, method_offset)); |
| 4675 | // lr = temp->GetEntryPoint(); |
| 4676 | __ Ldr(lr, MemOperand(temp, entry_point.SizeValue())); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4677 | { |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4678 | // Use a scope to help guarantee that `RecordPcInfo()` records the correct pc. |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4679 | ExactAssemblyScope eas(GetVIXLAssembler(), kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 4680 | // lr(); |
| 4681 | __ blr(lr); |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4682 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4683 | } |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4684 | } |
| 4685 | |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4686 | void LocationsBuilderARM64::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 4687 | HandleInvoke(invoke); |
| 4688 | } |
| 4689 | |
| 4690 | void InstructionCodeGeneratorARM64::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 4691 | codegen_->GenerateInvokePolymorphicCall(invoke); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 4692 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4693 | } |
| 4694 | |
Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 4695 | void LocationsBuilderARM64::VisitInvokeCustom(HInvokeCustom* invoke) { |
| 4696 | HandleInvoke(invoke); |
| 4697 | } |
| 4698 | |
| 4699 | void InstructionCodeGeneratorARM64::VisitInvokeCustom(HInvokeCustom* invoke) { |
| 4700 | codegen_->GenerateInvokeCustomCall(invoke); |
| 4701 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
| 4702 | } |
| 4703 | |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 4704 | vixl::aarch64::Label* CodeGeneratorARM64::NewBootImageIntrinsicPatch( |
| 4705 | uint32_t intrinsic_data, |
| 4706 | vixl::aarch64::Label* adrp_label) { |
| 4707 | return NewPcRelativePatch( |
| 4708 | /* dex_file */ nullptr, intrinsic_data, adrp_label, &boot_image_intrinsic_patches_); |
| 4709 | } |
| 4710 | |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4711 | vixl::aarch64::Label* CodeGeneratorARM64::NewBootImageRelRoPatch( |
| 4712 | uint32_t boot_image_offset, |
| 4713 | vixl::aarch64::Label* adrp_label) { |
| 4714 | return NewPcRelativePatch( |
| 4715 | /* dex_file */ nullptr, boot_image_offset, adrp_label, &boot_image_method_patches_); |
| 4716 | } |
| 4717 | |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4718 | vixl::aarch64::Label* CodeGeneratorARM64::NewBootImageMethodPatch( |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4719 | MethodReference target_method, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4720 | vixl::aarch64::Label* adrp_label) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4721 | return NewPcRelativePatch( |
| 4722 | target_method.dex_file, target_method.index, adrp_label, &boot_image_method_patches_); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4723 | } |
| 4724 | |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4725 | vixl::aarch64::Label* CodeGeneratorARM64::NewMethodBssEntryPatch( |
| 4726 | MethodReference target_method, |
| 4727 | vixl::aarch64::Label* adrp_label) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4728 | return NewPcRelativePatch( |
| 4729 | target_method.dex_file, target_method.index, adrp_label, &method_bss_entry_patches_); |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4730 | } |
| 4731 | |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4732 | vixl::aarch64::Label* CodeGeneratorARM64::NewBootImageTypePatch( |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4733 | const DexFile& dex_file, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4734 | dex::TypeIndex type_index, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4735 | vixl::aarch64::Label* adrp_label) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4736 | return NewPcRelativePatch(&dex_file, type_index.index_, adrp_label, &boot_image_type_patches_); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4737 | } |
| 4738 | |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4739 | vixl::aarch64::Label* CodeGeneratorARM64::NewBssEntryTypePatch( |
| 4740 | const DexFile& dex_file, |
| 4741 | dex::TypeIndex type_index, |
| 4742 | vixl::aarch64::Label* adrp_label) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4743 | return NewPcRelativePatch(&dex_file, type_index.index_, adrp_label, &type_bss_entry_patches_); |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4744 | } |
| 4745 | |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4746 | vixl::aarch64::Label* CodeGeneratorARM64::NewBootImageStringPatch( |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4747 | const DexFile& dex_file, |
| 4748 | dex::StringIndex string_index, |
| 4749 | vixl::aarch64::Label* adrp_label) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4750 | return NewPcRelativePatch( |
| 4751 | &dex_file, string_index.index_, adrp_label, &boot_image_string_patches_); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4752 | } |
| 4753 | |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 4754 | vixl::aarch64::Label* CodeGeneratorARM64::NewStringBssEntryPatch( |
| 4755 | const DexFile& dex_file, |
| 4756 | dex::StringIndex string_index, |
| 4757 | vixl::aarch64::Label* adrp_label) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4758 | return NewPcRelativePatch(&dex_file, string_index.index_, adrp_label, &string_bss_entry_patches_); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 4759 | } |
| 4760 | |
Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 4761 | void CodeGeneratorARM64::EmitBakerReadBarrierCbnz(uint32_t custom_data) { |
| 4762 | ExactAssemblyScope guard(GetVIXLAssembler(), 1 * vixl::aarch64::kInstructionSize); |
| 4763 | if (Runtime::Current()->UseJitCompilation()) { |
| 4764 | auto it = jit_baker_read_barrier_slow_paths_.FindOrAdd(custom_data); |
| 4765 | vixl::aarch64::Label* slow_path_entry = &it->second.label; |
| 4766 | __ cbnz(mr, slow_path_entry); |
| 4767 | } else { |
| 4768 | baker_read_barrier_patches_.emplace_back(custom_data); |
| 4769 | vixl::aarch64::Label* cbnz_label = &baker_read_barrier_patches_.back().label; |
| 4770 | __ bind(cbnz_label); |
| 4771 | __ cbnz(mr, static_cast<int64_t>(0)); // Placeholder, patched at link-time. |
| 4772 | } |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 4773 | } |
| 4774 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4775 | vixl::aarch64::Label* CodeGeneratorARM64::NewPcRelativePatch( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4776 | const DexFile* dex_file, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4777 | uint32_t offset_or_index, |
| 4778 | vixl::aarch64::Label* adrp_label, |
| 4779 | ArenaDeque<PcRelativePatchInfo>* patches) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4780 | // Add a patch entry and return the label. |
| 4781 | patches->emplace_back(dex_file, offset_or_index); |
| 4782 | PcRelativePatchInfo* info = &patches->back(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4783 | vixl::aarch64::Label* label = &info->label; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4784 | // If adrp_label is null, this is the ADRP patch and needs to point to its own label. |
| 4785 | info->pc_insn_label = (adrp_label != nullptr) ? adrp_label : label; |
| 4786 | return label; |
| 4787 | } |
| 4788 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4789 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateBootImageAddressLiteral( |
| 4790 | uint64_t address) { |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4791 | return DeduplicateUint32Literal(dchecked_integral_cast<uint32_t>(address)); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4792 | } |
| 4793 | |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 4794 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateJitStringLiteral( |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 4795 | const DexFile& dex_file, dex::StringIndex string_index, Handle<mirror::String> handle) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 4796 | ReserveJitStringRoot(StringReference(&dex_file, string_index), handle); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 4797 | return jit_string_patches_.GetOrCreate( |
| 4798 | StringReference(&dex_file, string_index), |
| 4799 | [this]() { return __ CreateLiteralDestroyedWithPool<uint32_t>(/* placeholder */ 0u); }); |
| 4800 | } |
| 4801 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 4802 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateJitClassLiteral( |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 4803 | const DexFile& dex_file, dex::TypeIndex type_index, Handle<mirror::Class> handle) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 4804 | ReserveJitClassRoot(TypeReference(&dex_file, type_index), handle); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 4805 | return jit_class_patches_.GetOrCreate( |
| 4806 | TypeReference(&dex_file, type_index), |
| 4807 | [this]() { return __ CreateLiteralDestroyedWithPool<uint32_t>(/* placeholder */ 0u); }); |
| 4808 | } |
| 4809 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4810 | void CodeGeneratorARM64::EmitAdrpPlaceholder(vixl::aarch64::Label* fixup_label, |
| 4811 | vixl::aarch64::Register reg) { |
| 4812 | DCHECK(reg.IsX()); |
| 4813 | SingleEmissionCheckScope guard(GetVIXLAssembler()); |
| 4814 | __ Bind(fixup_label); |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 4815 | __ adrp(reg, /* offset placeholder */ static_cast<int64_t>(0)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4816 | } |
| 4817 | |
| 4818 | void CodeGeneratorARM64::EmitAddPlaceholder(vixl::aarch64::Label* fixup_label, |
| 4819 | vixl::aarch64::Register out, |
| 4820 | vixl::aarch64::Register base) { |
| 4821 | DCHECK(out.IsX()); |
| 4822 | DCHECK(base.IsX()); |
| 4823 | SingleEmissionCheckScope guard(GetVIXLAssembler()); |
| 4824 | __ Bind(fixup_label); |
| 4825 | __ add(out, base, Operand(/* offset placeholder */ 0)); |
| 4826 | } |
| 4827 | |
| 4828 | void CodeGeneratorARM64::EmitLdrOffsetPlaceholder(vixl::aarch64::Label* fixup_label, |
| 4829 | vixl::aarch64::Register out, |
| 4830 | vixl::aarch64::Register base) { |
| 4831 | DCHECK(base.IsX()); |
| 4832 | SingleEmissionCheckScope guard(GetVIXLAssembler()); |
| 4833 | __ Bind(fixup_label); |
| 4834 | __ ldr(out, MemOperand(base, /* offset placeholder */ 0)); |
| 4835 | } |
| 4836 | |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 4837 | void CodeGeneratorARM64::LoadBootImageAddress(vixl::aarch64::Register reg, |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 4838 | uint32_t boot_image_reference) { |
| 4839 | if (GetCompilerOptions().IsBootImage()) { |
| 4840 | // Add ADRP with its PC-relative type patch. |
| 4841 | vixl::aarch64::Label* adrp_label = NewBootImageIntrinsicPatch(boot_image_reference); |
| 4842 | EmitAdrpPlaceholder(adrp_label, reg.X()); |
| 4843 | // Add ADD with its PC-relative type patch. |
| 4844 | vixl::aarch64::Label* add_label = NewBootImageIntrinsicPatch(boot_image_reference, adrp_label); |
| 4845 | EmitAddPlaceholder(add_label, reg.X(), reg.X()); |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 4846 | } else if (Runtime::Current()->IsAotCompiler()) { |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 4847 | // Add ADRP with its PC-relative .data.bimg.rel.ro patch. |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 4848 | vixl::aarch64::Label* adrp_label = NewBootImageRelRoPatch(boot_image_reference); |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 4849 | EmitAdrpPlaceholder(adrp_label, reg.X()); |
| 4850 | // Add LDR with its PC-relative .data.bimg.rel.ro patch. |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 4851 | vixl::aarch64::Label* ldr_label = NewBootImageRelRoPatch(boot_image_reference, adrp_label); |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 4852 | EmitLdrOffsetPlaceholder(ldr_label, reg.W(), reg.X()); |
| 4853 | } else { |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 4854 | DCHECK(Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 4855 | gc::Heap* heap = Runtime::Current()->GetHeap(); |
| 4856 | DCHECK(!heap->GetBootImageSpaces().empty()); |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 4857 | const uint8_t* address = heap->GetBootImageSpaces()[0]->Begin() + boot_image_reference; |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 4858 | __ Ldr(reg.W(), DeduplicateBootImageAddressLiteral(reinterpret_cast<uintptr_t>(address))); |
| 4859 | } |
| 4860 | } |
| 4861 | |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 4862 | void CodeGeneratorARM64::AllocateInstanceForIntrinsic(HInvokeStaticOrDirect* invoke, |
| 4863 | uint32_t boot_image_offset) { |
| 4864 | DCHECK(invoke->IsStatic()); |
| 4865 | InvokeRuntimeCallingConvention calling_convention; |
| 4866 | Register argument = calling_convention.GetRegisterAt(0); |
| 4867 | if (GetCompilerOptions().IsBootImage()) { |
| 4868 | DCHECK_EQ(boot_image_offset, IntrinsicVisitor::IntegerValueOfInfo::kInvalidReference); |
| 4869 | // Load the class the same way as for HLoadClass::LoadKind::kBootImageLinkTimePcRelative. |
| 4870 | MethodReference target_method = invoke->GetTargetMethod(); |
| 4871 | dex::TypeIndex type_idx = target_method.dex_file->GetMethodId(target_method.index).class_idx_; |
| 4872 | // Add ADRP with its PC-relative type patch. |
| 4873 | vixl::aarch64::Label* adrp_label = NewBootImageTypePatch(*target_method.dex_file, type_idx); |
| 4874 | EmitAdrpPlaceholder(adrp_label, argument.X()); |
| 4875 | // Add ADD with its PC-relative type patch. |
| 4876 | vixl::aarch64::Label* add_label = |
| 4877 | NewBootImageTypePatch(*target_method.dex_file, type_idx, adrp_label); |
| 4878 | EmitAddPlaceholder(add_label, argument.X(), argument.X()); |
| 4879 | } else { |
| 4880 | LoadBootImageAddress(argument, boot_image_offset); |
| 4881 | } |
| 4882 | InvokeRuntime(kQuickAllocObjectInitialized, invoke, invoke->GetDexPc()); |
| 4883 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
| 4884 | } |
| 4885 | |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4886 | template <linker::LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4887 | inline void CodeGeneratorARM64::EmitPcRelativeLinkerPatches( |
| 4888 | const ArenaDeque<PcRelativePatchInfo>& infos, |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4889 | ArenaVector<linker::LinkerPatch>* linker_patches) { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4890 | for (const PcRelativePatchInfo& info : infos) { |
| 4891 | linker_patches->push_back(Factory(info.label.GetLocation(), |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4892 | info.target_dex_file, |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4893 | info.pc_insn_label->GetLocation(), |
| 4894 | info.offset_or_index)); |
| 4895 | } |
| 4896 | } |
| 4897 | |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 4898 | template <linker::LinkerPatch (*Factory)(size_t, uint32_t, uint32_t)> |
| 4899 | linker::LinkerPatch NoDexFileAdapter(size_t literal_offset, |
| 4900 | const DexFile* target_dex_file, |
| 4901 | uint32_t pc_insn_offset, |
| 4902 | uint32_t boot_image_offset) { |
| 4903 | DCHECK(target_dex_file == nullptr); // Unused for these patches, should be null. |
| 4904 | return Factory(literal_offset, pc_insn_offset, boot_image_offset); |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4905 | } |
| 4906 | |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4907 | void CodeGeneratorARM64::EmitLinkerPatches(ArenaVector<linker::LinkerPatch>* linker_patches) { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4908 | DCHECK(linker_patches->empty()); |
| 4909 | size_t size = |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4910 | boot_image_method_patches_.size() + |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4911 | method_bss_entry_patches_.size() + |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4912 | boot_image_type_patches_.size() + |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 4913 | type_bss_entry_patches_.size() + |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4914 | boot_image_string_patches_.size() + |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 4915 | string_bss_entry_patches_.size() + |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 4916 | boot_image_intrinsic_patches_.size() + |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 4917 | baker_read_barrier_patches_.size(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4918 | linker_patches->reserve(size); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4919 | if (GetCompilerOptions().IsBootImage()) { |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4920 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeMethodPatch>( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4921 | boot_image_method_patches_, linker_patches); |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4922 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeTypePatch>( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4923 | boot_image_type_patches_, linker_patches); |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4924 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeStringPatch>( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4925 | boot_image_string_patches_, linker_patches); |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 4926 | EmitPcRelativeLinkerPatches<NoDexFileAdapter<linker::LinkerPatch::IntrinsicReferencePatch>>( |
| 4927 | boot_image_intrinsic_patches_, linker_patches); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4928 | } else { |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 4929 | EmitPcRelativeLinkerPatches<NoDexFileAdapter<linker::LinkerPatch::DataBimgRelRoPatch>>( |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4930 | boot_image_method_patches_, linker_patches); |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 4931 | DCHECK(boot_image_type_patches_.empty()); |
| 4932 | DCHECK(boot_image_string_patches_.empty()); |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 4933 | DCHECK(boot_image_intrinsic_patches_.empty()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4934 | } |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4935 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::MethodBssEntryPatch>( |
| 4936 | method_bss_entry_patches_, linker_patches); |
| 4937 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::TypeBssEntryPatch>( |
| 4938 | type_bss_entry_patches_, linker_patches); |
| 4939 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::StringBssEntryPatch>( |
| 4940 | string_bss_entry_patches_, linker_patches); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 4941 | for (const BakerReadBarrierPatchInfo& info : baker_read_barrier_patches_) { |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4942 | linker_patches->push_back(linker::LinkerPatch::BakerReadBarrierBranchPatch( |
| 4943 | info.label.GetLocation(), info.custom_data)); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 4944 | } |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4945 | DCHECK_EQ(size, linker_patches->size()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4946 | } |
| 4947 | |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 4948 | bool CodeGeneratorARM64::NeedsThunkCode(const linker::LinkerPatch& patch) const { |
| 4949 | return patch.GetType() == linker::LinkerPatch::Type::kBakerReadBarrierBranch || |
| 4950 | patch.GetType() == linker::LinkerPatch::Type::kCallRelative; |
| 4951 | } |
| 4952 | |
| 4953 | void CodeGeneratorARM64::EmitThunkCode(const linker::LinkerPatch& patch, |
| 4954 | /*out*/ ArenaVector<uint8_t>* code, |
| 4955 | /*out*/ std::string* debug_name) { |
| 4956 | Arm64Assembler assembler(GetGraph()->GetAllocator()); |
| 4957 | switch (patch.GetType()) { |
| 4958 | case linker::LinkerPatch::Type::kCallRelative: { |
| 4959 | // The thunk just uses the entry point in the ArtMethod. This works even for calls |
| 4960 | // to the generic JNI and interpreter trampolines. |
| 4961 | Offset offset(ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
| 4962 | kArm64PointerSize).Int32Value()); |
| 4963 | assembler.JumpTo(ManagedRegister(arm64::X0), offset, ManagedRegister(arm64::IP0)); |
| 4964 | if (GetCompilerOptions().GenerateAnyDebugInfo()) { |
| 4965 | *debug_name = "MethodCallThunk"; |
| 4966 | } |
| 4967 | break; |
| 4968 | } |
| 4969 | case linker::LinkerPatch::Type::kBakerReadBarrierBranch: { |
| 4970 | DCHECK_EQ(patch.GetBakerCustomValue2(), 0u); |
| 4971 | CompileBakerReadBarrierThunk(assembler, patch.GetBakerCustomValue1(), debug_name); |
| 4972 | break; |
| 4973 | } |
| 4974 | default: |
| 4975 | LOG(FATAL) << "Unexpected patch type " << patch.GetType(); |
| 4976 | UNREACHABLE(); |
| 4977 | } |
| 4978 | |
| 4979 | // Ensure we emit the literal pool if any. |
| 4980 | assembler.FinalizeCode(); |
| 4981 | code->resize(assembler.CodeSize()); |
| 4982 | MemoryRegion code_region(code->data(), code->size()); |
| 4983 | assembler.FinalizeInstructions(code_region); |
| 4984 | } |
| 4985 | |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4986 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateUint32Literal(uint32_t value) { |
| 4987 | return uint32_literals_.GetOrCreate( |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4988 | value, |
| 4989 | [this, value]() { return __ CreateLiteralDestroyedWithPool<uint32_t>(value); }); |
| 4990 | } |
| 4991 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4992 | vixl::aarch64::Literal<uint64_t>* CodeGeneratorARM64::DeduplicateUint64Literal(uint64_t value) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4993 | return uint64_literals_.GetOrCreate( |
| 4994 | value, |
| 4995 | [this, value]() { return __ CreateLiteralDestroyedWithPool<uint64_t>(value); }); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4996 | } |
| 4997 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4998 | void InstructionCodeGeneratorARM64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 4999 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 5000 | // art::PrepareForRegisterAllocation. |
| 5001 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 5002 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 5003 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 5004 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 5005 | return; |
| 5006 | } |
| 5007 | |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 5008 | { |
| 5009 | // Ensure that between the BLR (emitted by GenerateStaticOrDirectCall) and RecordPcInfo there |
| 5010 | // are no pools emitted. |
| 5011 | EmissionCheckScope guard(GetVIXLAssembler(), kInvokeCodeMarginSizeInBytes); |
| 5012 | LocationSummary* locations = invoke->GetLocations(); |
| 5013 | codegen_->GenerateStaticOrDirectCall( |
| 5014 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
| 5015 | } |
| 5016 | |
| 5017 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5018 | } |
| 5019 | |
| 5020 | void InstructionCodeGeneratorARM64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 5021 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 5022 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 5023 | return; |
| 5024 | } |
| 5025 | |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 5026 | { |
| 5027 | // Ensure that between the BLR (emitted by GenerateVirtualCall) and RecordPcInfo there |
| 5028 | // are no pools emitted. |
| 5029 | EmissionCheckScope guard(GetVIXLAssembler(), kInvokeCodeMarginSizeInBytes); |
| 5030 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
| 5031 | DCHECK(!codegen_->IsLeafMethod()); |
| 5032 | } |
| 5033 | |
| 5034 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5035 | } |
| 5036 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5037 | HLoadClass::LoadKind CodeGeneratorARM64::GetSupportedLoadClassKind( |
| 5038 | HLoadClass::LoadKind desired_class_load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5039 | switch (desired_class_load_kind) { |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 5040 | case HLoadClass::LoadKind::kInvalid: |
| 5041 | LOG(FATAL) << "UNREACHABLE"; |
| 5042 | UNREACHABLE(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5043 | case HLoadClass::LoadKind::kReferrersClass: |
| 5044 | break; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5045 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5046 | case HLoadClass::LoadKind::kBootImageRelRo: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5047 | case HLoadClass::LoadKind::kBssEntry: |
| 5048 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| 5049 | break; |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 5050 | case HLoadClass::LoadKind::kJitBootImageAddress: |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5051 | case HLoadClass::LoadKind::kJitTableAddress: |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5052 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 5053 | break; |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5054 | case HLoadClass::LoadKind::kRuntimeCall: |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5055 | break; |
| 5056 | } |
| 5057 | return desired_class_load_kind; |
| 5058 | } |
| 5059 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5060 | void LocationsBuilderARM64::VisitLoadClass(HLoadClass* cls) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5061 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5062 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5063 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5064 | CodeGenerator::CreateLoadClassRuntimeCallLocationSummary( |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5065 | cls, |
| 5066 | LocationFrom(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5067 | LocationFrom(vixl::aarch64::x0)); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5068 | DCHECK(calling_convention.GetRegisterAt(0).Is(vixl::aarch64::x0)); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5069 | return; |
| 5070 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5071 | DCHECK(!cls->NeedsAccessCheck()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5072 | |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5073 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
| 5074 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5075 | ? LocationSummary::kCallOnSlowPath |
| 5076 | : LocationSummary::kNoCall; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5077 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(cls, call_kind); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5078 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5079 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5080 | } |
| 5081 | |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5082 | if (load_kind == HLoadClass::LoadKind::kReferrersClass) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5083 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5084 | } |
| 5085 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5086 | if (cls->GetLoadKind() == HLoadClass::LoadKind::kBssEntry) { |
| 5087 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 5088 | // Rely on the type resolution or initialization and marking to save everything we need. |
Vladimir Marko | 3232dbb | 2018-07-25 15:42:46 +0100 | [diff] [blame] | 5089 | locations->SetCustomSlowPathCallerSaves(OneRegInReferenceOutSaveEverythingCallerSaves()); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5090 | } else { |
| 5091 | // For non-Baker read barrier we have a temp-clobbering call. |
| 5092 | } |
| 5093 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5094 | } |
| 5095 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 5096 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 5097 | // move. |
| 5098 | void InstructionCodeGeneratorARM64::VisitLoadClass(HLoadClass* cls) NO_THREAD_SAFETY_ANALYSIS { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5099 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5100 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5101 | codegen_->GenerateLoadClassRuntimeCall(cls); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 5102 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5103 | return; |
| 5104 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5105 | DCHECK(!cls->NeedsAccessCheck()); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5106 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5107 | Location out_loc = cls->GetLocations()->Out(); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5108 | Register out = OutputRegister(cls); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5109 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5110 | const ReadBarrierOption read_barrier_option = cls->IsInBootImage() |
| 5111 | ? kWithoutReadBarrier |
| 5112 | : kCompilerReadBarrierOption; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5113 | bool generate_null_check = false; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5114 | switch (load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5115 | case HLoadClass::LoadKind::kReferrersClass: { |
| 5116 | DCHECK(!cls->CanCallRuntime()); |
| 5117 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 5118 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 5119 | Register current_method = InputRegisterAt(cls, 0); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 5120 | codegen_->GenerateGcRootFieldLoad(cls, |
| 5121 | out_loc, |
| 5122 | current_method, |
| 5123 | ArtMethod::DeclaringClassOffset().Int32Value(), |
| 5124 | /* fixup_label */ nullptr, |
| 5125 | read_barrier_option); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5126 | break; |
| 5127 | } |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5128 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5129 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5130 | // Add ADRP with its PC-relative type patch. |
| 5131 | const DexFile& dex_file = cls->GetDexFile(); |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 5132 | dex::TypeIndex type_index = cls->GetTypeIndex(); |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5133 | vixl::aarch64::Label* adrp_label = codegen_->NewBootImageTypePatch(dex_file, type_index); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5134 | codegen_->EmitAdrpPlaceholder(adrp_label, out.X()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5135 | // Add ADD with its PC-relative type patch. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5136 | vixl::aarch64::Label* add_label = |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5137 | codegen_->NewBootImageTypePatch(dex_file, type_index, adrp_label); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5138 | codegen_->EmitAddPlaceholder(add_label, out.X(), out.X()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5139 | break; |
| 5140 | } |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5141 | case HLoadClass::LoadKind::kBootImageRelRo: { |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 5142 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5143 | uint32_t boot_image_offset = codegen_->GetBootImageOffset(cls); |
| 5144 | // Add ADRP with its PC-relative .data.bimg.rel.ro patch. |
| 5145 | vixl::aarch64::Label* adrp_label = codegen_->NewBootImageRelRoPatch(boot_image_offset); |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 5146 | codegen_->EmitAdrpPlaceholder(adrp_label, out.X()); |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5147 | // Add LDR with its PC-relative .data.bimg.rel.ro patch. |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 5148 | vixl::aarch64::Label* ldr_label = |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5149 | codegen_->NewBootImageRelRoPatch(boot_image_offset, adrp_label); |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 5150 | codegen_->EmitLdrOffsetPlaceholder(ldr_label, out.W(), out.X()); |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 5151 | break; |
| 5152 | } |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5153 | case HLoadClass::LoadKind::kBssEntry: { |
| 5154 | // Add ADRP with its PC-relative Class .bss entry patch. |
| 5155 | const DexFile& dex_file = cls->GetDexFile(); |
| 5156 | dex::TypeIndex type_index = cls->GetTypeIndex(); |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 5157 | vixl::aarch64::Register temp = XRegisterFrom(out_loc); |
| 5158 | vixl::aarch64::Label* adrp_label = codegen_->NewBssEntryTypePatch(dex_file, type_index); |
| 5159 | codegen_->EmitAdrpPlaceholder(adrp_label, temp); |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5160 | // Add LDR with its PC-relative Class .bss entry patch. |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5161 | vixl::aarch64::Label* ldr_label = |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 5162 | codegen_->NewBssEntryTypePatch(dex_file, type_index, adrp_label); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5163 | // /* GcRoot<mirror::Class> */ out = *(base_address + offset) /* PC-relative */ |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 5164 | codegen_->GenerateGcRootFieldLoad(cls, |
| 5165 | out_loc, |
| 5166 | temp, |
| 5167 | /* offset placeholder */ 0u, |
| 5168 | ldr_label, |
| 5169 | read_barrier_option); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5170 | generate_null_check = true; |
| 5171 | break; |
| 5172 | } |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 5173 | case HLoadClass::LoadKind::kJitBootImageAddress: { |
| 5174 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
| 5175 | uint32_t address = reinterpret_cast32<uint32_t>(cls->GetClass().Get()); |
| 5176 | DCHECK_NE(address, 0u); |
| 5177 | __ Ldr(out.W(), codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 5178 | break; |
| 5179 | } |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5180 | case HLoadClass::LoadKind::kJitTableAddress: { |
| 5181 | __ Ldr(out, codegen_->DeduplicateJitClassLiteral(cls->GetDexFile(), |
| 5182 | cls->GetTypeIndex(), |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 5183 | cls->GetClass())); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 5184 | codegen_->GenerateGcRootFieldLoad(cls, |
| 5185 | out_loc, |
| 5186 | out.X(), |
| 5187 | /* offset */ 0, |
| 5188 | /* fixup_label */ nullptr, |
| 5189 | read_barrier_option); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5190 | break; |
| 5191 | } |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5192 | case HLoadClass::LoadKind::kRuntimeCall: |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 5193 | case HLoadClass::LoadKind::kInvalid: |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5194 | LOG(FATAL) << "UNREACHABLE"; |
| 5195 | UNREACHABLE(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5196 | } |
| 5197 | |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5198 | bool do_clinit = cls->MustGenerateClinitCheck(); |
| 5199 | if (generate_null_check || do_clinit) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5200 | DCHECK(cls->CanCallRuntime()); |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 5201 | SlowPathCodeARM64* slow_path = |
| 5202 | new (codegen_->GetScopedAllocator()) LoadClassSlowPathARM64(cls, cls); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5203 | codegen_->AddSlowPath(slow_path); |
| 5204 | if (generate_null_check) { |
| 5205 | __ Cbz(out, slow_path->GetEntryLabel()); |
| 5206 | } |
| 5207 | if (cls->MustGenerateClinitCheck()) { |
| 5208 | GenerateClassInitializationCheck(slow_path, out); |
| 5209 | } else { |
| 5210 | __ Bind(slow_path->GetExitLabel()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5211 | } |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 5212 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5213 | } |
| 5214 | } |
| 5215 | |
Orion Hodson | dbaa5c7 | 2018-05-10 08:22:46 +0100 | [diff] [blame] | 5216 | void LocationsBuilderARM64::VisitLoadMethodHandle(HLoadMethodHandle* load) { |
| 5217 | InvokeRuntimeCallingConvention calling_convention; |
| 5218 | Location location = LocationFrom(calling_convention.GetRegisterAt(0)); |
| 5219 | CodeGenerator::CreateLoadMethodHandleRuntimeCallLocationSummary(load, location, location); |
| 5220 | } |
| 5221 | |
| 5222 | void InstructionCodeGeneratorARM64::VisitLoadMethodHandle(HLoadMethodHandle* load) { |
| 5223 | codegen_->GenerateLoadMethodHandleRuntimeCall(load); |
| 5224 | } |
| 5225 | |
Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 5226 | void LocationsBuilderARM64::VisitLoadMethodType(HLoadMethodType* load) { |
| 5227 | InvokeRuntimeCallingConvention calling_convention; |
| 5228 | Location location = LocationFrom(calling_convention.GetRegisterAt(0)); |
| 5229 | CodeGenerator::CreateLoadMethodTypeRuntimeCallLocationSummary(load, location, location); |
| 5230 | } |
| 5231 | |
| 5232 | void InstructionCodeGeneratorARM64::VisitLoadMethodType(HLoadMethodType* load) { |
| 5233 | codegen_->GenerateLoadMethodTypeRuntimeCall(load); |
| 5234 | } |
| 5235 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5236 | static MemOperand GetExceptionTlsAddress() { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5237 | return MemOperand(tr, Thread::ExceptionOffset<kArm64PointerSize>().Int32Value()); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5238 | } |
| 5239 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5240 | void LocationsBuilderARM64::VisitLoadException(HLoadException* load) { |
| 5241 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5242 | new (GetGraph()->GetAllocator()) LocationSummary(load, LocationSummary::kNoCall); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5243 | locations->SetOut(Location::RequiresRegister()); |
| 5244 | } |
| 5245 | |
| 5246 | void InstructionCodeGeneratorARM64::VisitLoadException(HLoadException* instruction) { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5247 | __ Ldr(OutputRegister(instruction), GetExceptionTlsAddress()); |
| 5248 | } |
| 5249 | |
| 5250 | void LocationsBuilderARM64::VisitClearException(HClearException* clear) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5251 | new (GetGraph()->GetAllocator()) LocationSummary(clear, LocationSummary::kNoCall); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5252 | } |
| 5253 | |
| 5254 | void InstructionCodeGeneratorARM64::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 5255 | __ Str(wzr, GetExceptionTlsAddress()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5256 | } |
| 5257 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5258 | HLoadString::LoadKind CodeGeneratorARM64::GetSupportedLoadStringKind( |
| 5259 | HLoadString::LoadKind desired_string_load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5260 | switch (desired_string_load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5261 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5262 | case HLoadString::LoadKind::kBootImageRelRo: |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5263 | case HLoadString::LoadKind::kBssEntry: |
Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 5264 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5265 | break; |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 5266 | case HLoadString::LoadKind::kJitBootImageAddress: |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5267 | case HLoadString::LoadKind::kJitTableAddress: |
| 5268 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 5269 | break; |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5270 | case HLoadString::LoadKind::kRuntimeCall: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5271 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5272 | } |
| 5273 | return desired_string_load_kind; |
| 5274 | } |
| 5275 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5276 | void LocationsBuilderARM64::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5277 | LocationSummary::CallKind call_kind = CodeGenerator::GetLoadStringCallKind(load); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5278 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(load, call_kind); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5279 | if (load->GetLoadKind() == HLoadString::LoadKind::kRuntimeCall) { |
Christina Wadsworth | 1fe89ea | 2016-08-31 16:14:38 -0700 | [diff] [blame] | 5280 | InvokeRuntimeCallingConvention calling_convention; |
| 5281 | locations->SetOut(calling_convention.GetReturnLocation(load->GetType())); |
| 5282 | } else { |
| 5283 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5284 | if (load->GetLoadKind() == HLoadString::LoadKind::kBssEntry) { |
| 5285 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5286 | // Rely on the pResolveString and marking to save everything we need. |
Vladimir Marko | 3232dbb | 2018-07-25 15:42:46 +0100 | [diff] [blame] | 5287 | locations->SetCustomSlowPathCallerSaves(OneRegInReferenceOutSaveEverythingCallerSaves()); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5288 | } else { |
| 5289 | // For non-Baker read barrier we have a temp-clobbering call. |
| 5290 | } |
| 5291 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5292 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5293 | } |
| 5294 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 5295 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 5296 | // move. |
| 5297 | void InstructionCodeGeneratorARM64::VisitLoadString(HLoadString* load) NO_THREAD_SAFETY_ANALYSIS { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5298 | Register out = OutputRegister(load); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5299 | Location out_loc = load->GetLocations()->Out(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5300 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5301 | switch (load->GetLoadKind()) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5302 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5303 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5304 | // Add ADRP with its PC-relative String patch. |
| 5305 | const DexFile& dex_file = load->GetDexFile(); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5306 | const dex::StringIndex string_index = load->GetStringIndex(); |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5307 | vixl::aarch64::Label* adrp_label = codegen_->NewBootImageStringPatch(dex_file, string_index); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5308 | codegen_->EmitAdrpPlaceholder(adrp_label, out.X()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5309 | // Add ADD with its PC-relative String patch. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5310 | vixl::aarch64::Label* add_label = |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5311 | codegen_->NewBootImageStringPatch(dex_file, string_index, adrp_label); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5312 | codegen_->EmitAddPlaceholder(add_label, out.X(), out.X()); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5313 | return; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5314 | } |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5315 | case HLoadString::LoadKind::kBootImageRelRo: { |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5316 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5317 | // Add ADRP with its PC-relative .data.bimg.rel.ro patch. |
| 5318 | uint32_t boot_image_offset = codegen_->GetBootImageOffset(load); |
| 5319 | vixl::aarch64::Label* adrp_label = codegen_->NewBootImageRelRoPatch(boot_image_offset); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5320 | codegen_->EmitAdrpPlaceholder(adrp_label, out.X()); |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5321 | // Add LDR with its PC-relative .data.bimg.rel.ro patch. |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5322 | vixl::aarch64::Label* ldr_label = |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5323 | codegen_->NewBootImageRelRoPatch(boot_image_offset, adrp_label); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5324 | codegen_->EmitLdrOffsetPlaceholder(ldr_label, out.W(), out.X()); |
| 5325 | return; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5326 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5327 | case HLoadString::LoadKind::kBssEntry: { |
| 5328 | // Add ADRP with its PC-relative String .bss entry patch. |
| 5329 | const DexFile& dex_file = load->GetDexFile(); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5330 | const dex::StringIndex string_index = load->GetStringIndex(); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5331 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 5332 | Register temp = XRegisterFrom(out_loc); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5333 | vixl::aarch64::Label* adrp_label = codegen_->NewStringBssEntryPatch(dex_file, string_index); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5334 | codegen_->EmitAdrpPlaceholder(adrp_label, temp); |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5335 | // Add LDR with its PC-relative String .bss entry patch. |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5336 | vixl::aarch64::Label* ldr_label = |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5337 | codegen_->NewStringBssEntryPatch(dex_file, string_index, adrp_label); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5338 | // /* GcRoot<mirror::String> */ out = *(base_address + offset) /* PC-relative */ |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 5339 | codegen_->GenerateGcRootFieldLoad(load, |
| 5340 | out_loc, |
| 5341 | temp, |
| 5342 | /* offset placeholder */ 0u, |
| 5343 | ldr_label, |
| 5344 | kCompilerReadBarrierOption); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5345 | SlowPathCodeARM64* slow_path = |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 5346 | new (codegen_->GetScopedAllocator()) LoadStringSlowPathARM64(load); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5347 | codegen_->AddSlowPath(slow_path); |
| 5348 | __ Cbz(out.X(), slow_path->GetEntryLabel()); |
| 5349 | __ Bind(slow_path->GetExitLabel()); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 5350 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5351 | return; |
| 5352 | } |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 5353 | case HLoadString::LoadKind::kJitBootImageAddress: { |
| 5354 | uint32_t address = reinterpret_cast32<uint32_t>(load->GetString().Get()); |
| 5355 | DCHECK_NE(address, 0u); |
| 5356 | __ Ldr(out.W(), codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 5357 | return; |
| 5358 | } |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5359 | case HLoadString::LoadKind::kJitTableAddress: { |
| 5360 | __ Ldr(out, codegen_->DeduplicateJitStringLiteral(load->GetDexFile(), |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 5361 | load->GetStringIndex(), |
| 5362 | load->GetString())); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 5363 | codegen_->GenerateGcRootFieldLoad(load, |
| 5364 | out_loc, |
| 5365 | out.X(), |
| 5366 | /* offset */ 0, |
| 5367 | /* fixup_label */ nullptr, |
| 5368 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5369 | return; |
| 5370 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5371 | default: |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 5372 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5373 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5374 | |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 5375 | // TODO: Re-add the compiler code to do string dex cache lookup again. |
Christina Wadsworth | 1fe89ea | 2016-08-31 16:14:38 -0700 | [diff] [blame] | 5376 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5377 | DCHECK_EQ(calling_convention.GetRegisterAt(0).GetCode(), out.GetCode()); |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 5378 | __ Mov(calling_convention.GetRegisterAt(0).W(), load->GetStringIndex().index_); |
Christina Wadsworth | 1fe89ea | 2016-08-31 16:14:38 -0700 | [diff] [blame] | 5379 | codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc()); |
| 5380 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 5381 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5382 | } |
| 5383 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5384 | void LocationsBuilderARM64::VisitLongConstant(HLongConstant* constant) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5385 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(constant); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5386 | locations->SetOut(Location::ConstantLocation(constant)); |
| 5387 | } |
| 5388 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5389 | void InstructionCodeGeneratorARM64::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5390 | // Will be generated at use site. |
| 5391 | } |
| 5392 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5393 | void LocationsBuilderARM64::VisitMonitorOperation(HMonitorOperation* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5394 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 5395 | instruction, LocationSummary::kCallOnMainOnly); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5396 | InvokeRuntimeCallingConvention calling_convention; |
| 5397 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 5398 | } |
| 5399 | |
| 5400 | void InstructionCodeGeneratorARM64::VisitMonitorOperation(HMonitorOperation* instruction) { |
Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 5401 | codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject : kQuickUnlockObject, |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 5402 | instruction, |
| 5403 | instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5404 | if (instruction->IsEnter()) { |
| 5405 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 5406 | } else { |
| 5407 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 5408 | } |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 5409 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5410 | } |
| 5411 | |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5412 | void LocationsBuilderARM64::VisitMul(HMul* mul) { |
| 5413 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5414 | new (GetGraph()->GetAllocator()) LocationSummary(mul, LocationSummary::kNoCall); |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5415 | switch (mul->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5416 | case DataType::Type::kInt32: |
| 5417 | case DataType::Type::kInt64: |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5418 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5419 | locations->SetInAt(1, Location::RequiresRegister()); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 5420 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5421 | break; |
| 5422 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5423 | case DataType::Type::kFloat32: |
| 5424 | case DataType::Type::kFloat64: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 5425 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 5426 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5427 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5428 | break; |
| 5429 | |
| 5430 | default: |
| 5431 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 5432 | } |
| 5433 | } |
| 5434 | |
| 5435 | void InstructionCodeGeneratorARM64::VisitMul(HMul* mul) { |
| 5436 | switch (mul->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5437 | case DataType::Type::kInt32: |
| 5438 | case DataType::Type::kInt64: |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5439 | __ Mul(OutputRegister(mul), InputRegisterAt(mul, 0), InputRegisterAt(mul, 1)); |
| 5440 | break; |
| 5441 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5442 | case DataType::Type::kFloat32: |
| 5443 | case DataType::Type::kFloat64: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 5444 | __ Fmul(OutputFPRegister(mul), InputFPRegisterAt(mul, 0), InputFPRegisterAt(mul, 1)); |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5445 | break; |
| 5446 | |
| 5447 | default: |
| 5448 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 5449 | } |
| 5450 | } |
| 5451 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5452 | void LocationsBuilderARM64::VisitNeg(HNeg* neg) { |
| 5453 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5454 | new (GetGraph()->GetAllocator()) LocationSummary(neg, LocationSummary::kNoCall); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5455 | switch (neg->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5456 | case DataType::Type::kInt32: |
| 5457 | case DataType::Type::kInt64: |
Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 5458 | locations->SetInAt(0, ARM64EncodableConstantOrRegister(neg->InputAt(0), neg)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5459 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5460 | break; |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5461 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5462 | case DataType::Type::kFloat32: |
| 5463 | case DataType::Type::kFloat64: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5464 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 5465 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5466 | break; |
| 5467 | |
| 5468 | default: |
| 5469 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 5470 | } |
| 5471 | } |
| 5472 | |
| 5473 | void InstructionCodeGeneratorARM64::VisitNeg(HNeg* neg) { |
| 5474 | switch (neg->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5475 | case DataType::Type::kInt32: |
| 5476 | case DataType::Type::kInt64: |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5477 | __ Neg(OutputRegister(neg), InputOperandAt(neg, 0)); |
| 5478 | break; |
| 5479 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5480 | case DataType::Type::kFloat32: |
| 5481 | case DataType::Type::kFloat64: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5482 | __ Fneg(OutputFPRegister(neg), InputFPRegisterAt(neg, 0)); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5483 | break; |
| 5484 | |
| 5485 | default: |
| 5486 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 5487 | } |
| 5488 | } |
| 5489 | |
| 5490 | void LocationsBuilderARM64::VisitNewArray(HNewArray* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5491 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 5492 | instruction, LocationSummary::kCallOnMainOnly); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5493 | InvokeRuntimeCallingConvention calling_convention; |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5494 | locations->SetOut(LocationFrom(x0)); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 5495 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 5496 | locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(1))); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5497 | } |
| 5498 | |
| 5499 | void InstructionCodeGeneratorARM64::VisitNewArray(HNewArray* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5500 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 5501 | // of poisoning the reference. |
Nicolas Geoffray | b048cb7 | 2017-01-23 22:50:24 +0000 | [diff] [blame] | 5502 | QuickEntrypointEnum entrypoint = |
| 5503 | CodeGenerator::GetArrayAllocationEntrypoint(instruction->GetLoadClass()->GetClass()); |
| 5504 | codegen_->InvokeRuntime(entrypoint, instruction, instruction->GetDexPc()); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 5505 | CheckEntrypointTypes<kQuickAllocArrayResolved, void*, mirror::Class*, int32_t>(); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 5506 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5507 | } |
| 5508 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5509 | void LocationsBuilderARM64::VisitNewInstance(HNewInstance* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5510 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 5511 | instruction, LocationSummary::kCallOnMainOnly); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5512 | InvokeRuntimeCallingConvention calling_convention; |
Alex Light | d109e30 | 2018-06-27 10:25:41 -0700 | [diff] [blame] | 5513 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5514 | locations->SetOut(calling_convention.GetReturnLocation(DataType::Type::kReference)); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5515 | } |
| 5516 | |
| 5517 | void InstructionCodeGeneratorARM64::VisitNewInstance(HNewInstance* instruction) { |
Alex Light | d109e30 | 2018-06-27 10:25:41 -0700 | [diff] [blame] | 5518 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
| 5519 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 5520 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5521 | } |
| 5522 | |
| 5523 | void LocationsBuilderARM64::VisitNot(HNot* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5524 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Alexandre Rames | 4e59651 | 2014-11-07 15:56:50 +0000 | [diff] [blame] | 5525 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 5526 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5527 | } |
| 5528 | |
| 5529 | void InstructionCodeGeneratorARM64::VisitNot(HNot* instruction) { |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 5530 | switch (instruction->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5531 | case DataType::Type::kInt32: |
| 5532 | case DataType::Type::kInt64: |
Roland Levillain | 55dcfb5 | 2014-10-24 18:09:09 +0100 | [diff] [blame] | 5533 | __ Mvn(OutputRegister(instruction), InputOperandAt(instruction, 0)); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5534 | break; |
| 5535 | |
| 5536 | default: |
| 5537 | LOG(FATAL) << "Unexpected type for not operation " << instruction->GetResultType(); |
| 5538 | } |
| 5539 | } |
| 5540 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5541 | void LocationsBuilderARM64::VisitBooleanNot(HBooleanNot* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5542 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5543 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5544 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5545 | } |
| 5546 | |
| 5547 | void InstructionCodeGeneratorARM64::VisitBooleanNot(HBooleanNot* instruction) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5548 | __ Eor(OutputRegister(instruction), InputRegisterAt(instruction, 0), vixl::aarch64::Operand(1)); |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5549 | } |
| 5550 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5551 | void LocationsBuilderARM64::VisitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5552 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| 5553 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5554 | } |
| 5555 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5556 | void CodeGeneratorARM64::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 5557 | if (CanMoveNullCheckToUser(instruction)) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5558 | return; |
| 5559 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 5560 | { |
| 5561 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 5562 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 5563 | Location obj = instruction->GetLocations()->InAt(0); |
| 5564 | __ Ldr(wzr, HeapOperandFrom(obj, Offset(0))); |
| 5565 | RecordPcInfo(instruction, instruction->GetDexPc()); |
| 5566 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5567 | } |
| 5568 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5569 | void CodeGeneratorARM64::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5570 | SlowPathCodeARM64* slow_path = new (GetScopedAllocator()) NullCheckSlowPathARM64(instruction); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5571 | AddSlowPath(slow_path); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5572 | |
| 5573 | LocationSummary* locations = instruction->GetLocations(); |
| 5574 | Location obj = locations->InAt(0); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5575 | |
| 5576 | __ Cbz(RegisterFrom(obj, instruction->InputAt(0)->GetType()), slow_path->GetEntryLabel()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5577 | } |
| 5578 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5579 | void InstructionCodeGeneratorARM64::VisitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5580 | codegen_->GenerateNullCheck(instruction); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5581 | } |
| 5582 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5583 | void LocationsBuilderARM64::VisitOr(HOr* instruction) { |
| 5584 | HandleBinaryOp(instruction); |
| 5585 | } |
| 5586 | |
| 5587 | void InstructionCodeGeneratorARM64::VisitOr(HOr* instruction) { |
| 5588 | HandleBinaryOp(instruction); |
| 5589 | } |
| 5590 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 5591 | void LocationsBuilderARM64::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
| 5592 | LOG(FATAL) << "Unreachable"; |
| 5593 | } |
| 5594 | |
| 5595 | void InstructionCodeGeneratorARM64::VisitParallelMove(HParallelMove* instruction) { |
Vladimir Marko | bea75ff | 2017-10-11 20:39:54 +0100 | [diff] [blame] | 5596 | if (instruction->GetNext()->IsSuspendCheck() && |
| 5597 | instruction->GetBlock()->GetLoopInformation() != nullptr) { |
| 5598 | HSuspendCheck* suspend_check = instruction->GetNext()->AsSuspendCheck(); |
| 5599 | // The back edge will generate the suspend check. |
| 5600 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(suspend_check, instruction); |
| 5601 | } |
| 5602 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 5603 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 5604 | } |
| 5605 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5606 | void LocationsBuilderARM64::VisitParameterValue(HParameterValue* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5607 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5608 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 5609 | if (location.IsStackSlot()) { |
| 5610 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 5611 | } else if (location.IsDoubleStackSlot()) { |
| 5612 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 5613 | } |
| 5614 | locations->SetOut(location); |
| 5615 | } |
| 5616 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5617 | void InstructionCodeGeneratorARM64::VisitParameterValue( |
| 5618 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5619 | // Nothing to do, the parameter is already at its location. |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5620 | } |
| 5621 | |
| 5622 | void LocationsBuilderARM64::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 5623 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5624 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 5625 | locations->SetOut(LocationFrom(kArtMethodRegister)); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5626 | } |
| 5627 | |
| 5628 | void InstructionCodeGeneratorARM64::VisitCurrentMethod( |
| 5629 | HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
| 5630 | // Nothing to do, the method is already at its location. |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5631 | } |
| 5632 | |
| 5633 | void LocationsBuilderARM64::VisitPhi(HPhi* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5634 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5635 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5636 | locations->SetInAt(i, Location::Any()); |
| 5637 | } |
| 5638 | locations->SetOut(Location::Any()); |
| 5639 | } |
| 5640 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5641 | void InstructionCodeGeneratorARM64::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5642 | LOG(FATAL) << "Unreachable"; |
| 5643 | } |
| 5644 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5645 | void LocationsBuilderARM64::VisitRem(HRem* rem) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5646 | DataType::Type type = rem->GetResultType(); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 5647 | LocationSummary::CallKind call_kind = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5648 | DataType::IsFloatingPointType(type) ? LocationSummary::kCallOnMainOnly |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 5649 | : LocationSummary::kNoCall; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5650 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(rem, call_kind); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5651 | |
| 5652 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5653 | case DataType::Type::kInt32: |
| 5654 | case DataType::Type::kInt64: |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5655 | locations->SetInAt(0, Location::RequiresRegister()); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 5656 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5657 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5658 | break; |
| 5659 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5660 | case DataType::Type::kFloat32: |
| 5661 | case DataType::Type::kFloat64: { |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5662 | InvokeRuntimeCallingConvention calling_convention; |
| 5663 | locations->SetInAt(0, LocationFrom(calling_convention.GetFpuRegisterAt(0))); |
| 5664 | locations->SetInAt(1, LocationFrom(calling_convention.GetFpuRegisterAt(1))); |
| 5665 | locations->SetOut(calling_convention.GetReturnLocation(type)); |
| 5666 | |
| 5667 | break; |
| 5668 | } |
| 5669 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5670 | default: |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5671 | LOG(FATAL) << "Unexpected rem type " << type; |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5672 | } |
| 5673 | } |
| 5674 | |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 5675 | void InstructionCodeGeneratorARM64::GenerateIntRemForPower2Denom(HRem *instruction) { |
Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 5676 | int64_t imm = Int64FromLocation(instruction->GetLocations()->InAt(1)); |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 5677 | uint64_t abs_imm = static_cast<uint64_t>(AbsOrMin(imm)); |
| 5678 | DCHECK(IsPowerOfTwo(abs_imm)) << abs_imm; |
| 5679 | |
| 5680 | Register out = OutputRegister(instruction); |
| 5681 | Register dividend = InputRegisterAt(instruction, 0); |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 5682 | |
Evgeny Astigeevich | a3234e9 | 2018-06-19 23:26:15 +0100 | [diff] [blame] | 5683 | if (abs_imm == 2) { |
| 5684 | __ Cmp(dividend, 0); |
| 5685 | __ And(out, dividend, 1); |
| 5686 | __ Csneg(out, out, out, ge); |
| 5687 | } else { |
| 5688 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 5689 | Register temp = temps.AcquireSameSizeAs(out); |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 5690 | |
Evgeny Astigeevich | a3234e9 | 2018-06-19 23:26:15 +0100 | [diff] [blame] | 5691 | __ Negs(temp, dividend); |
| 5692 | __ And(out, dividend, abs_imm - 1); |
| 5693 | __ And(temp, temp, abs_imm - 1); |
| 5694 | __ Csneg(out, out, temp, mi); |
| 5695 | } |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 5696 | } |
| 5697 | |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 5698 | void InstructionCodeGeneratorARM64::GenerateIntRemForConstDenom(HRem *instruction) { |
Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 5699 | int64_t imm = Int64FromLocation(instruction->GetLocations()->InAt(1)); |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 5700 | |
| 5701 | if (imm == 0) { |
| 5702 | // Do not generate anything. |
| 5703 | // DivZeroCheck would prevent any code to be executed. |
| 5704 | return; |
| 5705 | } |
| 5706 | |
Evgeny Astigeevich | f58dc65 | 2018-06-25 17:54:07 +0100 | [diff] [blame] | 5707 | if (IsPowerOfTwo(AbsOrMin(imm))) { |
| 5708 | // Cases imm == -1 or imm == 1 are handled in constant folding by |
| 5709 | // InstructionWithAbsorbingInputSimplifier. |
| 5710 | // If the cases have survided till code generation they are handled in |
| 5711 | // GenerateIntRemForPower2Denom becauses -1 and 1 are the power of 2 (2^0). |
| 5712 | // The correct code is generated for them, just more instructions. |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 5713 | GenerateIntRemForPower2Denom(instruction); |
| 5714 | } else { |
| 5715 | DCHECK(imm < -2 || imm > 2) << imm; |
| 5716 | GenerateDivRemWithAnyConstant(instruction); |
| 5717 | } |
| 5718 | } |
| 5719 | |
| 5720 | void InstructionCodeGeneratorARM64::GenerateIntRem(HRem* instruction) { |
| 5721 | DCHECK(DataType::IsIntOrLongType(instruction->GetResultType())) |
| 5722 | << instruction->GetResultType(); |
| 5723 | |
| 5724 | if (instruction->GetLocations()->InAt(1).IsConstant()) { |
| 5725 | GenerateIntRemForConstDenom(instruction); |
| 5726 | } else { |
| 5727 | Register out = OutputRegister(instruction); |
| 5728 | Register dividend = InputRegisterAt(instruction, 0); |
| 5729 | Register divisor = InputRegisterAt(instruction, 1); |
| 5730 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 5731 | Register temp = temps.AcquireSameSizeAs(out); |
| 5732 | __ Sdiv(temp, dividend, divisor); |
| 5733 | __ Msub(out, temp, divisor, dividend); |
| 5734 | } |
| 5735 | } |
| 5736 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5737 | void InstructionCodeGeneratorARM64::VisitRem(HRem* rem) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5738 | DataType::Type type = rem->GetResultType(); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5739 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5740 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5741 | case DataType::Type::kInt32: |
| 5742 | case DataType::Type::kInt64: { |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 5743 | GenerateIntRem(rem); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5744 | break; |
| 5745 | } |
| 5746 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5747 | case DataType::Type::kFloat32: |
| 5748 | case DataType::Type::kFloat64: { |
| 5749 | QuickEntrypointEnum entrypoint = |
| 5750 | (type == DataType::Type::kFloat32) ? kQuickFmodf : kQuickFmod; |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 5751 | codegen_->InvokeRuntime(entrypoint, rem, rem->GetDexPc()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5752 | if (type == DataType::Type::kFloat32) { |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5753 | CheckEntrypointTypes<kQuickFmodf, float, float, float>(); |
| 5754 | } else { |
| 5755 | CheckEntrypointTypes<kQuickFmod, double, double, double>(); |
| 5756 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5757 | break; |
| 5758 | } |
| 5759 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5760 | default: |
| 5761 | LOG(FATAL) << "Unexpected rem type " << type; |
Vladimir Marko | 351dddf | 2015-12-11 16:34:46 +0000 | [diff] [blame] | 5762 | UNREACHABLE(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5763 | } |
| 5764 | } |
| 5765 | |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5766 | void LocationsBuilderARM64::VisitMin(HMin* min) { |
Petre-Ionut Tudor | 2227fe4 | 2018-04-20 17:12:05 +0100 | [diff] [blame] | 5767 | HandleBinaryOp(min); |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5768 | } |
| 5769 | |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5770 | void InstructionCodeGeneratorARM64::VisitMin(HMin* min) { |
Petre-Ionut Tudor | 2227fe4 | 2018-04-20 17:12:05 +0100 | [diff] [blame] | 5771 | HandleBinaryOp(min); |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5772 | } |
| 5773 | |
| 5774 | void LocationsBuilderARM64::VisitMax(HMax* max) { |
Petre-Ionut Tudor | 2227fe4 | 2018-04-20 17:12:05 +0100 | [diff] [blame] | 5775 | HandleBinaryOp(max); |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5776 | } |
| 5777 | |
| 5778 | void InstructionCodeGeneratorARM64::VisitMax(HMax* max) { |
Petre-Ionut Tudor | 2227fe4 | 2018-04-20 17:12:05 +0100 | [diff] [blame] | 5779 | HandleBinaryOp(max); |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5780 | } |
| 5781 | |
Aart Bik | 3dad341 | 2018-02-28 12:01:46 -0800 | [diff] [blame] | 5782 | void LocationsBuilderARM64::VisitAbs(HAbs* abs) { |
| 5783 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(abs); |
| 5784 | switch (abs->GetResultType()) { |
| 5785 | case DataType::Type::kInt32: |
| 5786 | case DataType::Type::kInt64: |
| 5787 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5788 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5789 | break; |
| 5790 | case DataType::Type::kFloat32: |
| 5791 | case DataType::Type::kFloat64: |
| 5792 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 5793 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 5794 | break; |
| 5795 | default: |
| 5796 | LOG(FATAL) << "Unexpected type for abs operation " << abs->GetResultType(); |
| 5797 | } |
| 5798 | } |
| 5799 | |
| 5800 | void InstructionCodeGeneratorARM64::VisitAbs(HAbs* abs) { |
| 5801 | switch (abs->GetResultType()) { |
| 5802 | case DataType::Type::kInt32: |
| 5803 | case DataType::Type::kInt64: { |
| 5804 | Register in_reg = InputRegisterAt(abs, 0); |
| 5805 | Register out_reg = OutputRegister(abs); |
| 5806 | __ Cmp(in_reg, Operand(0)); |
| 5807 | __ Cneg(out_reg, in_reg, lt); |
| 5808 | break; |
| 5809 | } |
| 5810 | case DataType::Type::kFloat32: |
| 5811 | case DataType::Type::kFloat64: { |
| 5812 | FPRegister in_reg = InputFPRegisterAt(abs, 0); |
| 5813 | FPRegister out_reg = OutputFPRegister(abs); |
| 5814 | __ Fabs(out_reg, in_reg); |
| 5815 | break; |
| 5816 | } |
| 5817 | default: |
| 5818 | LOG(FATAL) << "Unexpected type for abs operation " << abs->GetResultType(); |
| 5819 | } |
| 5820 | } |
| 5821 | |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 5822 | void LocationsBuilderARM64::VisitConstructorFence(HConstructorFence* constructor_fence) { |
| 5823 | constructor_fence->SetLocations(nullptr); |
| 5824 | } |
| 5825 | |
| 5826 | void InstructionCodeGeneratorARM64::VisitConstructorFence( |
| 5827 | HConstructorFence* constructor_fence ATTRIBUTE_UNUSED) { |
| 5828 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kStoreStore); |
| 5829 | } |
| 5830 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 5831 | void LocationsBuilderARM64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 5832 | memory_barrier->SetLocations(nullptr); |
| 5833 | } |
| 5834 | |
| 5835 | void InstructionCodeGeneratorARM64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5836 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 5837 | } |
| 5838 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5839 | void LocationsBuilderARM64::VisitReturn(HReturn* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5840 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5841 | DataType::Type return_type = instruction->InputAt(0)->GetType(); |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 5842 | locations->SetInAt(0, ARM64ReturnLocation(return_type)); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5843 | } |
| 5844 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5845 | void InstructionCodeGeneratorARM64::VisitReturn(HReturn* instruction ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5846 | codegen_->GenerateFrameExit(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5847 | } |
| 5848 | |
| 5849 | void LocationsBuilderARM64::VisitReturnVoid(HReturnVoid* instruction) { |
| 5850 | instruction->SetLocations(nullptr); |
| 5851 | } |
| 5852 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5853 | void InstructionCodeGeneratorARM64::VisitReturnVoid(HReturnVoid* instruction ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5854 | codegen_->GenerateFrameExit(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5855 | } |
| 5856 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5857 | void LocationsBuilderARM64::VisitRor(HRor* ror) { |
| 5858 | HandleBinaryOp(ror); |
| 5859 | } |
| 5860 | |
| 5861 | void InstructionCodeGeneratorARM64::VisitRor(HRor* ror) { |
| 5862 | HandleBinaryOp(ror); |
| 5863 | } |
| 5864 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5865 | void LocationsBuilderARM64::VisitShl(HShl* shl) { |
| 5866 | HandleShift(shl); |
| 5867 | } |
| 5868 | |
| 5869 | void InstructionCodeGeneratorARM64::VisitShl(HShl* shl) { |
| 5870 | HandleShift(shl); |
| 5871 | } |
| 5872 | |
| 5873 | void LocationsBuilderARM64::VisitShr(HShr* shr) { |
| 5874 | HandleShift(shr); |
| 5875 | } |
| 5876 | |
| 5877 | void InstructionCodeGeneratorARM64::VisitShr(HShr* shr) { |
| 5878 | HandleShift(shr); |
| 5879 | } |
| 5880 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5881 | void LocationsBuilderARM64::VisitSub(HSub* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5882 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5883 | } |
| 5884 | |
| 5885 | void InstructionCodeGeneratorARM64::VisitSub(HSub* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5886 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5887 | } |
| 5888 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5889 | void LocationsBuilderARM64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5890 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5891 | } |
| 5892 | |
| 5893 | void InstructionCodeGeneratorARM64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 5894 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5895 | } |
| 5896 | |
| 5897 | void LocationsBuilderARM64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 5898 | HandleFieldSet(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5899 | } |
| 5900 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5901 | void InstructionCodeGeneratorARM64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5902 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5903 | } |
| 5904 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5905 | void LocationsBuilderARM64::VisitUnresolvedInstanceFieldGet( |
| 5906 | HUnresolvedInstanceFieldGet* instruction) { |
| 5907 | FieldAccessCallingConventionARM64 calling_convention; |
| 5908 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5909 | instruction, instruction->GetFieldType(), calling_convention); |
| 5910 | } |
| 5911 | |
| 5912 | void InstructionCodeGeneratorARM64::VisitUnresolvedInstanceFieldGet( |
| 5913 | HUnresolvedInstanceFieldGet* instruction) { |
| 5914 | FieldAccessCallingConventionARM64 calling_convention; |
| 5915 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5916 | instruction->GetFieldType(), |
| 5917 | instruction->GetFieldIndex(), |
| 5918 | instruction->GetDexPc(), |
| 5919 | calling_convention); |
| 5920 | } |
| 5921 | |
| 5922 | void LocationsBuilderARM64::VisitUnresolvedInstanceFieldSet( |
| 5923 | HUnresolvedInstanceFieldSet* instruction) { |
| 5924 | FieldAccessCallingConventionARM64 calling_convention; |
| 5925 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5926 | instruction, instruction->GetFieldType(), calling_convention); |
| 5927 | } |
| 5928 | |
| 5929 | void InstructionCodeGeneratorARM64::VisitUnresolvedInstanceFieldSet( |
| 5930 | HUnresolvedInstanceFieldSet* instruction) { |
| 5931 | FieldAccessCallingConventionARM64 calling_convention; |
| 5932 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5933 | instruction->GetFieldType(), |
| 5934 | instruction->GetFieldIndex(), |
| 5935 | instruction->GetDexPc(), |
| 5936 | calling_convention); |
| 5937 | } |
| 5938 | |
| 5939 | void LocationsBuilderARM64::VisitUnresolvedStaticFieldGet( |
| 5940 | HUnresolvedStaticFieldGet* instruction) { |
| 5941 | FieldAccessCallingConventionARM64 calling_convention; |
| 5942 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5943 | instruction, instruction->GetFieldType(), calling_convention); |
| 5944 | } |
| 5945 | |
| 5946 | void InstructionCodeGeneratorARM64::VisitUnresolvedStaticFieldGet( |
| 5947 | HUnresolvedStaticFieldGet* instruction) { |
| 5948 | FieldAccessCallingConventionARM64 calling_convention; |
| 5949 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5950 | instruction->GetFieldType(), |
| 5951 | instruction->GetFieldIndex(), |
| 5952 | instruction->GetDexPc(), |
| 5953 | calling_convention); |
| 5954 | } |
| 5955 | |
| 5956 | void LocationsBuilderARM64::VisitUnresolvedStaticFieldSet( |
| 5957 | HUnresolvedStaticFieldSet* instruction) { |
| 5958 | FieldAccessCallingConventionARM64 calling_convention; |
| 5959 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5960 | instruction, instruction->GetFieldType(), calling_convention); |
| 5961 | } |
| 5962 | |
| 5963 | void InstructionCodeGeneratorARM64::VisitUnresolvedStaticFieldSet( |
| 5964 | HUnresolvedStaticFieldSet* instruction) { |
| 5965 | FieldAccessCallingConventionARM64 calling_convention; |
| 5966 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5967 | instruction->GetFieldType(), |
| 5968 | instruction->GetFieldIndex(), |
| 5969 | instruction->GetDexPc(), |
| 5970 | calling_convention); |
| 5971 | } |
| 5972 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5973 | void LocationsBuilderARM64::VisitSuspendCheck(HSuspendCheck* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5974 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 5975 | instruction, LocationSummary::kCallOnSlowPath); |
Artem Serov | 7957d95 | 2017-04-04 15:44:09 +0100 | [diff] [blame] | 5976 | // In suspend check slow path, usually there are no caller-save registers at all. |
| 5977 | // If SIMD instructions are present, however, we force spilling all live SIMD |
| 5978 | // registers in full width (since the runtime only saves/restores lower part). |
| 5979 | locations->SetCustomSlowPathCallerSaves( |
| 5980 | GetGraph()->HasSIMD() ? RegisterSet::AllFpu() : RegisterSet::Empty()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5981 | } |
| 5982 | |
| 5983 | void InstructionCodeGeneratorARM64::VisitSuspendCheck(HSuspendCheck* instruction) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5984 | HBasicBlock* block = instruction->GetBlock(); |
| 5985 | if (block->GetLoopInformation() != nullptr) { |
| 5986 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 5987 | // The back edge will generate the suspend check. |
| 5988 | return; |
| 5989 | } |
| 5990 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 5991 | // The goto will generate the suspend check. |
| 5992 | return; |
| 5993 | } |
| 5994 | GenerateSuspendCheck(instruction, nullptr); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 5995 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5996 | } |
| 5997 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5998 | void LocationsBuilderARM64::VisitThrow(HThrow* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5999 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 6000 | instruction, LocationSummary::kCallOnMainOnly); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6001 | InvokeRuntimeCallingConvention calling_convention; |
| 6002 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 6003 | } |
| 6004 | |
| 6005 | void InstructionCodeGeneratorARM64::VisitThrow(HThrow* instruction) { |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 6006 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 6007 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6008 | } |
| 6009 | |
| 6010 | void LocationsBuilderARM64::VisitTypeConversion(HTypeConversion* conversion) { |
| 6011 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6012 | new (GetGraph()->GetAllocator()) LocationSummary(conversion, LocationSummary::kNoCall); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6013 | DataType::Type input_type = conversion->GetInputType(); |
| 6014 | DataType::Type result_type = conversion->GetResultType(); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6015 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 6016 | << input_type << " -> " << result_type; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6017 | if ((input_type == DataType::Type::kReference) || (input_type == DataType::Type::kVoid) || |
| 6018 | (result_type == DataType::Type::kReference) || (result_type == DataType::Type::kVoid)) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6019 | LOG(FATAL) << "Unexpected type conversion from " << input_type << " to " << result_type; |
| 6020 | } |
| 6021 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6022 | if (DataType::IsFloatingPointType(input_type)) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6023 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 6024 | } else { |
| 6025 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6026 | } |
| 6027 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6028 | if (DataType::IsFloatingPointType(result_type)) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6029 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 6030 | } else { |
| 6031 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6032 | } |
| 6033 | } |
| 6034 | |
| 6035 | void InstructionCodeGeneratorARM64::VisitTypeConversion(HTypeConversion* conversion) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6036 | DataType::Type result_type = conversion->GetResultType(); |
| 6037 | DataType::Type input_type = conversion->GetInputType(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6038 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6039 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 6040 | << input_type << " -> " << result_type; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6041 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6042 | if (DataType::IsIntegralType(result_type) && DataType::IsIntegralType(input_type)) { |
| 6043 | int result_size = DataType::Size(result_type); |
| 6044 | int input_size = DataType::Size(input_type); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 6045 | int min_size = std::min(result_size, input_size); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 6046 | Register output = OutputRegister(conversion); |
| 6047 | Register source = InputRegisterAt(conversion, 0); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6048 | if (result_type == DataType::Type::kInt32 && input_type == DataType::Type::kInt64) { |
Alexandre Rames | 4dff2fd | 2015-08-20 13:36:35 +0100 | [diff] [blame] | 6049 | // 'int' values are used directly as W registers, discarding the top |
| 6050 | // bits, so we don't need to sign-extend and can just perform a move. |
| 6051 | // We do not pass the `kDiscardForSameWReg` argument to force clearing the |
| 6052 | // top 32 bits of the target register. We theoretically could leave those |
| 6053 | // bits unchanged, but we would have to make sure that no code uses a |
| 6054 | // 32bit input value as a 64bit value assuming that the top 32 bits are |
| 6055 | // zero. |
| 6056 | __ Mov(output.W(), source.W()); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6057 | } else if (DataType::IsUnsignedType(result_type) || |
| 6058 | (DataType::IsUnsignedType(input_type) && input_size < result_size)) { |
| 6059 | __ Ubfx(output, output.IsX() ? source.X() : source.W(), 0, result_size * kBitsPerByte); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6060 | } else { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 6061 | __ Sbfx(output, output.IsX() ? source.X() : source.W(), 0, min_size * kBitsPerByte); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6062 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6063 | } else if (DataType::IsFloatingPointType(result_type) && DataType::IsIntegralType(input_type)) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 6064 | __ Scvtf(OutputFPRegister(conversion), InputRegisterAt(conversion, 0)); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6065 | } else if (DataType::IsIntegralType(result_type) && DataType::IsFloatingPointType(input_type)) { |
| 6066 | CHECK(result_type == DataType::Type::kInt32 || result_type == DataType::Type::kInt64); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 6067 | __ Fcvtzs(OutputRegister(conversion), InputFPRegisterAt(conversion, 0)); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6068 | } else if (DataType::IsFloatingPointType(result_type) && |
| 6069 | DataType::IsFloatingPointType(input_type)) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 6070 | __ Fcvt(OutputFPRegister(conversion), InputFPRegisterAt(conversion, 0)); |
| 6071 | } else { |
| 6072 | LOG(FATAL) << "Unexpected or unimplemented type conversion from " << input_type |
| 6073 | << " to " << result_type; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6074 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 6075 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6076 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 6077 | void LocationsBuilderARM64::VisitUShr(HUShr* ushr) { |
| 6078 | HandleShift(ushr); |
| 6079 | } |
| 6080 | |
| 6081 | void InstructionCodeGeneratorARM64::VisitUShr(HUShr* ushr) { |
| 6082 | HandleShift(ushr); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6083 | } |
| 6084 | |
| 6085 | void LocationsBuilderARM64::VisitXor(HXor* instruction) { |
| 6086 | HandleBinaryOp(instruction); |
| 6087 | } |
| 6088 | |
| 6089 | void InstructionCodeGeneratorARM64::VisitXor(HXor* instruction) { |
| 6090 | HandleBinaryOp(instruction); |
| 6091 | } |
| 6092 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6093 | void LocationsBuilderARM64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6094 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6095 | LOG(FATAL) << "Unreachable"; |
| 6096 | } |
| 6097 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6098 | void InstructionCodeGeneratorARM64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6099 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6100 | LOG(FATAL) << "Unreachable"; |
| 6101 | } |
| 6102 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6103 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 6104 | void LocationsBuilderARM64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 6105 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6106 | new (GetGraph()->GetAllocator()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6107 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6108 | } |
| 6109 | |
| 6110 | void InstructionCodeGeneratorARM64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 6111 | int32_t lower_bound = switch_instr->GetStartValue(); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 6112 | uint32_t num_entries = switch_instr->GetNumEntries(); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6113 | Register value_reg = InputRegisterAt(switch_instr, 0); |
| 6114 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 6115 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 6116 | // 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] | 6117 | static constexpr int32_t kMaxExpectedSizePerHInstruction = 16 * kInstructionSize; |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 6118 | // ADR has a limited range(+/-1MB), so we set a threshold for the number of HIRs in the graph to |
| 6119 | // make sure we don't emit it if the target may run out of range. |
| 6120 | // TODO: Instead of emitting all jump tables at the end of the code, we could keep track of ADR |
| 6121 | // ranges and emit the tables only as required. |
| 6122 | static constexpr int32_t kJumpTableInstructionThreshold = 1* MB / kMaxExpectedSizePerHInstruction; |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6123 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6124 | if (num_entries <= kPackedSwitchCompareJumpThreshold || |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 6125 | // Current instruction id is an upper bound of the number of HIRs in the graph. |
| 6126 | GetGraph()->GetCurrentInstructionId() > kJumpTableInstructionThreshold) { |
| 6127 | // Create a series of compare/jumps. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6128 | UseScratchRegisterScope temps(codegen_->GetVIXLAssembler()); |
| 6129 | Register temp = temps.AcquireW(); |
| 6130 | __ Subs(temp, value_reg, Operand(lower_bound)); |
| 6131 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 6132 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6133 | // Jump to successors[0] if value == lower_bound. |
| 6134 | __ B(eq, codegen_->GetLabelOf(successors[0])); |
| 6135 | int32_t last_index = 0; |
| 6136 | for (; num_entries - last_index > 2; last_index += 2) { |
| 6137 | __ Subs(temp, temp, Operand(2)); |
| 6138 | // Jump to successors[last_index + 1] if value < case_value[last_index + 2]. |
| 6139 | __ B(lo, codegen_->GetLabelOf(successors[last_index + 1])); |
| 6140 | // Jump to successors[last_index + 2] if value == case_value[last_index + 2]. |
| 6141 | __ B(eq, codegen_->GetLabelOf(successors[last_index + 2])); |
| 6142 | } |
| 6143 | if (num_entries - last_index == 2) { |
| 6144 | // The last missing case_value. |
| 6145 | __ Cmp(temp, Operand(1)); |
| 6146 | __ B(eq, codegen_->GetLabelOf(successors[last_index + 1])); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 6147 | } |
| 6148 | |
| 6149 | // And the default for any other value. |
| 6150 | if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) { |
| 6151 | __ B(codegen_->GetLabelOf(default_block)); |
| 6152 | } |
| 6153 | } else { |
Alexandre Rames | c01a664 | 2016-04-15 11:54:06 +0100 | [diff] [blame] | 6154 | JumpTableARM64* jump_table = codegen_->CreateJumpTable(switch_instr); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 6155 | |
| 6156 | UseScratchRegisterScope temps(codegen_->GetVIXLAssembler()); |
| 6157 | |
| 6158 | // Below instructions should use at most one blocked register. Since there are two blocked |
| 6159 | // registers, we are free to block one. |
| 6160 | Register temp_w = temps.AcquireW(); |
| 6161 | Register index; |
| 6162 | // Remove the bias. |
| 6163 | if (lower_bound != 0) { |
| 6164 | index = temp_w; |
| 6165 | __ Sub(index, value_reg, Operand(lower_bound)); |
| 6166 | } else { |
| 6167 | index = value_reg; |
| 6168 | } |
| 6169 | |
| 6170 | // Jump to default block if index is out of the range. |
| 6171 | __ Cmp(index, Operand(num_entries)); |
| 6172 | __ B(hs, codegen_->GetLabelOf(default_block)); |
| 6173 | |
| 6174 | // In current VIXL implementation, it won't require any blocked registers to encode the |
| 6175 | // immediate value for Adr. So we are free to use both VIXL blocked registers to reduce the |
| 6176 | // register pressure. |
| 6177 | Register table_base = temps.AcquireX(); |
| 6178 | // Load jump offset from the table. |
| 6179 | __ Adr(table_base, jump_table->GetTableStartLabel()); |
| 6180 | Register jump_offset = temp_w; |
| 6181 | __ Ldr(jump_offset, MemOperand(table_base, index, UXTW, 2)); |
| 6182 | |
| 6183 | // Jump to target block by branching to table_base(pc related) + offset. |
| 6184 | Register target_address = table_base; |
| 6185 | __ Add(target_address, table_base, Operand(jump_offset, SXTW)); |
| 6186 | __ Br(target_address); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6187 | } |
| 6188 | } |
| 6189 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6190 | void InstructionCodeGeneratorARM64::GenerateReferenceLoadOneRegister( |
| 6191 | HInstruction* instruction, |
| 6192 | Location out, |
| 6193 | uint32_t offset, |
| 6194 | Location maybe_temp, |
| 6195 | ReadBarrierOption read_barrier_option) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6196 | DataType::Type type = DataType::Type::kReference; |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6197 | Register out_reg = RegisterFrom(out, type); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6198 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6199 | CHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6200 | if (kUseBakerReadBarrier) { |
| 6201 | // Load with fast path based Baker's read barrier. |
| 6202 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6203 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 6204 | out, |
| 6205 | out_reg, |
| 6206 | offset, |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6207 | maybe_temp, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6208 | /* needs_null_check */ false, |
| 6209 | /* use_load_acquire */ false); |
| 6210 | } else { |
| 6211 | // Load with slow path based read barrier. |
| 6212 | // Save the value of `out` into `maybe_temp` before overwriting it |
| 6213 | // in the following move operation, as we will need it for the |
| 6214 | // read barrier below. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6215 | Register temp_reg = RegisterFrom(maybe_temp, type); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6216 | __ Mov(temp_reg, out_reg); |
| 6217 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6218 | __ Ldr(out_reg, HeapOperand(out_reg, offset)); |
| 6219 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
| 6220 | } |
| 6221 | } else { |
| 6222 | // Plain load with no read barrier. |
| 6223 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6224 | __ Ldr(out_reg, HeapOperand(out_reg, offset)); |
| 6225 | GetAssembler()->MaybeUnpoisonHeapReference(out_reg); |
| 6226 | } |
| 6227 | } |
| 6228 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6229 | void InstructionCodeGeneratorARM64::GenerateReferenceLoadTwoRegisters( |
| 6230 | HInstruction* instruction, |
| 6231 | Location out, |
| 6232 | Location obj, |
| 6233 | uint32_t offset, |
| 6234 | Location maybe_temp, |
| 6235 | ReadBarrierOption read_barrier_option) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6236 | DataType::Type type = DataType::Type::kReference; |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6237 | Register out_reg = RegisterFrom(out, type); |
| 6238 | Register obj_reg = RegisterFrom(obj, type); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6239 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6240 | CHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6241 | if (kUseBakerReadBarrier) { |
| 6242 | // Load with fast path based Baker's read barrier. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6243 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6244 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 6245 | out, |
| 6246 | obj_reg, |
| 6247 | offset, |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6248 | maybe_temp, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6249 | /* needs_null_check */ false, |
| 6250 | /* use_load_acquire */ false); |
| 6251 | } else { |
| 6252 | // Load with slow path based read barrier. |
| 6253 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6254 | __ Ldr(out_reg, HeapOperand(obj_reg, offset)); |
| 6255 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 6256 | } |
| 6257 | } else { |
| 6258 | // Plain load with no read barrier. |
| 6259 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6260 | __ Ldr(out_reg, HeapOperand(obj_reg, offset)); |
| 6261 | GetAssembler()->MaybeUnpoisonHeapReference(out_reg); |
| 6262 | } |
| 6263 | } |
| 6264 | |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6265 | void CodeGeneratorARM64::GenerateGcRootFieldLoad( |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6266 | HInstruction* instruction, |
| 6267 | Location root, |
| 6268 | Register obj, |
| 6269 | uint32_t offset, |
| 6270 | vixl::aarch64::Label* fixup_label, |
| 6271 | ReadBarrierOption read_barrier_option) { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6272 | DCHECK(fixup_label == nullptr || offset == 0u); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6273 | Register root_reg = RegisterFrom(root, DataType::Type::kReference); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6274 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6275 | DCHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6276 | if (kUseBakerReadBarrier) { |
| 6277 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6278 | // Baker's read barrier are used. |
Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 6279 | if (kBakerReadBarrierLinkTimeThunksEnableForGcRoots) { |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6280 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in |
| 6281 | // the Marking Register) to decide whether we need to enter |
| 6282 | // the slow path to mark the GC root. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6283 | // |
Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 6284 | // We use shared thunks for the slow path; shared within the method |
| 6285 | // for JIT, across methods for AOT. That thunk checks the reference |
| 6286 | // and jumps to the entrypoint if needed. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6287 | // |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6288 | // lr = &return_address; |
| 6289 | // GcRoot<mirror::Object> root = *(obj+offset); // Original reference load. |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6290 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
| 6291 | // goto gc_root_thunk<root_reg>(lr) |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6292 | // } |
| 6293 | // return_address: |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6294 | |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6295 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 6296 | DCHECK(temps.IsAvailable(ip0)); |
| 6297 | DCHECK(temps.IsAvailable(ip1)); |
| 6298 | temps.Exclude(ip0, ip1); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6299 | uint32_t custom_data = EncodeBakerReadBarrierGcRootData(root_reg.GetCode()); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6300 | |
Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 6301 | ExactAssemblyScope guard(GetVIXLAssembler(), 3 * vixl::aarch64::kInstructionSize); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6302 | vixl::aarch64::Label return_address; |
| 6303 | __ adr(lr, &return_address); |
| 6304 | if (fixup_label != nullptr) { |
Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 6305 | __ bind(fixup_label); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6306 | } |
| 6307 | static_assert(BAKER_MARK_INTROSPECTION_GC_ROOT_LDR_OFFSET == -8, |
| 6308 | "GC root LDR must be 2 instruction (8B) before the return address label."); |
| 6309 | __ ldr(root_reg, MemOperand(obj.X(), offset)); |
Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 6310 | EmitBakerReadBarrierCbnz(custom_data); |
| 6311 | __ bind(&return_address); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6312 | } else { |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6313 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in |
| 6314 | // the Marking Register) to decide whether we need to enter |
| 6315 | // the slow path to mark the GC root. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6316 | // |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6317 | // GcRoot<mirror::Object> root = *(obj+offset); // Original reference load. |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6318 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6319 | // // Slow path. |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6320 | // entrypoint = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 6321 | // root = entrypoint(root); // root = ReadBarrier::Mark(root); // Entry point call. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6322 | // } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6323 | |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6324 | // Slow path marking the GC root `root`. The entrypoint will |
| 6325 | // be loaded by the slow path code. |
| 6326 | SlowPathCodeARM64* slow_path = |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6327 | new (GetScopedAllocator()) ReadBarrierMarkSlowPathARM64(instruction, root); |
| 6328 | AddSlowPath(slow_path); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6329 | |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6330 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 6331 | if (fixup_label == nullptr) { |
| 6332 | __ Ldr(root_reg, MemOperand(obj, offset)); |
| 6333 | } else { |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6334 | EmitLdrOffsetPlaceholder(fixup_label, root_reg, obj); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6335 | } |
| 6336 | static_assert( |
| 6337 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 6338 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 6339 | "have different sizes."); |
| 6340 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 6341 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 6342 | "have different sizes."); |
| 6343 | |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6344 | __ Cbnz(mr, slow_path->GetEntryLabel()); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6345 | __ Bind(slow_path->GetExitLabel()); |
| 6346 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6347 | } else { |
| 6348 | // GC root loaded through a slow path for read barriers other |
| 6349 | // than Baker's. |
| 6350 | // /* GcRoot<mirror::Object>* */ root = obj + offset |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6351 | if (fixup_label == nullptr) { |
| 6352 | __ Add(root_reg.X(), obj.X(), offset); |
| 6353 | } else { |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6354 | EmitAddPlaceholder(fixup_label, root_reg.X(), obj.X()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6355 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6356 | // /* mirror::Object* */ root = root->Read() |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6357 | GenerateReadBarrierForRootSlow(instruction, root, root); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6358 | } |
| 6359 | } else { |
| 6360 | // Plain GC root load with no read barrier. |
| 6361 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6362 | if (fixup_label == nullptr) { |
| 6363 | __ Ldr(root_reg, MemOperand(obj, offset)); |
| 6364 | } else { |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6365 | EmitLdrOffsetPlaceholder(fixup_label, root_reg, obj.X()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6366 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6367 | // Note that GC roots are not affected by heap poisoning, thus we |
| 6368 | // do not have to unpoison `root_reg` here. |
| 6369 | } |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6370 | MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6371 | } |
| 6372 | |
| 6373 | void CodeGeneratorARM64::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6374 | Location ref, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 6375 | Register obj, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6376 | uint32_t offset, |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6377 | Location maybe_temp, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6378 | bool needs_null_check, |
| 6379 | bool use_load_acquire) { |
| 6380 | DCHECK(kEmitCompilerReadBarrier); |
| 6381 | DCHECK(kUseBakerReadBarrier); |
| 6382 | |
Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 6383 | if (kBakerReadBarrierLinkTimeThunksEnableForFields && !use_load_acquire) { |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6384 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in the |
| 6385 | // Marking Register) to decide whether we need to enter the slow |
| 6386 | // path to mark the reference. Then, in the slow path, check the |
| 6387 | // gray bit in the lock word of the reference's holder (`obj`) to |
| 6388 | // decide whether to mark `ref` or not. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6389 | // |
Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 6390 | // We use shared thunks for the slow path; shared within the method |
| 6391 | // for JIT, across methods for AOT. That thunk checks the holder |
| 6392 | // and jumps to the entrypoint if needed. If the holder is not gray, |
| 6393 | // it creates a fake dependency and returns to the LDR instruction. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6394 | // |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6395 | // lr = &gray_return_address; |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6396 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
| 6397 | // goto field_thunk<holder_reg, base_reg>(lr) |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6398 | // } |
| 6399 | // not_gray_return_address: |
| 6400 | // // Original reference load. If the offset is too large to fit |
| 6401 | // // into LDR, we use an adjusted base register here. |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 6402 | // HeapReference<mirror::Object> reference = *(obj+offset); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6403 | // gray_return_address: |
| 6404 | |
| 6405 | DCHECK_ALIGNED(offset, sizeof(mirror::HeapReference<mirror::Object>)); |
| 6406 | Register base = obj; |
| 6407 | if (offset >= kReferenceLoadMinFarOffset) { |
| 6408 | DCHECK(maybe_temp.IsRegister()); |
| 6409 | base = WRegisterFrom(maybe_temp); |
| 6410 | static_assert(IsPowerOfTwo(kReferenceLoadMinFarOffset), "Expecting a power of 2."); |
| 6411 | __ Add(base, obj, Operand(offset & ~(kReferenceLoadMinFarOffset - 1u))); |
| 6412 | offset &= (kReferenceLoadMinFarOffset - 1u); |
| 6413 | } |
| 6414 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 6415 | DCHECK(temps.IsAvailable(ip0)); |
| 6416 | DCHECK(temps.IsAvailable(ip1)); |
| 6417 | temps.Exclude(ip0, ip1); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6418 | uint32_t custom_data = EncodeBakerReadBarrierFieldData(base.GetCode(), obj.GetCode()); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6419 | |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 6420 | { |
Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 6421 | ExactAssemblyScope guard(GetVIXLAssembler(), |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 6422 | (kPoisonHeapReferences ? 4u : 3u) * vixl::aarch64::kInstructionSize); |
| 6423 | vixl::aarch64::Label return_address; |
| 6424 | __ adr(lr, &return_address); |
Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 6425 | EmitBakerReadBarrierCbnz(custom_data); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 6426 | static_assert(BAKER_MARK_INTROSPECTION_FIELD_LDR_OFFSET == (kPoisonHeapReferences ? -8 : -4), |
| 6427 | "Field LDR must be 1 instruction (4B) before the return address label; " |
| 6428 | " 2 instructions (8B) for heap poisoning."); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6429 | Register ref_reg = RegisterFrom(ref, DataType::Type::kReference); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 6430 | __ ldr(ref_reg, MemOperand(base.X(), offset)); |
| 6431 | if (needs_null_check) { |
| 6432 | MaybeRecordImplicitNullCheck(instruction); |
| 6433 | } |
Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 6434 | // Unpoison the reference explicitly if needed. MaybeUnpoisonHeapReference() uses |
| 6435 | // macro instructions disallowed in ExactAssemblyScope. |
| 6436 | if (kPoisonHeapReferences) { |
| 6437 | __ neg(ref_reg, Operand(ref_reg)); |
| 6438 | } |
| 6439 | __ bind(&return_address); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6440 | } |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 6441 | MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__, /* temp_loc */ LocationFrom(ip1)); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6442 | return; |
| 6443 | } |
| 6444 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6445 | // /* HeapReference<Object> */ ref = *(obj + offset) |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6446 | Register temp = WRegisterFrom(maybe_temp); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6447 | Location no_index = Location::NoLocation(); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 6448 | size_t no_scale_factor = 0u; |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6449 | GenerateReferenceLoadWithBakerReadBarrier(instruction, |
| 6450 | ref, |
| 6451 | obj, |
| 6452 | offset, |
| 6453 | no_index, |
| 6454 | no_scale_factor, |
| 6455 | temp, |
| 6456 | needs_null_check, |
| 6457 | use_load_acquire); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6458 | } |
| 6459 | |
| 6460 | void CodeGeneratorARM64::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6461 | Location ref, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 6462 | Register obj, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6463 | uint32_t data_offset, |
| 6464 | Location index, |
| 6465 | Register temp, |
| 6466 | bool needs_null_check) { |
| 6467 | DCHECK(kEmitCompilerReadBarrier); |
| 6468 | DCHECK(kUseBakerReadBarrier); |
| 6469 | |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6470 | static_assert( |
| 6471 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 6472 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6473 | size_t scale_factor = DataType::SizeShift(DataType::Type::kReference); |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6474 | |
Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 6475 | if (kBakerReadBarrierLinkTimeThunksEnableForArrays) { |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6476 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in the |
| 6477 | // Marking Register) to decide whether we need to enter the slow |
| 6478 | // path to mark the reference. Then, in the slow path, check the |
| 6479 | // gray bit in the lock word of the reference's holder (`obj`) to |
| 6480 | // decide whether to mark `ref` or not. |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6481 | // |
Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 6482 | // We use shared thunks for the slow path; shared within the method |
| 6483 | // for JIT, across methods for AOT. That thunk checks the holder |
| 6484 | // and jumps to the entrypoint if needed. If the holder is not gray, |
| 6485 | // it creates a fake dependency and returns to the LDR instruction. |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6486 | // |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6487 | // lr = &gray_return_address; |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6488 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
| 6489 | // goto array_thunk<base_reg>(lr) |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6490 | // } |
| 6491 | // not_gray_return_address: |
| 6492 | // // Original reference load. If the offset is too large to fit |
| 6493 | // // into LDR, we use an adjusted base register here. |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 6494 | // HeapReference<mirror::Object> reference = data[index]; |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6495 | // gray_return_address: |
| 6496 | |
| 6497 | DCHECK(index.IsValid()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6498 | Register index_reg = RegisterFrom(index, DataType::Type::kInt32); |
| 6499 | Register ref_reg = RegisterFrom(ref, DataType::Type::kReference); |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6500 | |
| 6501 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 6502 | DCHECK(temps.IsAvailable(ip0)); |
| 6503 | DCHECK(temps.IsAvailable(ip1)); |
| 6504 | temps.Exclude(ip0, ip1); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6505 | uint32_t custom_data = EncodeBakerReadBarrierArrayData(temp.GetCode()); |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6506 | |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6507 | __ Add(temp.X(), obj.X(), Operand(data_offset)); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 6508 | { |
Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 6509 | ExactAssemblyScope guard(GetVIXLAssembler(), |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 6510 | (kPoisonHeapReferences ? 4u : 3u) * vixl::aarch64::kInstructionSize); |
| 6511 | vixl::aarch64::Label return_address; |
| 6512 | __ adr(lr, &return_address); |
Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 6513 | EmitBakerReadBarrierCbnz(custom_data); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 6514 | static_assert(BAKER_MARK_INTROSPECTION_ARRAY_LDR_OFFSET == (kPoisonHeapReferences ? -8 : -4), |
| 6515 | "Array LDR must be 1 instruction (4B) before the return address label; " |
| 6516 | " 2 instructions (8B) for heap poisoning."); |
| 6517 | __ ldr(ref_reg, MemOperand(temp.X(), index_reg.X(), LSL, scale_factor)); |
| 6518 | DCHECK(!needs_null_check); // The thunk cannot handle the null check. |
Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 6519 | // Unpoison the reference explicitly if needed. MaybeUnpoisonHeapReference() uses |
| 6520 | // macro instructions disallowed in ExactAssemblyScope. |
| 6521 | if (kPoisonHeapReferences) { |
| 6522 | __ neg(ref_reg, Operand(ref_reg)); |
| 6523 | } |
| 6524 | __ bind(&return_address); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 6525 | } |
| 6526 | MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__, /* temp_loc */ LocationFrom(ip1)); |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6527 | return; |
| 6528 | } |
| 6529 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6530 | // Array cells are never volatile variables, therefore array loads |
| 6531 | // never use Load-Acquire instructions on ARM64. |
| 6532 | const bool use_load_acquire = false; |
| 6533 | |
| 6534 | // /* HeapReference<Object> */ ref = |
| 6535 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6536 | GenerateReferenceLoadWithBakerReadBarrier(instruction, |
| 6537 | ref, |
| 6538 | obj, |
| 6539 | data_offset, |
| 6540 | index, |
| 6541 | scale_factor, |
| 6542 | temp, |
| 6543 | needs_null_check, |
| 6544 | use_load_acquire); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6545 | } |
| 6546 | |
| 6547 | void CodeGeneratorARM64::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6548 | Location ref, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 6549 | Register obj, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6550 | uint32_t offset, |
| 6551 | Location index, |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6552 | size_t scale_factor, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6553 | Register temp, |
| 6554 | bool needs_null_check, |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6555 | bool use_load_acquire) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6556 | DCHECK(kEmitCompilerReadBarrier); |
| 6557 | DCHECK(kUseBakerReadBarrier); |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6558 | // If we are emitting an array load, we should not be using a |
| 6559 | // Load Acquire instruction. In other words: |
| 6560 | // `instruction->IsArrayGet()` => `!use_load_acquire`. |
| 6561 | DCHECK(!instruction->IsArrayGet() || !use_load_acquire); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6562 | |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6563 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in the |
| 6564 | // Marking Register) to decide whether we need to enter the slow |
| 6565 | // path to mark the reference. Then, in the slow path, check the |
| 6566 | // gray bit in the lock word of the reference's holder (`obj`) to |
| 6567 | // decide whether to mark `ref` or not. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6568 | // |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6569 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6570 | // // Slow path. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 6571 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 6572 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 6573 | // HeapReference<mirror::Object> ref = *src; // Original reference load. |
| 6574 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 6575 | // if (is_gray) { |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6576 | // entrypoint = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 6577 | // ref = entrypoint(ref); // ref = ReadBarrier::Mark(ref); // Runtime entry point call. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 6578 | // } |
| 6579 | // } else { |
| 6580 | // HeapReference<mirror::Object> ref = *src; // Original reference load. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6581 | // } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6582 | |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6583 | // Slow path marking the object `ref` when the GC is marking. The |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6584 | // entrypoint will be loaded by the slow path code. |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6585 | SlowPathCodeARM64* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6586 | new (GetScopedAllocator()) LoadReferenceWithBakerReadBarrierSlowPathARM64( |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6587 | instruction, |
| 6588 | ref, |
| 6589 | obj, |
| 6590 | offset, |
| 6591 | index, |
| 6592 | scale_factor, |
| 6593 | needs_null_check, |
| 6594 | use_load_acquire, |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6595 | temp); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6596 | AddSlowPath(slow_path); |
| 6597 | |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6598 | __ Cbnz(mr, slow_path->GetEntryLabel()); |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6599 | // Fast path: the GC is not marking: just load the reference. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 6600 | GenerateRawReferenceLoad( |
| 6601 | instruction, ref, obj, offset, index, scale_factor, needs_null_check, use_load_acquire); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6602 | __ Bind(slow_path->GetExitLabel()); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 6603 | MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6604 | } |
| 6605 | |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6606 | void CodeGeneratorARM64::UpdateReferenceFieldWithBakerReadBarrier(HInstruction* instruction, |
| 6607 | Location ref, |
| 6608 | Register obj, |
| 6609 | Location field_offset, |
| 6610 | Register temp, |
| 6611 | bool needs_null_check, |
| 6612 | bool use_load_acquire) { |
| 6613 | DCHECK(kEmitCompilerReadBarrier); |
| 6614 | DCHECK(kUseBakerReadBarrier); |
| 6615 | // If we are emitting an array load, we should not be using a |
| 6616 | // Load Acquire instruction. In other words: |
| 6617 | // `instruction->IsArrayGet()` => `!use_load_acquire`. |
| 6618 | DCHECK(!instruction->IsArrayGet() || !use_load_acquire); |
| 6619 | |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6620 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in the |
| 6621 | // Marking Register) to decide whether we need to enter the slow |
| 6622 | // path to update the reference field within `obj`. Then, in the |
| 6623 | // slow path, check the gray bit in the lock word of the reference's |
| 6624 | // holder (`obj`) to decide whether to mark `ref` and update the |
| 6625 | // field or not. |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6626 | // |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6627 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6628 | // // Slow path. |
| 6629 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 6630 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 6631 | // HeapReference<mirror::Object> ref = *(obj + field_offset); // Reference load. |
| 6632 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 6633 | // if (is_gray) { |
| 6634 | // old_ref = ref; |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6635 | // entrypoint = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 6636 | // ref = entrypoint(ref); // ref = ReadBarrier::Mark(ref); // Runtime entry point call. |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6637 | // compareAndSwapObject(obj, field_offset, old_ref, ref); |
| 6638 | // } |
| 6639 | // } |
| 6640 | |
| 6641 | // Slow path updating the object reference at address `obj + field_offset` |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6642 | // when the GC is marking. The entrypoint will be loaded by the slow path code. |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6643 | SlowPathCodeARM64* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6644 | new (GetScopedAllocator()) LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM64( |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6645 | instruction, |
| 6646 | ref, |
| 6647 | obj, |
| 6648 | /* offset */ 0u, |
| 6649 | /* index */ field_offset, |
| 6650 | /* scale_factor */ 0u /* "times 1" */, |
| 6651 | needs_null_check, |
| 6652 | use_load_acquire, |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6653 | temp); |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6654 | AddSlowPath(slow_path); |
| 6655 | |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6656 | __ Cbnz(mr, slow_path->GetEntryLabel()); |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6657 | // Fast path: the GC is not marking: nothing to do (the field is |
| 6658 | // up-to-date, and we don't need to load the reference). |
| 6659 | __ Bind(slow_path->GetExitLabel()); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 6660 | MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6661 | } |
| 6662 | |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6663 | void CodeGeneratorARM64::GenerateRawReferenceLoad(HInstruction* instruction, |
| 6664 | Location ref, |
| 6665 | Register obj, |
| 6666 | uint32_t offset, |
| 6667 | Location index, |
| 6668 | size_t scale_factor, |
| 6669 | bool needs_null_check, |
| 6670 | bool use_load_acquire) { |
| 6671 | DCHECK(obj.IsW()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6672 | DataType::Type type = DataType::Type::kReference; |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6673 | Register ref_reg = RegisterFrom(ref, type); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6674 | |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6675 | // If needed, vixl::EmissionCheckScope guards are used to ensure |
| 6676 | // that no pools are emitted between the load (macro) instruction |
| 6677 | // and MaybeRecordImplicitNullCheck. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6678 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6679 | if (index.IsValid()) { |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 6680 | // Load types involving an "index": ArrayGet, |
| 6681 | // UnsafeGetObject/UnsafeGetObjectVolatile and UnsafeCASObject |
| 6682 | // intrinsics. |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6683 | if (use_load_acquire) { |
| 6684 | // UnsafeGetObjectVolatile intrinsic case. |
| 6685 | // Register `index` is not an index in an object array, but an |
| 6686 | // offset to an object reference field within object `obj`. |
| 6687 | DCHECK(instruction->IsInvoke()) << instruction->DebugName(); |
| 6688 | DCHECK(instruction->GetLocations()->Intrinsified()); |
| 6689 | DCHECK(instruction->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile) |
| 6690 | << instruction->AsInvoke()->GetIntrinsic(); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 6691 | DCHECK_EQ(offset, 0u); |
| 6692 | DCHECK_EQ(scale_factor, 0u); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6693 | DCHECK_EQ(needs_null_check, false); |
| 6694 | // /* HeapReference<mirror::Object> */ ref = *(obj + index) |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6695 | MemOperand field = HeapOperand(obj, XRegisterFrom(index)); |
| 6696 | LoadAcquire(instruction, ref_reg, field, /* needs_null_check */ false); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6697 | } else { |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6698 | // ArrayGet and UnsafeGetObject and UnsafeCASObject intrinsics cases. |
| 6699 | // /* HeapReference<mirror::Object> */ ref = *(obj + offset + (index << scale_factor)) |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6700 | if (index.IsConstant()) { |
Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 6701 | uint32_t computed_offset = offset + (Int64FromLocation(index) << scale_factor); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6702 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6703 | Load(type, ref_reg, HeapOperand(obj, computed_offset)); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6704 | if (needs_null_check) { |
| 6705 | MaybeRecordImplicitNullCheck(instruction); |
| 6706 | } |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6707 | } else { |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6708 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 6709 | Register temp = temps.AcquireW(); |
| 6710 | __ Add(temp, obj, offset); |
| 6711 | { |
| 6712 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 6713 | Load(type, ref_reg, HeapOperand(temp, XRegisterFrom(index), LSL, scale_factor)); |
| 6714 | if (needs_null_check) { |
| 6715 | MaybeRecordImplicitNullCheck(instruction); |
| 6716 | } |
| 6717 | } |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6718 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6719 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6720 | } else { |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6721 | // /* HeapReference<mirror::Object> */ ref = *(obj + offset) |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6722 | MemOperand field = HeapOperand(obj, offset); |
| 6723 | if (use_load_acquire) { |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6724 | // Implicit null checks are handled by CodeGeneratorARM64::LoadAcquire. |
| 6725 | LoadAcquire(instruction, ref_reg, field, needs_null_check); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6726 | } else { |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6727 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6728 | Load(type, ref_reg, field); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6729 | if (needs_null_check) { |
| 6730 | MaybeRecordImplicitNullCheck(instruction); |
| 6731 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6732 | } |
| 6733 | } |
| 6734 | |
| 6735 | // Object* ref = ref_addr->AsMirrorPtr() |
| 6736 | GetAssembler()->MaybeUnpoisonHeapReference(ref_reg); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6737 | } |
| 6738 | |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 6739 | void CodeGeneratorARM64::MaybeGenerateMarkingRegisterCheck(int code, Location temp_loc) { |
| 6740 | // The following condition is a compile-time one, so it does not have a run-time cost. |
| 6741 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier && kIsDebugBuild) { |
| 6742 | // The following condition is a run-time one; it is executed after the |
| 6743 | // previous compile-time test, to avoid penalizing non-debug builds. |
| 6744 | if (GetCompilerOptions().EmitRunTimeChecksInDebugMode()) { |
| 6745 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 6746 | Register temp = temp_loc.IsValid() ? WRegisterFrom(temp_loc) : temps.AcquireW(); |
| 6747 | GetAssembler()->GenerateMarkingRegisterCheck(temp, code); |
| 6748 | } |
| 6749 | } |
| 6750 | } |
| 6751 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6752 | void CodeGeneratorARM64::GenerateReadBarrierSlow(HInstruction* instruction, |
| 6753 | Location out, |
| 6754 | Location ref, |
| 6755 | Location obj, |
| 6756 | uint32_t offset, |
| 6757 | Location index) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6758 | DCHECK(kEmitCompilerReadBarrier); |
| 6759 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6760 | // Insert a slow path based read barrier *after* the reference load. |
| 6761 | // |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6762 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 6763 | // reference will be carried out by the runtime within the slow |
| 6764 | // path. |
| 6765 | // |
| 6766 | // Note that `ref` currently does not get unpoisoned (when heap |
| 6767 | // poisoning is enabled), which is alright as the `ref` argument is |
| 6768 | // not used by the artReadBarrierSlow entry point. |
| 6769 | // |
| 6770 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6771 | SlowPathCodeARM64* slow_path = new (GetScopedAllocator()) |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6772 | ReadBarrierForHeapReferenceSlowPathARM64(instruction, out, ref, obj, offset, index); |
| 6773 | AddSlowPath(slow_path); |
| 6774 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6775 | __ B(slow_path->GetEntryLabel()); |
| 6776 | __ Bind(slow_path->GetExitLabel()); |
| 6777 | } |
| 6778 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6779 | void CodeGeneratorARM64::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 6780 | Location out, |
| 6781 | Location ref, |
| 6782 | Location obj, |
| 6783 | uint32_t offset, |
| 6784 | Location index) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6785 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6786 | // Baker's read barriers shall be handled by the fast path |
| 6787 | // (CodeGeneratorARM64::GenerateReferenceLoadWithBakerReadBarrier). |
| 6788 | DCHECK(!kUseBakerReadBarrier); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6789 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 6790 | // by the runtime within the slow path. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6791 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6792 | } else if (kPoisonHeapReferences) { |
| 6793 | GetAssembler()->UnpoisonHeapReference(WRegisterFrom(out)); |
| 6794 | } |
| 6795 | } |
| 6796 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6797 | void CodeGeneratorARM64::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 6798 | Location out, |
| 6799 | Location root) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6800 | DCHECK(kEmitCompilerReadBarrier); |
| 6801 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6802 | // Insert a slow path based read barrier *after* the GC root load. |
| 6803 | // |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6804 | // Note that GC roots are not affected by heap poisoning, so we do |
| 6805 | // not need to do anything special for this here. |
| 6806 | SlowPathCodeARM64* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6807 | new (GetScopedAllocator()) ReadBarrierForRootSlowPathARM64(instruction, out, root); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6808 | AddSlowPath(slow_path); |
| 6809 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6810 | __ B(slow_path->GetEntryLabel()); |
| 6811 | __ Bind(slow_path->GetExitLabel()); |
| 6812 | } |
| 6813 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6814 | void LocationsBuilderARM64::VisitClassTableGet(HClassTableGet* instruction) { |
| 6815 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6816 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6817 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6818 | locations->SetOut(Location::RequiresRegister()); |
| 6819 | } |
| 6820 | |
| 6821 | void InstructionCodeGeneratorARM64::VisitClassTableGet(HClassTableGet* instruction) { |
| 6822 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6823 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 6824 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6825 | instruction->GetIndex(), kArm64PointerSize).SizeValue(); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 6826 | __ Ldr(XRegisterFrom(locations->Out()), |
| 6827 | MemOperand(XRegisterFrom(locations->InAt(0)), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6828 | } else { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 6829 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 6830 | instruction->GetIndex(), kArm64PointerSize)); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 6831 | __ Ldr(XRegisterFrom(locations->Out()), MemOperand(XRegisterFrom(locations->InAt(0)), |
| 6832 | mirror::Class::ImtPtrOffset(kArm64PointerSize).Uint32Value())); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 6833 | __ Ldr(XRegisterFrom(locations->Out()), |
| 6834 | MemOperand(XRegisterFrom(locations->Out()), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6835 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6836 | } |
| 6837 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6838 | static void PatchJitRootUse(uint8_t* code, |
| 6839 | const uint8_t* roots_data, |
| 6840 | vixl::aarch64::Literal<uint32_t>* literal, |
| 6841 | uint64_t index_in_table) { |
| 6842 | uint32_t literal_offset = literal->GetOffset(); |
| 6843 | uintptr_t address = |
| 6844 | reinterpret_cast<uintptr_t>(roots_data) + index_in_table * sizeof(GcRoot<mirror::Object>); |
| 6845 | uint8_t* data = code + literal_offset; |
| 6846 | reinterpret_cast<uint32_t*>(data)[0] = dchecked_integral_cast<uint32_t>(address); |
| 6847 | } |
| 6848 | |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6849 | void CodeGeneratorARM64::EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) { |
| 6850 | for (const auto& entry : jit_string_patches_) { |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 6851 | const StringReference& string_reference = entry.first; |
| 6852 | vixl::aarch64::Literal<uint32_t>* table_entry_literal = entry.second; |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6853 | uint64_t index_in_table = GetJitStringRootIndex(string_reference); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 6854 | PatchJitRootUse(code, roots_data, table_entry_literal, index_in_table); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6855 | } |
| 6856 | for (const auto& entry : jit_class_patches_) { |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 6857 | const TypeReference& type_reference = entry.first; |
| 6858 | vixl::aarch64::Literal<uint32_t>* table_entry_literal = entry.second; |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6859 | uint64_t index_in_table = GetJitClassRootIndex(type_reference); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 6860 | PatchJitRootUse(code, roots_data, table_entry_literal, index_in_table); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6861 | } |
| 6862 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6863 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6864 | #undef __ |
| 6865 | #undef QUICK_ENTRY_POINT |
| 6866 | |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6867 | #define __ assembler.GetVIXLAssembler()-> |
| 6868 | |
| 6869 | static void EmitGrayCheckAndFastPath(arm64::Arm64Assembler& assembler, |
| 6870 | vixl::aarch64::Register base_reg, |
| 6871 | vixl::aarch64::MemOperand& lock_word, |
Vladimir Marko | 7a69505 | 2018-04-12 10:26:50 +0100 | [diff] [blame] | 6872 | vixl::aarch64::Label* slow_path, |
| 6873 | vixl::aarch64::Label* throw_npe = nullptr) { |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6874 | // Load the lock word containing the rb_state. |
| 6875 | __ Ldr(ip0.W(), lock_word); |
| 6876 | // Given the numeric representation, it's enough to check the low bit of the rb_state. |
| 6877 | static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0"); |
| 6878 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
| 6879 | __ Tbnz(ip0.W(), LockWord::kReadBarrierStateShift, slow_path); |
| 6880 | static_assert( |
| 6881 | BAKER_MARK_INTROSPECTION_ARRAY_LDR_OFFSET == BAKER_MARK_INTROSPECTION_FIELD_LDR_OFFSET, |
| 6882 | "Field and array LDR offsets must be the same to reuse the same code."); |
Vladimir Marko | 7a69505 | 2018-04-12 10:26:50 +0100 | [diff] [blame] | 6883 | // To throw NPE, we return to the fast path; the artificial dependence below does not matter. |
| 6884 | if (throw_npe != nullptr) { |
| 6885 | __ Bind(throw_npe); |
| 6886 | } |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6887 | // Adjust the return address back to the LDR (1 instruction; 2 for heap poisoning). |
| 6888 | static_assert(BAKER_MARK_INTROSPECTION_FIELD_LDR_OFFSET == (kPoisonHeapReferences ? -8 : -4), |
| 6889 | "Field LDR must be 1 instruction (4B) before the return address label; " |
| 6890 | " 2 instructions (8B) for heap poisoning."); |
| 6891 | __ Add(lr, lr, BAKER_MARK_INTROSPECTION_FIELD_LDR_OFFSET); |
| 6892 | // Introduce a dependency on the lock_word including rb_state, |
| 6893 | // to prevent load-load reordering, and without using |
| 6894 | // a memory barrier (which would be more expensive). |
| 6895 | __ Add(base_reg, base_reg, Operand(ip0, LSR, 32)); |
| 6896 | __ Br(lr); // And return back to the function. |
| 6897 | // Note: The fake dependency is unnecessary for the slow path. |
| 6898 | } |
| 6899 | |
| 6900 | // Load the read barrier introspection entrypoint in register `entrypoint`. |
| 6901 | static void LoadReadBarrierMarkIntrospectionEntrypoint(arm64::Arm64Assembler& assembler, |
| 6902 | vixl::aarch64::Register entrypoint) { |
| 6903 | // entrypoint = Thread::Current()->pReadBarrierMarkReg16, i.e. pReadBarrierMarkIntrospection. |
| 6904 | DCHECK_EQ(ip0.GetCode(), 16u); |
| 6905 | const int32_t entry_point_offset = |
| 6906 | Thread::ReadBarrierMarkEntryPointsOffset<kArm64PointerSize>(ip0.GetCode()); |
| 6907 | __ Ldr(entrypoint, MemOperand(tr, entry_point_offset)); |
| 6908 | } |
| 6909 | |
| 6910 | void CodeGeneratorARM64::CompileBakerReadBarrierThunk(Arm64Assembler& assembler, |
| 6911 | uint32_t encoded_data, |
| 6912 | /*out*/ std::string* debug_name) { |
| 6913 | BakerReadBarrierKind kind = BakerReadBarrierKindField::Decode(encoded_data); |
| 6914 | switch (kind) { |
| 6915 | case BakerReadBarrierKind::kField: { |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6916 | auto base_reg = |
| 6917 | Register::GetXRegFromCode(BakerReadBarrierFirstRegField::Decode(encoded_data)); |
| 6918 | CheckValidReg(base_reg.GetCode()); |
| 6919 | auto holder_reg = |
| 6920 | Register::GetXRegFromCode(BakerReadBarrierSecondRegField::Decode(encoded_data)); |
| 6921 | CheckValidReg(holder_reg.GetCode()); |
| 6922 | UseScratchRegisterScope temps(assembler.GetVIXLAssembler()); |
| 6923 | temps.Exclude(ip0, ip1); |
Vladimir Marko | 7a69505 | 2018-04-12 10:26:50 +0100 | [diff] [blame] | 6924 | // If base_reg differs from holder_reg, the offset was too large and we must have emitted |
| 6925 | // an explicit null check before the load. Otherwise, for implicit null checks, we need to |
| 6926 | // null-check the holder as we do not necessarily do that check before going to the thunk. |
| 6927 | vixl::aarch64::Label throw_npe_label; |
| 6928 | vixl::aarch64::Label* throw_npe = nullptr; |
| 6929 | if (GetCompilerOptions().GetImplicitNullChecks() && holder_reg.Is(base_reg)) { |
| 6930 | throw_npe = &throw_npe_label; |
| 6931 | __ Cbz(holder_reg.W(), throw_npe); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6932 | } |
Vladimir Marko | 7a69505 | 2018-04-12 10:26:50 +0100 | [diff] [blame] | 6933 | // Check if the holder is gray and, if not, add fake dependency to the base register |
| 6934 | // and return to the LDR instruction to load the reference. Otherwise, use introspection |
| 6935 | // to load the reference and call the entrypoint that performs further checks on the |
| 6936 | // reference and marks it if needed. |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6937 | vixl::aarch64::Label slow_path; |
| 6938 | MemOperand lock_word(holder_reg, mirror::Object::MonitorOffset().Int32Value()); |
Vladimir Marko | 7a69505 | 2018-04-12 10:26:50 +0100 | [diff] [blame] | 6939 | EmitGrayCheckAndFastPath(assembler, base_reg, lock_word, &slow_path, throw_npe); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6940 | __ Bind(&slow_path); |
| 6941 | MemOperand ldr_address(lr, BAKER_MARK_INTROSPECTION_FIELD_LDR_OFFSET); |
| 6942 | __ Ldr(ip0.W(), ldr_address); // Load the LDR (immediate) unsigned offset. |
| 6943 | LoadReadBarrierMarkIntrospectionEntrypoint(assembler, ip1); |
| 6944 | __ Ubfx(ip0.W(), ip0.W(), 10, 12); // Extract the offset. |
| 6945 | __ Ldr(ip0.W(), MemOperand(base_reg, ip0, LSL, 2)); // Load the reference. |
| 6946 | // Do not unpoison. With heap poisoning enabled, the entrypoint expects a poisoned reference. |
| 6947 | __ Br(ip1); // Jump to the entrypoint. |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6948 | break; |
| 6949 | } |
| 6950 | case BakerReadBarrierKind::kArray: { |
| 6951 | auto base_reg = |
| 6952 | Register::GetXRegFromCode(BakerReadBarrierFirstRegField::Decode(encoded_data)); |
| 6953 | CheckValidReg(base_reg.GetCode()); |
| 6954 | DCHECK_EQ(kBakerReadBarrierInvalidEncodedReg, |
| 6955 | BakerReadBarrierSecondRegField::Decode(encoded_data)); |
| 6956 | UseScratchRegisterScope temps(assembler.GetVIXLAssembler()); |
| 6957 | temps.Exclude(ip0, ip1); |
| 6958 | vixl::aarch64::Label slow_path; |
| 6959 | int32_t data_offset = |
| 6960 | mirror::Array::DataOffset(Primitive::ComponentSize(Primitive::kPrimNot)).Int32Value(); |
| 6961 | MemOperand lock_word(base_reg, mirror::Object::MonitorOffset().Int32Value() - data_offset); |
| 6962 | DCHECK_LT(lock_word.GetOffset(), 0); |
| 6963 | EmitGrayCheckAndFastPath(assembler, base_reg, lock_word, &slow_path); |
| 6964 | __ Bind(&slow_path); |
| 6965 | MemOperand ldr_address(lr, BAKER_MARK_INTROSPECTION_ARRAY_LDR_OFFSET); |
| 6966 | __ Ldr(ip0.W(), ldr_address); // Load the LDR (register) unsigned offset. |
| 6967 | LoadReadBarrierMarkIntrospectionEntrypoint(assembler, ip1); |
| 6968 | __ Ubfx(ip0, ip0, 16, 6); // Extract the index register, plus 32 (bit 21 is set). |
| 6969 | __ Bfi(ip1, ip0, 3, 6); // Insert ip0 to the entrypoint address to create |
| 6970 | // a switch case target based on the index register. |
| 6971 | __ Mov(ip0, base_reg); // Move the base register to ip0. |
| 6972 | __ Br(ip1); // Jump to the entrypoint's array switch case. |
| 6973 | break; |
| 6974 | } |
| 6975 | case BakerReadBarrierKind::kGcRoot: { |
| 6976 | // Check if the reference needs to be marked and if so (i.e. not null, not marked yet |
| 6977 | // and it does not have a forwarding address), call the correct introspection entrypoint; |
| 6978 | // otherwise return the reference (or the extracted forwarding address). |
| 6979 | // There is no gray bit check for GC roots. |
| 6980 | auto root_reg = |
| 6981 | Register::GetWRegFromCode(BakerReadBarrierFirstRegField::Decode(encoded_data)); |
| 6982 | CheckValidReg(root_reg.GetCode()); |
| 6983 | DCHECK_EQ(kBakerReadBarrierInvalidEncodedReg, |
| 6984 | BakerReadBarrierSecondRegField::Decode(encoded_data)); |
| 6985 | UseScratchRegisterScope temps(assembler.GetVIXLAssembler()); |
| 6986 | temps.Exclude(ip0, ip1); |
| 6987 | vixl::aarch64::Label return_label, not_marked, forwarding_address; |
| 6988 | __ Cbz(root_reg, &return_label); |
| 6989 | MemOperand lock_word(root_reg.X(), mirror::Object::MonitorOffset().Int32Value()); |
| 6990 | __ Ldr(ip0.W(), lock_word); |
| 6991 | __ Tbz(ip0.W(), LockWord::kMarkBitStateShift, ¬_marked); |
| 6992 | __ Bind(&return_label); |
| 6993 | __ Br(lr); |
| 6994 | __ Bind(¬_marked); |
| 6995 | __ Tst(ip0.W(), Operand(ip0.W(), LSL, 1)); |
| 6996 | __ B(&forwarding_address, mi); |
| 6997 | LoadReadBarrierMarkIntrospectionEntrypoint(assembler, ip1); |
| 6998 | // Adjust the art_quick_read_barrier_mark_introspection address in IP1 to |
| 6999 | // art_quick_read_barrier_mark_introspection_gc_roots. |
| 7000 | __ Add(ip1, ip1, Operand(BAKER_MARK_INTROSPECTION_GC_ROOT_ENTRYPOINT_OFFSET)); |
| 7001 | __ Mov(ip0.W(), root_reg); |
| 7002 | __ Br(ip1); |
| 7003 | __ Bind(&forwarding_address); |
| 7004 | __ Lsl(root_reg, ip0.W(), LockWord::kForwardingAddressShift); |
| 7005 | __ Br(lr); |
| 7006 | break; |
| 7007 | } |
| 7008 | default: |
| 7009 | LOG(FATAL) << "Unexpected kind: " << static_cast<uint32_t>(kind); |
| 7010 | UNREACHABLE(); |
| 7011 | } |
| 7012 | |
Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 7013 | // For JIT, the slow path is considered part of the compiled method, |
| 7014 | // so JIT should pass null as `debug_name`. Tests may not have a runtime. |
| 7015 | DCHECK(Runtime::Current() == nullptr || |
| 7016 | !Runtime::Current()->UseJitCompilation() || |
| 7017 | debug_name == nullptr); |
| 7018 | if (debug_name != nullptr && GetCompilerOptions().GenerateAnyDebugInfo()) { |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 7019 | std::ostringstream oss; |
| 7020 | oss << "BakerReadBarrierThunk"; |
| 7021 | switch (kind) { |
| 7022 | case BakerReadBarrierKind::kField: |
| 7023 | oss << "Field_r" << BakerReadBarrierFirstRegField::Decode(encoded_data) |
| 7024 | << "_r" << BakerReadBarrierSecondRegField::Decode(encoded_data); |
| 7025 | break; |
| 7026 | case BakerReadBarrierKind::kArray: |
| 7027 | oss << "Array_r" << BakerReadBarrierFirstRegField::Decode(encoded_data); |
| 7028 | DCHECK_EQ(kBakerReadBarrierInvalidEncodedReg, |
| 7029 | BakerReadBarrierSecondRegField::Decode(encoded_data)); |
| 7030 | break; |
| 7031 | case BakerReadBarrierKind::kGcRoot: |
| 7032 | oss << "GcRoot_r" << BakerReadBarrierFirstRegField::Decode(encoded_data); |
| 7033 | DCHECK_EQ(kBakerReadBarrierInvalidEncodedReg, |
| 7034 | BakerReadBarrierSecondRegField::Decode(encoded_data)); |
| 7035 | break; |
| 7036 | } |
| 7037 | *debug_name = oss.str(); |
| 7038 | } |
| 7039 | } |
| 7040 | |
| 7041 | #undef __ |
| 7042 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 7043 | } // namespace arm64 |
| 7044 | } // namespace art |